js-ipld-dag-pb icon indicating copy to clipboard operation
js-ipld-dag-pb copied to clipboard

Return value of util.serialize(dagNode.toJSON()) should produce equal value to `dagNode.serialize()`

Open Gozala opened this issue 4 years ago • 2 comments

Current implementation of .toJSON() produces structure with fields: data, links and size. Which somewhat resembles DAGNode however passing that value into ipld.put stores block with CID QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n corresponding to {} because call to util.serialize looks at the capital cased fields instead

https://github.com/ipld/js-ipld-dag-pb/blob/1012cad04bd48183caf901c91ede1c9da67d0751/src/serialize.js#L40-L50

Which I find really unfortunate, as I was hoping to toJSON() for posting nodes across the threads.

Gozala avatar Jun 04 '20 05:06 Gozala

For my specific use case it would be even better if Data and Links getters were just turned into regular properties. That would make it unnecessary to call toJSON at least for my use case.

Gozala avatar Jun 04 '20 05:06 Gozala

toJSON() is mostly there for test purpose. It shouldn't really be used. I would've long removed it (as in other codec implementations) if it wouldn't break so much.

vmx avatar Jun 04 '20 13:06 vmx