cbor-js icon indicating copy to clipboard operation
cbor-js copied to clipboard

Need guidance ASAP please __/\__

Open devtrix opened this issue 4 years ago • 1 comments

I have a CBOR encoded hex string that I need to decode. I need code to do something like this that happens on cbor.me.
I paste this on the right side, select "as text" checkbox and click the left arrow button [<--] where it displays the word Bytes. I want my object (output) to look like the left side.

What I am getting is an error "First argument to DataView constructor must be an ArrayBuffer" Here is my function: const hexToUint8 = hexString => new Uint8Array(hexString.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));

    -------------------------------
    Here the data is the hex string.
         var buf = hexToUint8(data).buffer;;                   
         let txt = CBOR.decode(buf);
         console.log(txt);

What I am getting is [ 1413762, { "0,185,105,41,195,142,244,129,7,241,142,49,34,135,59,67,222,97,130,201,53,90,174,65,16,206,61,51": { "84,101,115,116,67,111,108,108,101,99,116,105,111,110,48,48,86,111,108,51,52,49": 1 } } ] Rather than the representation on cbor.me. Like this: [1413762, {h'00B96929C38EF48107F18E3122873B43DE6182C9355AAE4110CE3D33': {'TestCollection00Vol341': 1}}]

My question is, what is this an array of: "0,185,105,41,195,142,244,129,7,241,142,49,34,135,59,67,222,97,130,201,53,90,174,65,16,206,61,51"?

Here is the CBOR hex string again: 821a00159282a1581c00b96929c38ef48107f18e3122873b43de6182c9355aae4110ce3d33a15654657374436f6c6c656374696f6e3030566f6c33343101

devtrix avatar Dec 11 '21 17:12 devtrix

No Problemo : https://jsbin.com/sehitunono/edit?js,console

birowo avatar Jan 26 '22 06:01 birowo