Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

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

Open
Gozala opened this issue Jun 4, 2020 · 2 comments

Comments

@Gozala
Copy link
Contributor

Gozala commented Jun 4, 2020

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

const serializeDAGNode = (node) => {
const data = node.Data
const links = node.Links || []
const serialized = proto.PBNode.encode(toProtoBuf({
Data: data,
Links: links
}))
return serialized
}

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

@Gozala
Copy link
Contributor Author

Gozala commented Jun 4, 2020

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.

@vmx
Copy link
Member

vmx commented Jun 4, 2020

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants