Encoding/Decoding messagepack data with Node.js Buffers #37

Closed
matehat opened this Issue Dec 18, 2012 · 1 comment

Projects

None yet

1 participant

@matehat
matehat commented Dec 18, 2012

I'm using node-msgpack to encode and decode messages passed around between machines. One thing I'd like to be able to do is wrap raw Buffer data in an object and encode that with Messagepack.

msgpack = require('msgpack')
buf = <Buffer ac 48 65 6c 6c 6f 20 57 6f 72 6c 64 21>
obj = {foo: buf}
packed = msgpack.pack(obj)

In the example above, I wanted to do a consistency check on the raw bytes of buffers nested in an object. So buf was obtained like so :

buf = msgpack.pack("Hello World!")

In a perfect world, I would have obtained :

msgpack.unpack(new Buffer(msgpack.unpack(packed).foo));

#> "Hello World!"

Instead, I end up with -17. Digging up a little deeper, I end up with the following curiosity:

enc = 'ascii'
new Buffer(buf.toString(enc), enc)
#> <Buffer fd 48 65 6c 6c 6f 20 57 6f 72 6c 64 21>

buf
#> <Buffer ac 48 65 6c 6c 6f 20 57 6f 72 6c 64 21>

The first byte is the problem. I tried using different encoding with no luck. What is happening here and what can I do to do circumvent the issue?

@matehat
matehat commented Dec 29, 2012

This issue is not a bug on the side of msgpack. I've documented it on stackoverflow

@matehat matehat closed this Dec 29, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment