I made on node.js, this program, which has an anomaly. When I do decodeAllSync I get a vector of decimal numbers which has one fewer numbers than I get by reconverting the vector with encodeAsync. Why don't I get the same vector? Thank you
const cbor = require('cbor');
...
const results = cbor.decodeAllSync(output);
const input = cbor.encodeAsync(results);
console.log(output);
input.then(
function (x) {
var v=new Uint8Array(x);
console.log(v);
},
function () {
console.log("fail ");
});
I receive for the printout of the input:
Uint8Array [
129,
210,
132,
77,
...
I receive for the printout of the output:
Uint8Array [
210,
132,
77,
...
cbor.decodeAllSync
with n arguments returns an array with n entries. So what you encode has an extra pair of []
around it.
> cbor.decodeAllSync(cbor.encode(1))
[ 1 ]
> cbor.decode(cbor.encode(1))
1