Git Product home page Git Product logo

Comments (3)

rvagg avatar rvagg commented on June 5, 2024

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.

telamon avatar telamon commented on June 5, 2024

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.

rvagg avatar rvagg commented on June 5, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.