shamblett / cbor

A CBOR implementation for Dart
MIT License
36 stars 15 forks source link

Impossible to get same object between 2 libraries #50

Closed jerdesk closed 1 year ago

jerdesk commented 1 year ago

Hello,

I'm so confused because I would like to use your library in the decoding of CBOR Bytes.

The encoding is made by a node CBOR Library (cbor-x). With my Node.JS enconding I have the current object to encode : const data = [ { toto: '/3303/0/5700', bt: 1278887, v: 35.5 }, { t: 10, v: 34 }, { t: 20, v: 33 }, { t: 30, v: 32 }, { t: 40, v: 31 }, { t: 50, v: 30 } ]; let basicCbor = new Encoder() let basicBuff = basicCbor.encode(data); console.log(basicBuff.toString("base64"));

The base64 string is : htnf/4UZ4ACDZHRvdG9iYnRhdmwvMzMwMy8wLzU3MDAaABODp/tAQcAAAAAAANnf/4QZ4AGCYXRhdgoYItngAYIUGCHZ4AGCGB4YINngAYIYKBgf2eABghgyGB4=

When I try to decode the base64 string in Flutter with your Library, I do this : var bytes = base64.decode("htnf/4UZ4ACDZHRvdG9iYnRhdmwvMzMwMy8wLzU3MDAaABODp/tAQcAAAAAAANnf/4QZ4AGCYXRhdgoYItngAYIUGCHZ4AGCGB4YINngAYIYKBgf2eABghgyGB4="); final cborDecoded = cbor.decode(bytes); print(cborDecoded); But the result of the print is not the same, like : [[57344, [toto, bt, v], /3303/0/5700, 1278887, 35.5], [57345, [t, v], 10, 34], [20, 33], [30, 32], [40, 31], [50, 30]]

I can't understand why the object is not the same, what is my mistake ?

Thank you a lot for your help.

shamblett commented 1 year ago

Would it be possible to dump the byte string before encoding it to base64? I can then take that and decode it using this package, if that works then the prob is the base64 encoding/decoding.

jerdesk commented 1 year ago

I got it... So I used the library cbor-x to encode my cbor with nodeJS. To decode clearly in flutter with this library, I need to add an argument like this (before in Node JS) : let basicCbor = new Encoder({ useRecords: false });

Thank you for your help :)