kriszyp / msgpackr

Ultra-fast MessagePack implementation with extension for record and structural cloning / msgpack.org[JavaScript/NodeJS]

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

README.md#record-structure-extension-definition example doesn't work

xBZZZZ opened this issue · comments

README.md#record-structure-extension-definition says:

+--------+--------+--------+~~~~~~~~~~~~~~~~~~~~~~~~~+--------+--------+--------+
|  0xd4  |  0x72  |  0x40  | array: [ "foo", "bar" ] |  0x40  |  0x04  |  0x02  |
+--------+--------+--------+~~~~~~~~~~~~~~~~~~~~~~~~~+--------+--------+--------+

Which should generate an object that would correspond to JSON:

{ "foo": 4, "bar": 2}
but example doesn't work:
//this is in node.js
var m=require("msgpackr");
m.unpack(Buffer.of(0xD4,0x72,0x40,...m.pack(["foo","bar"]),0x40,0x04,0x02));

throws Uncaught Error: Unexpected end of MessagePack data

but if you remove second 0x40 it works:
//this is in node.js
var m=require("msgpackr");
m.unpack(Buffer.of(0xD4,0x72,0x40,...m.pack(["foo","bar"]),/*0x40, REMOVED*/0x04,0x02));

You are correct, thank you for pointing this!