Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need guidance ASAP please __/\__ #32

Open
devtrix opened this issue Dec 11, 2021 · 1 comment
Open

Need guidance ASAP please __/\__ #32

devtrix opened this issue Dec 11, 2021 · 1 comment

Comments

@devtrix
Copy link

devtrix commented Dec 11, 2021

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

@ghost
Copy link

ghost commented Jan 26, 2022

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

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

No branches or pull requests

1 participant