forked from pgriess/node-msgpack
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose # bytes left in buffer after unpack.
- If msgpack.unpack() does not consume the entire buffer, expose the number of bytes remaining as the 'msgpack.unpack.bytes_remaining' property.
- Loading branch information
Showing
3 changed files
with
40 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Verify that unpacking a buffer with extra bytes doesn't lose the extra data | ||
|
||
var assert = require('assert'); | ||
var msgpack = require('msgpack'); | ||
var buffer = require('buffer'); | ||
|
||
// Object to test with | ||
var o = [1, 2, 3]; | ||
|
||
// Create two buffers full of packed data, 'b' and 'bb', with the latter | ||
// containing 3 extra bytes | ||
var b = msgpack.pack(o); | ||
var bb = new buffer.Buffer(b.length + 3); | ||
b.copy(bb, 0, 0, b.length); | ||
|
||
// Expect no remaining bytes when unpacking 'b' | ||
assert.deepEqual(msgpack.unpack(b), o); | ||
assert.deepEqual(msgpack.unpack.bytes_remaining, 0); | ||
|
||
// Expect 3 remaining bytes when unpacking 'bb' | ||
assert.deepEqual(msgpack.unpack(bb), o); | ||
assert.equal(msgpack.unpack.bytes_remaining, 3); |
File renamed without changes.