Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion msgpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ exports.encode = function (value) {
}

exports.decode = decode;
exports.Decoder = Decoder;

// http://wiki.msgpack.org/display/MSGPACK/Format+specification
// I've extended the protocol to have two new types that were previously reserved.
Expand All @@ -18,6 +19,7 @@ exports.decode = decode;
function Decoder(buffer, offset) {
this.offset = offset || 0;
this.buffer = buffer;
this.bytesRemaining = buffer.length - this.offset;
}
Decoder.prototype.map = function (length) {
var value = {};
Expand Down Expand Up @@ -186,6 +188,11 @@ Decoder.prototype.parse = function () {
}
throw new Error("Unknown type 0x" + type.toString(16));
};
Decoder.prototype.decode = function () {
var rv = this.parse();
this.bytesRemaining = this.buffer.length - this.offset;
return rv;
};
function decode(buffer) {
var decoder = new Decoder(buffer);
var value = decoder.parse();
Expand Down Expand Up @@ -470,4 +477,3 @@ function sizeof(value) {
throw new Error("Unknown type " + type);
}