paroga / cbor-js

The Concise Binary Object Representation (CBOR) data format (RFC7049) implemented in pure JavaScript.
MIT License
310 stars 51 forks source link

Problem with indefinite-length map #1

Closed ralscha closed 10 years ago

ralscha commented 10 years ago

Hi

I try to send a cbor message from a java back end to the browser. I use https://github.com/FasterXML/jackson-dataformat-cbor for the message encoding.

On the client cbor-js tries to decode the message and throws this exception: "Uncaught RangeError: Offset is outside the bounds of the DataView"

Here is a code snippet that demonstrates the problem:

var b = new Uint8Array([191,100,110,97,109,101,101,82,97,108,112,104,255]);
var o = CBOR.decode(b.buffer);

According to cbor.me http://cbor.me/?bytes=BF646E616D656552616C7068FF it's a valid cbor message.

It works with a fixed length map

var b = new Uint8Array([161,100,110,97,109,101,101,82,97,108,112,104]);
var o = CBOR.decode(b.buffer);

http://cbor.me/?bytes=A1646E616D656552616C7068

paroga commented 10 years ago

i didn't push my implementation of indefinite-length arrays/maps/strings to the github repository yet, but i implemented it already. if you can wait until next week i'll push the missing commits (i'm not at home atm)

ralscha commented 10 years ago

Thanks. I can wait I'm not in a hurry.

paroga commented 10 years ago

sorry for the the delay, but i just pushed commit dca0855fd71ee9e480881e6e1bccce6591ffa67b which implements decoding for indefinite length items

please let me know if it works for you now.

ralscha commented 10 years ago

Hi Works great. Thanks a lot.

paroga commented 10 years ago

cool to see other people using it. :-)