Comments (3)
yeah:
$ cborg hex2diag a50102032620012158209b58eab4a0bd78474117f6f23a6c457cc5351d7b6bbeab62271d5ce2c8fdbda4225820db189f7af9cf4eb6149d6204ebe0821b0ed95193f10dc84044fac1e3f26c4a50a16b6372656450726f7465637402
a5 # map(5)
01 # uint(1)
02 # uint(2)
03 # uint(3)
26 # negint(-7)
20 # negint(-1)
01 # uint(1)
21 # negint(-2)
58 20 # bytes(32)
9b58eab4a0bd78474117f6f23a6c457cc5351d7b6bbe # "\x9bXê´\xa0½xGA\x17öò:lE|Å5\x1d{k¾"
ab62271d5ce2c8fdbda4 # "«b'\x1d\âÈý½¤"
22 # negint(-3)
58 20 # bytes(32)
db189f7af9cf4eb6149d6204ebe0821b0ed95193f10d # "Û\x18\x9fzùÏN¶\x14\x9db\x04ëà\x82\x1b\x0eÙQ\x93ñ\x0d"
c84044fac1e3f26c4a50 # "È@DúÁãòlJP"
a1 # map(1)
6b # string(11)
6372656450726f74656374 # "credProtect"
02 # uint(2)
So the problem here is that you have two maps, but they are not contained within a parent object, it doesn't know what to do with 2 dangling maps.
This would work:
cborg.decode(Buffer.from('a50102032620012158209b58eab4a0bd78474117f6f23a6c457cc5351d7b6bbeab62271d5ce2c8fdbda4225820db189f7af9cf4eb6149d6204ebe0821b0ed95193f10dc84044fac1e3f26c4a50', 'hex'), { useMaps: true })
// ->
Map(5) {
1 => 2,
3 => -7,
-1 => 1,
-2 => Uint8Array(32) [
155, 88, 234, 180, 160, 189, 120, 71,
65, 23, 246, 242, 58, 108, 69, 124,
197, 53, 29, 123, 107, 190, 171, 98,
39, 29, 92, 226, 200, 253, 189, 164
],
-3 => Uint8Array(32) [
219, 24, 159, 122, 249, 207, 78, 182,
20, 157, 98, 4, 235, 224, 130, 27,
14, 217, 81, 147, 241, 13, 200, 64,
68, 250, 193, 227, 242, 108, 74, 80
]
}
and this would work:
cborg.decode(Buffer.from('a16b6372656450726f7465637402', 'hex'), { useMaps: true })
// ->
Map(1) { 'credProtect' => 2 }
and finally if you really wanted it to work you could join them together, maybe with an array:
cborg.decode(Buffer.from('82a50102032620012158209b58eab4a0bd78474117f6f23a6c457cc5351d7b6bbeab62271d5ce2c8fdbda4225820db189f7af9cf4eb6149d6204ebe0821b0ed95193f10dc84044fac1e3f26c4a50a16b6372656450726f7465637402', 'hex'), { useMaps: true })
// ->
[
Map(5) {
1 => 2,
3 => -7,
-1 => 1,
-2 => Uint8Array(32) [
155, 88, 234, 180, 160, 189, 120, 71,
65, 23, 246, 242, 58, 108, 69, 124,
197, 53, 29, 123, 107, 190, 171, 98,
39, 29, 92, 226, 200, 253, 189, 164
],
-3 => Uint8Array(32) [
219, 24, 159, 122, 249, 207, 78, 182,
20, 157, 98, 4, 235, 224, 130, 27,
14, 217, 81, 147, 241, 13, 200, 64,
68, 250, 193, 227, 242, 108, 74, 80
]
},
Map(1) { 'credProtect' => 2 }
]
Currently we have no support for read-until termination of an object; although it has been requested and shouldn't be too hard to do. I wrote up some notes in #75
from cborg.
I see. Those are two separate maps yes.
In my case that sequence was output by hardware.
Without read-until termination of object - there is no way to determine the size of the first map / offset of second map.
const m1 = decode(buffer)
const m2 = decode(buffer.slice(decode.decodedBytes))
from cborg.
see #93, I'll likely publish that as a 4.0.0 tomorrow if there's no feedback in the meantime
from cborg.
Related Issues (15)
- Buffer detection HOT 3
- ** operator HOT 1
- Needs a main entry in package.json HOT 2
- safari error HOT 3
- more low level decoding HOT 2
- better structuredClone support HOT 4
- parity with cbor-x HOT 3
- [Feature Request]: Encode as blobParts (may include blobs)
- Option to bail on duplicate map keys
- Decoding concatenated data items HOT 6
- Typings don't work when cborg is imported in a ESM project HOT 2
- Max encodable BigInt is smaller than max encodable Number? HOT 1
- Disallow certain types when decoding HOT 1
- Ability to configure width for cli diagnostic output HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cborg.