-
Notifications
You must be signed in to change notification settings - Fork 20
Discrepancy between util.serialize and DAGNode.create #28
Comments
#11 fixed this one, essentially, data is always expected to be a Buffer, we just didn't have a strict conversion. Please test master and let me know. |
No, this is now fixed. See the following reproduction: const dagPB = require('ipld-dag-pb');
const obj = { data: '{"Luck":0.4,"Proof":"<TEE signature>"}',
links:
[ { multihash: 'QmUxD5gZfKzm8UN4WaguAMAZjw2TzZ2ZUmcqm2qXPtais7',
name: 'payload',
size: 819 } ] };
dagPB.DAGNode.create(obj.data, obj.links, 'sha2-256', (error, dag) => {console.log(dag.toJSON())});
dagPB.util.serialize(obj, (error, serialized) => {dagPB.util.deserialize(serialized, (error, dag) => { console.log(dag.toJSON())})}); See the difference in Tested with ipld-dag-pb@0.10.0. |
See the different in the multihash of the link
The issue is that you are passing a It seems that we could indeed support both, currently, the util.serialize expects for the |
I think I got confused because in js-ipld-dag-cbor documentation you are passing to I would assume both libraries are using the same API, just a different serialization. Sadly, I do not think I will have time for PR at the moment. |
It is the same API, just dag-cbor takes json (because of the one to one mapping) and dag-pb takes DAGNode classes (pb aware objects). Nevertheless, it is indeed possible to achieve what you tried. I'll leave this issue open as a feature request, once my availability increases, I'll look into it again :) |
@diasdavid Rolled out a PR. PTAL. |
Thanks @atvanguard ! Let's continue tracking this on that PR #43 👍 |
I am seeing strange discrepancy between
util.serialize
andDAGNode.create
. Maybe I am using it wrong.I have the following object:
If I do:
Then the JSON output of DAGNode is:
But if I do
util.serialize
and thenutil.deserialize
, and do JSON output, then I get:Observe how
multihash
of links is different, andsize
value of the whole JSON.The text was updated successfully, but these errors were encountered: