Coder Social home page Coder Social logo

kawanet / msgpack-lite Goto Github PK

View Code? Open in Web Editor NEW
980.0 23.0 126.0 481 KB

Fast Pure JavaScript MessagePack Encoder and Decoder / msgpack.org[JavaScript]

Home Page: https://www.npmjs.com/package/msgpack-lite

License: MIT License

Shell 0.82% JavaScript 99.01% HTML 0.17%

msgpack-lite's Introduction

msgpack-lite npm version Build Status

Fast Pure JavaScript MessagePack Encoder and Decoder

Sauce Test Status

Online demo: http://kawanet.github.io/msgpack-lite/

Features

  • Pure JavaScript only (No node-gyp nor gcc required)
  • Faster than any other pure JavaScript libraries on node.js v4
  • Even faster than node-gyp C++ based msgpack library (90% faster on encoding)
  • Streaming encoding and decoding interface is also available. It's more faster.
  • Ready for Web browsers including Chrome, Firefox, Safari and even IE8
  • Tested on Node.js v0.10, v0.12, v4, v5 and v6 as well as Web browsers

Encoding and Decoding MessagePack

var msgpack = require("msgpack-lite");

// encode from JS Object to MessagePack (Buffer)
var buffer = msgpack.encode({"foo": "bar"});

// decode from MessagePack (Buffer) to JS Object
var data = msgpack.decode(buffer); // => {"foo": "bar"}

// if encode/decode receives an invalid argument an error is thrown

Writing to MessagePack Stream

var fs = require("fs");
var msgpack = require("msgpack-lite");

var writeStream = fs.createWriteStream("test.msp");
var encodeStream = msgpack.createEncodeStream();
encodeStream.pipe(writeStream);

// send multiple objects to stream
encodeStream.write({foo: "bar"});
encodeStream.write({baz: "qux"});

// call this once you're done writing to the stream.
encodeStream.end();

Reading from MessagePack Stream

var fs = require("fs");
var msgpack = require("msgpack-lite");

var readStream = fs.createReadStream("test.msp");
var decodeStream = msgpack.createDecodeStream();

// show multiple objects decoded from stream
readStream.pipe(decodeStream).on("data", console.warn);

Decoding MessagePack Bytes Array

var msgpack = require("msgpack-lite");

// decode() accepts Buffer instance per default
msgpack.decode(Buffer([0x81, 0xA3, 0x66, 0x6F, 0x6F, 0xA3, 0x62, 0x61, 0x72]));

// decode() also accepts Array instance
msgpack.decode([0x81, 0xA3, 0x66, 0x6F, 0x6F, 0xA3, 0x62, 0x61, 0x72]);

// decode() accepts raw Uint8Array instance as well
msgpack.decode(new Uint8Array([0x81, 0xA3, 0x66, 0x6F, 0x6F, 0xA3, 0x62, 0x61, 0x72]));

Command Line Interface

A CLI tool bin/msgpack converts data stream from JSON to MessagePack and vice versa.

$ echo '{"foo": "bar"}' | ./bin/msgpack -Jm | od -tx1
0000000    81  a3  66  6f  6f  a3  62  61  72

$ echo '{"foo": "bar"}' | ./bin/msgpack -Jm | ./bin/msgpack -Mj
{"foo":"bar"}

Installation

$ npm install --save msgpack-lite

Tests

Run tests on node.js:

$ make test

Run tests on browsers:

$ make test-browser-local
open the following url in a browser:
http://localhost:4000/__zuul

Browser Build

Browser version msgpack.min.js is also available. 50KB minified, 14KB gziped.

<!--[if lte IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.1.10/es5-shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/json3/3.3.2/json3.min.js"></script>
<![endif]-->
<script src="https://rawgit.com/kawanet/msgpack-lite/master/dist/msgpack.min.js"></script>
<script>
// encode from JS Object to MessagePack (Uint8Array)
var buffer = msgpack.encode({foo: "bar"});

// decode from MessagePack (Uint8Array) to JS Object
var array = new Uint8Array([0x81, 0xA3, 0x66, 0x6F, 0x6F, 0xA3, 0x62, 0x61, 0x72]);
var data = msgpack.decode(array);
</script>

MessagePack With Browserify

Step #1: write some code at first.

var msgpack = require("msgpack-lite");
var buffer = msgpack.encode({"foo": "bar"});
var data = msgpack.decode(buffer);
console.warn(data); // => {"foo": "bar"}

Proceed to the next steps if you prefer faster browserify compilation time.

Step #2: add browser property on package.json in your project. This refers the global msgpack object instead of including whole of msgpack-lite source code.

{
  "dependencies": {
    "msgpack-lite": "*"
  },
  "browser": {
    "msgpack-lite": "msgpack-lite/global"
  }
}

Step #3: compile it with browserify and uglifyjs.

browserify src/main.js -o tmp/main.browserify.js -s main
uglifyjs tmp/main.browserify.js -m -c -o js/main.min.js
cp node_modules/msgpack-lite/dist/msgpack.min.js js/msgpack.min.js

Step #4: load msgpack.min.js before your code.

<script src="js/msgpack.min.js"></script>
<script src="js/main.min.js"></script>

Interoperability

It is tested to have basic compatibility with other Node.js MessagePack modules below:

Benchmarks

A benchmark tool lib/benchmark.js is available to compare encoding/decoding speed (operation per second) with other MessagePack modules. It counts operations of 1KB JSON document in 10 seconds.

$ npm install msgpack msgpack-js msgpack-js-v5 msgpack-unpack msgpack5 notepack
$ npm run benchmark 10
operation op ms op/s
buf = Buffer(JSON.stringify(obj)); 1055200 10000 105520
obj = JSON.parse(buf); 863800 10000 86380
buf = require("msgpack-lite").encode(obj); 969100 10000 96910
obj = require("msgpack-lite").decode(buf); 600300 10000 60030
buf = require("msgpack").pack(obj); 503500 10001 50344
obj = require("msgpack").unpack(buf); 560200 10001 56014
buf = Buffer(require("msgpack.codec").msgpack.pack(obj)); 653500 10000 65349
obj = require("msgpack.codec").msgpack.unpack(buf); 367500 10001 36746
buf = require("msgpack-js-v5").encode(obj); 189500 10002 18946
obj = require("msgpack-js-v5").decode(buf); 408900 10000 40890
buf = require("msgpack-js").encode(obj); 189200 10000 18920
obj = require("msgpack-js").decode(buf); 375600 10002 37552
buf = require("msgpack5")().encode(obj); 110500 10009 11040
obj = require("msgpack5")().decode(buf); 165500 10000 16550
buf = require("notepack")().encode(obj); 847800 10000 84780
obj = require("notepack")().decode(buf); 599800 10000 59980
obj = require("msgpack-unpack").decode(buf); 48100 10002 4809

Streaming benchmark tool lib/benchmark-stream.js is also available. It counts milliseconds for 1,000,000 operations of 30 bytes fluentd msgpack fragment. This shows streaming encoding and decoding are super faster.

$ npm run benchmark-stream 2
operation (1000000 x 2) op ms op/s
stream.write(msgpack.encode(obj)); 1000000 3027 330360
stream.write(notepack.encode(obj)); 1000000 2012 497017
msgpack.Encoder().on("data",ondata).encode(obj); 1000000 2956 338294
msgpack.createEncodeStream().write(obj); 1000000 1888 529661
stream.write(msgpack.decode(buf)); 1000000 2020 495049
stream.write(notepack.decode(buf)); 1000000 1794 557413
msgpack.Decoder().on("data",ondata).decode(buf); 1000000 2744 364431
msgpack.createDecodeStream().write(buf); 1000000 1341 745712

Test environment: msgpack-lite 0.1.14, Node v4.2.3, Intel(R) Xeon(R) CPU E5-2666 v3 @ 2.90GHz

MessagePack Mapping Table

The following table shows how JavaScript objects (value) will be mapped to MessagePack formats and vice versa.

Source Value MessagePack Format Value Decoded
null, undefined nil format family null
Boolean (true, false) bool format family Boolean (true, false)
Number (32bit int) int format family Number (int or double)
Number (64bit double) float format family Number (double)
String str format family String
Buffer bin format family Buffer
Array array format family Array
Map map format family Map (if usemap=true)
Object (plain object) map format family Object (or Map if usemap=true)
Object (see below) ext format family Object (see below)

Note that both null and undefined are mapped to nil 0xC1 type. This means undefined value will be upgraded to null in other words.

Extension Types

The MessagePack specification allows 128 application-specific extension types. The library uses the following types to make round-trip conversion possible for JavaScript native objects.

Type Object Type Object
0x00 0x10
0x01 EvalError 0x11 Int8Array
0x02 RangeError 0x12 Uint8Array
0x03 ReferenceError 0x13 Int16Array
0x04 SyntaxError 0x14 Uint16Array
0x05 TypeError 0x15 Int32Array
0x06 URIError 0x16 Uint32Array
0x07 0x17 Float32Array
0x08 0x18 Float64Array
0x09 0x19 Uint8ClampedArray
0x0A RegExp 0x1A ArrayBuffer
0x0B Boolean 0x1B Buffer
0x0C String 0x1C
0x0D Date 0x1D DataView
0x0E Error 0x1E
0x0F Number 0x1F

Other extension types are mapped to built-in ExtBuffer object.

Custom Extension Types (Codecs)

Register a custom extension type number to serialize/deserialize your own class instances.

var msgpack = require("msgpack-lite");

var codec = msgpack.createCodec();
codec.addExtPacker(0x3F, MyVector, myVectorPacker);
codec.addExtUnpacker(0x3F, myVectorUnpacker);

var data = new MyVector(1, 2);
var encoded = msgpack.encode(data, {codec: codec});
var decoded = msgpack.decode(encoded, {codec: codec});

function MyVector(x, y) {
  this.x = x;
  this.y = y;
}

function myVectorPacker(vector) {
  var array = [vector.x, vector.y];
  return msgpack.encode(array); // return Buffer serialized
}

function myVectorUnpacker(buffer) {
  var array = msgpack.decode(buffer);
  return new MyVector(array[0], array[1]); // return Object deserialized
}

The first argument of addExtPacker and addExtUnpacker should be an integer within the range of 0 and 127 (0x0 and 0x7F). myClassPacker is a function that accepts an instance of MyClass, and should return a buffer representing that instance. myClassUnpacker is the opposite: it accepts a buffer and should return an instance of MyClass.

If you pass an array of functions to addExtPacker or addExtUnpacker, the value to be encoded/decoded will pass through each one in order. This allows you to do things like this:

codec.addExtPacker(0x00, Date, [Number, msgpack.encode]);

You can also pass the codec option to msgpack.Decoder(options), msgpack.Encoder(options), msgpack.createEncodeStream(options), and msgpack.createDecodeStream(options).

If you wish to modify the default built-in codec, you can access it at msgpack.codec.preset.

Custom Codec Options

msgpack.createCodec() function accepts some options.

It does NOT have the preset extension types defined when no options given.

var codec = msgpack.createCodec();

preset: It has the preset extension types described above.

var codec = msgpack.createCodec({preset: true});

safe: It runs a validation of the value before writing it into buffer. This is the default behavior for some old browsers which do not support ArrayBuffer object.

var codec = msgpack.createCodec({safe: true});

useraw: It uses raw formats instead of bin and str.

var codec = msgpack.createCodec({useraw: true});

int64: It decodes msgpack's int64/uint64 formats with int64-buffer object.

var codec = msgpack.createCodec({int64: true});

binarraybuffer: It ties msgpack's bin format with ArrayBuffer object, instead of Buffer object.

var codec = msgpack.createCodec({binarraybuffer: true, preset: true});

uint8array: It returns Uint8Array object when encoding, instead of Buffer object.

var codec = msgpack.createCodec({uint8array: true});

usemap: Uses the global JavaScript Map type, if available, to unpack MessagePack map elements.

var codec = msgpack.createCodec({usemap: true});

Compatibility Mode

The compatibility mode respects for msgpack's old spec. Set true to useraw.

// default mode handles both str and bin formats individually
msgpack.encode("Aa"); // => <Buffer a2 41 61> (str format)
msgpack.encode(new Buffer([0x41, 0x61])); // => <Buffer c4 02 41 61> (bin format)

msgpack.decode(new Buffer([0xa2, 0x41, 0x61])); // => 'Aa' (String)
msgpack.decode(new Buffer([0xc4, 0x02, 0x41, 0x61])); // => <Buffer 41 61> (Buffer)

// compatibility mode handles only raw format both for String and Buffer
var options = {codec: msgpack.createCodec({useraw: true})};
msgpack.encode("Aa", options); // => <Buffer a2 41 61> (raw format)
msgpack.encode(new Buffer([0x41, 0x61]), options); // => <Buffer a2 41 61> (raw format)

msgpack.decode(new Buffer([0xa2, 0x41, 0x61]), options); // => <Buffer 41 61> (Buffer)
msgpack.decode(new Buffer([0xa2, 0x41, 0x61]), options).toString(); // => 'Aa' (String)

Repository

See Also

License

The MIT License (MIT)

Copyright (c) 2015-2016 Yusuke Kawasaki

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

msgpack-lite's People

Contributors

cvermilion avatar doodzik avatar fearthecowboy avatar jessearmand avatar kawanet avatar maciejhirsz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

msgpack-lite's Issues

Decode ArrayBuffer

Version: 0.1.20

Description:
An error is thrown when trying to decode an ArrayBuffer

/home/luigi/pack/node_modules/msgpack-lite/lib/read-core.js:15
    if (!func) throw new Error("Invalid type: " + (type ? ("0x" + type.toString(16)) : type));
               ^

Error: Invalid type: undefined
    at Codec.decode (/home/luigi/pack/node_modules/msgpack-lite/lib/read-core.js:15:22)
    at DecodeBuffer.fetch (/home/luigi/pack/node_modules/msgpack-lite/lib/decode-buffer.js:54:21)
    at DecodeBuffer.read (/home/luigi/pack/node_modules/msgpack-lite/lib/decode-buffer.js:39:28)
    at Object.decode (/home/luigi/pack/node_modules/msgpack-lite/lib/decode.js:10:18)
    at Object.<anonymous> (/home/luigi/pack/index.js:10:9)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)

Test case:

'use strict';

const msgpack = require('msgpack-lite');

const arr = new Uint8Array([163, 102, 111, 111]);

msgpack.decode(arr);         // Works as intended
msgpack.decode(arr.buffer);  // Throws

Is this expected? Should an ArrayBuffer be explicitly converted to a typed array before decoding it?
I stumbled upon this when trying to decode a message from a WebSocket object whose binaryType was set to arraybuffer.

Newbie Question: How to unpack a base64 encoded string which encapsulates data

Hi,

We have a service that packs some data (int, int, boolean) and encodes it (base 64 encoding). It spits out the base64 encoded string. Now I am creating a client side javascript that decodes this string. How do I use it using msgpack-lite? I've read that a multi-level msgpack requires a different handling. Please advise.

Cheers!

ES6 Modules + Rollup

I don't know if this is something you're interested in, so I figured I'd open an issue before submitting any pull requests.

Basically I've forked this repo and its dependencies and made them all into ES6 modules that build with rollup:

https://github.com/Benjamin-Dobell/msgpack-lite
https://github.com/Benjamin-Dobell/event-lite
https://github.com/Benjamin-Dobell/int64-buffer

You can't have circular dependencies in ES6 modules (although it's probably good to avoid them regardless) so unfortunately I did have to make some pretty drastic changes to the project. I haven't tried to make it pretty at this point, as I just wanted this done for my own purposes. However, if you're interested I'll submit pull requests and clean-up accordingly.

Possible for c++ bindings?

I've tested bson, pson, msgpack5 and everything.

This module is the fastest. It's right next to speeds of JSON and I love it. I am wondering, if you could even push it for more performance with a native c/c++ binding of it?

I love it, thanks for all your hard work kawanet.

Decoding 0-length buffer throws unhelpful error message

msgpack.decode(new Buffer(''))

throws an Error, without a message or a stack.

I inspected it in the node REPL:

> strangeError
[Error]
> strangeError.stack
undefined
> strangeError.name
'Error'
> strangeError.message
''
> strangeError instanceof Error
true

64bit Integer

The current decoder decodes msgpack's int 64 (0xd3) as a JS's Number which means double.

https://www.npmjs.com/package/node-int64

JavaScript Numbers are represented as IEEE 754 double-precision floats. Unfortunately, this means they lose integer precision for values beyond +/- 2^^53. For projects that need to accurately handle 64-bit ints, such as node-thrift, a performant, Number-like class is needed. Int64 is that class.

It looks fit for us as node-int64 has internal raw Buffer object with big endian byte sequence.

New option: initial and maximum buffer size

At the commit d4cb247, it allows modifying initialSize of internal buffer.

https://github.com/kawanet/msgpack-lite/blob/d4cb247/lib/encoder.js#L15

function Encoder(initialSize,output) {

The change was once reverted by the reason mentioned at issue #6 however.

At the commit d00df50, it gives constant MIN_BUFFER_SIZE and MAX_BUFFER_SIZE instead.

-var BUFFER_LENGTH = 2048;
+var MIN_BUFFER_SIZE = 2048;
+var MAX_BUFFER_SIZE = 65536;

Some application may know the best size of the internal buffers.

Question: is there a ways to determine byte size of the packed message without actually decoding it?

The use case might be to only determine boudaries of the msgpack or count sequenced msgpacked items.

e.g.

var data1 = encode("some data"); // <Buffer a9 73 6f 6d 65 20 64 61 74 61>
var data2 = encode(123); // <Buffer 7b>
var data = Buffer.concat([data1, data2]);
// hypothetical api:
decodeSize(data) // -> 10
decodeSize(data.slice(10)) // -> 1
decodeSize(data.slice(0, 9)) // -> undefined (truncated data)

Perhaps an interface similar to Decode().

Decode().on('data', (n) => console.log(`number of bytes: ${n}`)).decodeSize(data);

Another question: is there a way to encode message to provided buffer with offset and boundary length?

// hypothetical api: encode(data[, buffer[, offset[, maxLength]]])
encode("some data", new Buffer(100), 10, 50);

new option: concat encoding buffer per message

See also: Use of Buffer is killing performance. #2

The current streaming encoder MAY split a single msgpack message into multiple chunks separated.

This works fine when writing messages to a file and socket.
This is required when encoding a huge message.

However, at some purpose such like sending messages via WebSocket, separated message would not be welcomed.

Tag recent releases in GitHub?

It looks like the latest version available from the GitHub release page is 0.1.21. Do you mind adding a release for 0.1.26 (and future releases)? It would be very helpful in packaging this library for use in ClojureScript. Thanks!

Use of Buffer is killing performance.

Howdy!

I'm using msgpack-lite in a very high performance situation, and I've discovered a bit about some of the way that you're doing some stuff that's robbing you of performance greatly.

It turns out that any use of new Buffer(...) or Buffer.concat()is terrible for performance.

Reallocating a buffer during flush() pretty much guarantees that you're losing some very valuable performance, and returning objects from encode() kills it too.

I started tweaking msgpack-lite and in my case exposed the Encoder type out to the consumer, and have it keep it's internal buffer, and only reallocate if the size of the current encode() is exceeding it.

I use it like this now:

    var msgpack = require("msgpack-lite");
    // ....

    var enc = new Encoder();
    // ... 

    /// in a tight loop somewhere
    // msg is some object from somewhere
    var buf = enc.encode( msg ); 

    // buf is .slice() 'd  from the internal buffer in the object 
    // slice() is a cheap operation, since it doesn't actually allocate more data
    // it just creates a view

   // at that point, you can do what you want with it...
   somestream.write( buf );

Using msgpack-lite in this way, I'm able to encode and process around 200,000 messages per second in on a single core in a VM.

I'm working on a pull request for the changes, once I clean up the hacking mess I did :)

Incidentally, in buffer-lite.js it mentions:

    // new Buffer(string, "utf-8") is SLOWER then below

I imagine that Buffer allocation speed is what's really killing that. If you pre-allocate and re-use the buffer, and just use buffer.write(string, 'utf-8') it appears to be much better.

Roadmap question

Hi, I was wondering what was the development status for this project. My Library, Kalm Heavily uses msgpack-lite. Are there plans to ensure compatibility with modern node releases ? Cross-platform compatibility ?

I would like to help, if possible. Do you accept PRs ?

Cheers!

Requiring just decoder is broken

Until of the newest version (1.1.19) released today, I was able to require just the decoder portion of the code (using webpack), like this:

const decode = require('msgpack-lite/lib/decode').decode;

This worked great, because I didn't need to unnecessarily load the encoding code into the client, which was only decoding. It looks like now the decoder requires the entire repo (as of this commit 189b604), which causes two problems:

  1. I now have to load the encoding scripts, which I don't really need and
  2. It causes a circular dependency, which is screwing up webpack.

Is it possible to revert this change and find another way to accomplish whatever you were trying to do in that commit?

Thanks! (And thanks for writing/maintaining this repo in the first place!)

Is it possible to stream data to msgpack to decode?

For example, if I want to build an express middleware that parses MessagePack bodies, it seems I have to read the entire body into memory before passing it to msgpack.decode, which seems inefficient for large bodies.

If msgpack.decode could handle a readble stream, then it could begin parsing the data before the all of the data has been received from the source, which would be more efficient than waiting for the entire stream to be read before parsing it.

Just to be clear, I'm talking about decoding a single MessagePack encoded object from a stream, not decoding a stream of MessagePack objects.

Example use case

function parseMsgpackBody(req, res, next) {

  // only parse when Content-Type: application/msgpack
  if(req.headers['content-type'] === 'application/msgpack') {

    // msgpack's awesome new API for reading directly from a stream
    msgpack.decode(req, function(err, data) {
      if(err) {
        res.sendStatus(400) // invalid msgpack object
      }

      // set the request's body property to the decoded msgpack object
      req.body = data
    }
  }

  // call the next middleware
  next()
}

const app = express()
app.use(parseMsgPackBody)

BufferShortageError on Mac

I've tried multiple versions of Node on Mac and I keep getting BufferShortageError.
This occurs during benchmarking with buffers of around 5kb. This doesn't happen on Linux.

You can get the code here: https://github.com/fed135/Kalm/tree/master/tests/benchmarks
(You can change the duration of the tests in /tests/settings.js)

node tests/benchmarks

/Users/frederic/node/Kalm/node_modules/msgpack-lite/lib/read-format.js:74
if (end > buffer.length) throw new BufferShortageError();

Cursor streaming buffer or abstract class

This package (will) support the following usages.

usage input output
1 var buf = msgpack.encode(obj) 1 object 1 msgpack
2 msgpack.Encoder().on("data", onData).encode(obj) objects msgpacks
3 msgpack.createEncodeStream().pipe(stream) objects streaming
4 var obj = msgpack.decode(buf) 1 msgpack 1 object
5 msgpack.Decoder().on("data", onData).decode(buf) msgpacks objects
6 stream.pipe(msgpack.createDecodeStream()) streaming objects

it seems to need a kind of Encoder abstract class to implement concat option described on issue #5 without any performance penalties.

After the refactoring works done recently, both Encoder and Decoder class are smaller than before. However, it seems EventEmitter-style on usage 2 and 5 looks better to be separated with other usages.

Encoder and Decoder classes could be separated to an abstract class for all usages above and a subclass supporting EventEmitter.

decode Array and Uint8Array

The current version of msgpack.decode() accepts only Buffer instance as node.js supports Buffer. On browser environment, it'd be useful when msgpack.decode() accepts plain old Array and Uint8Array as well as Buffer.

See also:

  • msgpack.decode(new Uint8Array(data)) leads to "Uncaught TypeError: this.readUInt32BE is not a function" #16
  • 64bit int decode error: Object doesn't support property or method 'readInt32BE' #27

Example from README.md is not working.

I tried:

var fs = require("fs");
var msgpack = require("msgpack-lite");

var writeStream = fs.createWriteStream("test.msp");
var encodeStream = msgpack.createEncodeStream();
encodeStream.pipe(writeStream);

// send multiple objects to stream
encodeStream.write({foo: "bar"});
encodeStream.write({baz: "qux"});

I am on Windows 8.1 and tried Node versions 0.12.2, 4.2.0, 4.2.2 and 5.0.0.
The script always creates an empty "test.msp". It seems like https://github.com/kawanet/msgpack-lite/blob/master/lib/encode-stream.js#L26 is never called.

Separating Encoder and Decoder for browsers

The module has both interfaces of encoder and decoder. It might be better to have a one side interface than two for some cases such as a web client which sends msgpack but does not receive.

var decode = require('msgpack').decode; // this load full (both) interfaces per default
var decode = require('msgpack-lite/lib/decode').decode; // this should load less dependencies than above
var encode = require('msgpack-lite/lib/encode').encode; // ditto

See #33

Noty support encode/decode for MongoDB ObjectId.

// This is a mongodb document.
var doc = {
     _id: ObjectId,
    ....
}
var encodeObjectId = msgpack.encode(doc._id)
var decodeObjectId = msgpack.decode(encodeObjectId)

decodeObjectId is { _bsontype: 'ObjectID', id: 'XOรบ๏ฟฝHยง%ยค๏ฟฝรฟ\u0016\u001a' }

Encoded binary is different from other library

Thank you for great library!

Now, I have a trouble that a converted binary is different from other library.
I am unsure of msgpack, so, I could not know which result is right or my json data is wrong data.
I am sorry about my bad English...

Source json data

[["Layer",{"applyMatrix":true,"locked":true,"children":[["Raster",{"applyMatrix":false,"matrix":[1.616161616161616,0,0,1.616161616161616,400.00000000000006,248.42105263157896],"locked":true,"source":"/i/cs/21/11/fd7ca8286be2f256b3edd55a84f31565.png"}]]}],["Layer",{"applyMatrix":true,"children":[["MyText",{"applyMatrix":false,"matrix":[1,0,0,1,42.10526315789473,82.49999999999999],"lockScalingY":true,"lockScalingXY":true,"content":"Company Name","fontId":"1472","textTitleTypeId":3,"fontFamily":"\"Open Sans\",\"serif\"","fontSize":32.67836257309941,"font":"\"Open Sans\",\"serif\"","leading":39.214035087719296,"maxWidth":715.7894736842106}],["MyText",{"applyMatrix":false,"matrix":[1,0,0,1,42.10526315789473,154.07894736842107],"lockScalingY":true,"lockScalingXY":true,"content":"Full Name","fontId":"1472","textTitleTypeId":2,"fontFamily":"\"Open Sans\",\"serif\"","fontSize":53.47368421052631,"font":"\"Open Sans\",\"serif\"","leading":64.16842105263157,"maxWidth":715.7894736842106}],["MyText",{"applyMatrix":false,"matrix":[1,0,0,1,42.10526315789473,196.18421052631578],"lockScalingY":true,"lockScalingXY":true,"content":"Job Title","fontId":"1472","textTitleTypeId":4,"fontFamily":"\"Open Sans\",\"serif\"","fontSize":26.736842105263154,"font":"\"Open Sans\",\"serif\"","leading":32.084210526315786,"maxWidth":715.7894736842106}],["MyText",{"applyMatrix":false,"matrix":[1,0,0,1,42.10526315789473,263.55263157894734],"lockScalingY":true,"lockScalingXY":true,"content":"Email","fontId":"1472","textTitleTypeId":5,"fontFamily":"\"Open Sans\",\"serif\"","fontSize":23.766081871345026,"font":"\"Open Sans\",\"serif\"","leading":28.51929824561403,"maxWidth":715.7894736842106}],["MyText",{"applyMatrix":false,"matrix":[1,0,0,1,42.10526315789473,301.4473684210526],"lockScalingY":true,"lockScalingXY":true,"content":"Phone","fontId":"1472","textTitleTypeId":6,"fontFamily":"\"Open Sans\",\"serif\"","fontSize":23.766081871345026,"font":"\"Open Sans\",\"serif\"","leading":28.51929824561403,"maxWidth":715.7894736842106}],["MyText",{"applyMatrix":false,"matrix":[1,0,0,1,42.10526315789473,339.34210526315786],"lockScalingY":true,"lockScalingXY":true,"content":"Address Lines","fontId":"1472","textTitleTypeId":21,"fontFamily":"\"Open Sans\",\"serif\"","fontSize":23.766081871345026,"font":"\"Open Sans\",\"serif\"","leading":28.51929824561403,"maxWidth":715.7894736842106}],["MyText",{"applyMatrix":false,"matrix":[1,0,0,1,42.10526315789473,406.7105263157895],"lockScalingY":true,"lockScalingXY":true,"content":"Web","fontId":"1472","textTitleTypeId":10,"fontFamily":"\"Open Sans\",\"serif\"","fontSize":23.766081871345026,"font":"\"Open Sans\",\"serif\"","leading":28.51929824561403,"maxWidth":715.7894736842106}],["Path",{"applyMatrix":true,"segments":[[[719.925436,69.147025],[39,19],[-39,-19]],[[640.925436,58.147025],[19,-8],[-19,8]],[[591.925436,104.147025],[6,-12],[-6,12]],[[573.925436,142.147025],[9,-6],[-9,6]],[[546.925436,152.147025],[4,0],[-4,0]],[[442.925436,132.147025],[30,12],[-30,-12]],[[353.925436,151.147025],[17,-13],[-17,13]],[[305.925436,237.147025],[4,-21],[-4,21]],[[303.925436,341.147025],[-19,-25],[-1,1]],[[265.925436,364.147025],[48,3],[-48,-3]],[[212.925436,390.147025],[21,-14],[-21,14]],[[161.925436,414.147025],[8,-16],[-8,16]],[[189.925436,462.147025],[-41,-2],[41,2]],[[303.925436,416.147025],[-7,16],[7,-16]],[[337.925436,390.147025],[-11,-3],[11,3]],[[363.925436,410.147025],[-25,-8],[25,8]],[[396.925436,422.147025],[-15,1],[15,-1]],[[424.925436,422.147025],[-7,8],[7,-8]],[[431.925436,435.147025],[-6,-6],[6,6]],[[492.925436,447.147025],[-41,5],[41,-5]],[[564.925436,436.147025],[0,2],[0,-2]],[[547.925436,425.147025],[18,-1],[-18,1]],[[512.925436,426.147025],[20,5],[-20,-5]],[[476.925436,409.147025],[0,18],[0,-18]],[[474.925436,379.147025],[21,10],[-21,-10]],[476.925436,340.147025],[[481.925436,312.147025],[-12,15],[12,-15]],[[518.925436,310.147025],[1,-13],[-1,13]],[[507.925436,345.147025],[0,-14],[0,14]],[[509.925436,375.147025],[8,-19],[-8,19]],[[500.925436,413.147025],[-2,-7],[2,7]],[[507.925436,434.147025],[-14,2],[14,-2]],[[526.925436,416.147025],[4,21],[-4,-21]],[[586.925436,313.147025],[-22,14],[22,-14]],[[644.925436,240.147025],[-9,17],[9,-17]],[[694.925436,160.147025],[-7,18],[7,-18]],[[701.925436,140.147025],[5,9],[22,-5]],[[734.925436,130.147025],[-4,9],[4,-9]],[[746.925436,107.147025],[5,9],[-5,-9]],[[727.925436,92.147025],[5,12],[-5,-12]],[719.925436,70.147025],[719.925436,70.147025]],"fillColor":[1,1,1],"strokeWidth":0.8421052631578947}]]}]]

Converted binary from http://kawanet.github.io/msgpack-lite/

92 92 A5 4C 61 79 65 72 83 AB 61 70 70 6C 79 4D 61 74 72 69 78 C3 A6 6C 6F 63 6B 65 64 C3 A8 63 68 69 6C 64 72 65 6E 91 92 A6 52 61 73 74 65 72 84 AB 61 70 70 6C 79 4D 61 74 72 69 78 C2 A6 6D 61 74 72 69 78 96 CB 3F F9 DB CC 48 67 6F 30 00 00 CB 3F F9 DB CC 48 67 6F 30 CB 40 79 00 00 00 00 00 01 CB 40 6F 0D 79 43 5E 50 D8 A6 6C 6F 63 6B 65 64 C3 A6 73 6F 75 72 63 65 DA 00 30 2F 69 2F 63 73 2F 32 31 2F 31 31 2F 66 64 37 63 61 38 32 38 36 62 65 32 66 32 35 36 62 33 65 64 64 35 35 61 38 34 66 33 31 35 36 35 2E 70 6E 67 92 A5 4C 61 79 65 72 82 AB 61 70 70 6C 79 4D 61 74 72 69 78 C3 A8 63 68 69 6C 64 72 65 6E 98 92 A6 4D 79 54 65 78 74 8C AB 61 70 70 6C 79 4D 61 74 72 69 78 C2 A6 6D 61 74 72 69 78 96 01 00 00 01 CB 40 45 0D 79 43 5E 50 D7 CB 40 54 9F FF FF FF FF FF AC 6C 6F 63 6B 53 63 61 6C 69 6E 67 59 C3 AD 6C 6F 63 6B 53 63 61 6C 69 6E 67 58 59 C3 A7 63 6F 6E 74 65 6E 74 AC 43 6F 6D 70 61 6E 79 20 4E 61 6D 65 A6 66 6F 6E 74 49 64 A4 31 34 37 32 AF 74 65 78 74 54 69 74 6C 65 54 79 70 65 49 64 03 AA 66 6F 6E 74 46 61 6D 69 6C 79 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A8 66 6F 6E 74 53 69 7A 65 CB 40 40 56 D4 95 B5 25 6D A4 66 6F 6E 74 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A7 6C 65 61 64 69 6E 67 CB 40 43 9B 65 80 72 F9 B6 A8 6D 61 78 57 69 64 74 68 CB 40 86 5E 50 D7 94 35 E6 92 A6 4D 79 54 65 78 74 8C AB 61 70 70 6C 79 4D 61 74 72 69 78 C2 A6 6D 61 74 72 69 78 96 01 00 00 01 CB 40 45 0D 79 43 5E 50 D7 CB 40 63 42 86 BC A1 AF 29 AC 6C 6F 63 6B 53 63 61 6C 69 6E 67 59 C3 AD 6C 6F 63 6B 53 63 61 6C 69 6E 67 58 59 C3 A7 63 6F 6E 74 65 6E 74 A9 46 75 6C 6C 20 4E 61 6D 65 A6 66 6F 6E 74 49 64 A4 31 34 37 32 AF 74 65 78 74 54 69 74 6C 65 54 79 70 65 49 64 02 AA 66 6F 6E 74 46 61 6D 69 6C 79 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A8 66 6F 6E 74 53 69 7A 65 CB 40 4A BC A1 AF 28 6B C9 A4 66 6F 6E 74 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A7 6C 65 61 64 69 6E 67 CB 40 50 0A C7 69 18 40 AC A8 6D 61 78 57 69 64 74 68 CB 40 86 5E 50 D7 94 35 E6 92 A6 4D 79 54 65 78 74 8C AB 61 70 70 6C 79 4D 61 74 72 69 78 C2 A6 6D 61 74 72 69 78 96 01 00 00 01 CB 40 45 0D 79 43 5E 50 D7 CB 40 68 85 E5 0D 79 43 5E AC 6C 6F 63 6B 53 63 61 6C 69 6E 67 59 C3 AD 6C 6F 63 6B 53 63 61 6C 69 6E 67 58 59 C3 A7 63 6F 6E 74 65 6E 74 A9 4A 6F 62 20 54 69 74 6C 65 A6 66 6F 6E 74 49 64 A4 31 34 37 32 AF 74 65 78 74 54 69 74 6C 65 54 79 70 65 49 64 04 AA 66 6F 6E 74 46 61 6D 69 6C 79 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A8 66 6F 6E 74 53 69 7A 65 CB 40 3A BC A1 AF 28 6B C9 A4 66 6F 6E 74 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A7 6C 65 61 64 69 6E 67 CB 40 40 0A C7 69 18 40 AC A8 6D 61 78 57 69 64 74 68 CB 40 86 5E 50 D7 94 35 E6 92 A6 4D 79 54 65 78 74 8C AB 61 70 70 6C 79 4D 61 74 72 69 78 C2 A6 6D 61 74 72 69 78 96 01 00 00 01 CB 40 45 0D 79 43 5E 50 D7 CB 40 70 78 D7 94 35 E5 0D AC 6C 6F 63 6B 53 63 61 6C 69 6E 67 59 C3 AD 6C 6F 63 6B 53 63 61 6C 69 6E 67 58 59 C3 A7 63 6F 6E 74 65 6E 74 A5 45 6D 61 69 6C A6 66 6F 6E 74 49 64 A4 31 34 37 32 AF 74 65 78 74 54 69 74 6C 65 54 79 70 65 49 64 05 AA 66 6F 6E 74 46 61 6D 69 6C 79 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A8 66 6F 6E 74 53 69 7A 65 CB 40 37 C4 1D F1 07 7C 41 A4 66 6F 6E 74 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A7 6C 65 61 64 69 6E 67 CB 40 3C 84 F0 BA D5 C8 4E A8 6D 61 78 57 69 64 74 68 CB 40 86 5E 50 D7 94 35 E6 92 A6 4D 79 54 65 78 74 8C AB 61 70 70 6C 79 4D 61 74 72 69 78 C2 A6 6D 61 74 72 69 78 96 01 00 00 01 CB 40 45 0D 79 43 5E 50 D7 CB 40 72 D7 28 6B CA 1A F2 AC 6C 6F 63 6B 53 63 61 6C 69 6E 67 59 C3 AD 6C 6F 63 6B 53 63 61 6C 69 6E 67 58 59 C3 A7 63 6F 6E 74 65 6E 74 A5 50 68 6F 6E 65 A6 66 6F 6E 74 49 64 A4 31 34 37 32 AF 74 65 78 74 54 69 74 6C 65 54 79 70 65 49 64 06 AA 66 6F 6E 74 46 61 6D 69 6C 79 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A8 66 6F 6E 74 53 69 7A 65 CB 40 37 C4 1D F1 07 7C 41 A4 66 6F 6E 74 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A7 6C 65 61 64 69 6E 67 CB 40 3C 84 F0 BA D5 C8 4E A8 6D 61 78 57 69 64 74 68 CB 40 86 5E 50 D7 94 35 E6 92 A6 4D 79 54 65 78 74 8C AB 61 70 70 6C 79 4D 61 74 72 69 78 C2 A6 6D 61 74 72 69 78 96 01 00 00 01 CB 40 45 0D 79 43 5E 50 D7 CB 40 75 35 79 43 5E 50 D7 AC 6C 6F 63 6B 53 63 61 6C 69 6E 67 59 C3 AD 6C 6F 63 6B 53 63 61 6C 69 6E 67 58 59 C3 A7 63 6F 6E 74 65 6E 74 AD 41 64 64 72 65 73 73 20 4C 69 6E 65 73 A6 66 6F 6E 74 49 64 A4 31 34 37 32 AF 74 65 78 74 54 69 74 6C 65 54 79 70 65 49 64 15 AA 66 6F 6E 74 46 61 6D 69 6C 79 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A8 66 6F 6E 74 53 69 7A 65 CB 40 37 C4 1D F1 07 7C 41 A4 66 6F 6E 74 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A7 6C 65 61 64 69 6E 67 CB 40 3C 84 F0 BA D5 C8 4E A8 6D 61 78 57 69 64 74 68 CB 40 86 5E 50 D7 94 35 E6 92 A6 4D 79 54 65 78 74 8C AB 61 70 70 6C 79 4D 61 74 72 69 78 C2 A6 6D 61 74 72 69 78 96 01 00 00 01 CB 40 45 0D 79 43 5E 50 D7 CB 40 79 6B 5E 50 D7 94 36 AC 6C 6F 63 6B 53 63 61 6C 69 6E 67 59 C3 AD 6C 6F 63 6B 53 63 61 6C 69 6E 67 58 59 C3 A7 63 6F 6E 74 65 6E 74 A3 57 65 62 A6 66 6F 6E 74 49 64 A4 31 34 37 32 AF 74 65 78 74 54 69 74 6C 65 54 79 70 65 49 64 0A AA 66 6F 6E 74 46 61 6D 69 6C 79 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A8 66 6F 6E 74 53 69 7A 65 CB 40 37 C4 1D F1 07 7C 41 A4 66 6F 6E 74 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A7 6C 65 61 64 69 6E 67 CB 40 3C 84 F0 BA D5 C8 4E A8 6D 61 78 57 69 64 74 68 CB 40 86 5E 50 D7 94 35 E6 92 A4 50 61 74 68 84 AB 61 70 70 6C 79 4D 61 74 72 69 78 C3 A8 73 65 67 6D 65 6E 74 73 DC 00 2A 93 92 CB 40 86 7F 67 4A FD 54 54 CB 40 51 49 68 DB 8B AC 71 92 27 13 92 D0 D9 ED 93 92 CB 40 84 07 67 4A FD 54 54 CB 40 4D 12 D1 B7 17 58 E2 92 13 F8 92 ED 08 93 92 CB 40 82 7F 67 4A FD 54 54 CB 40 5A 09 68 DB 8B AC 71 92 06 F4 92 FA 0C 93 92 CB 40 81 EF 67 4A FD 54 54 CB 40 61 C4 B4 6D C5 D6 39 92 09 FA 92 F7 06 93 92 CB 40 81 17 67 4A FD 54 54 CB 40 63 04 B4 6D C5 D6 39 92 04 00 92 FC 00 93 92 CB 40 7B AE CE 95 FA A8 A8 CB 40 60 84 B4 6D C5 D6 39 92 1E 0C 92 E2 F4 93 92 CB 40 76 1E CE 95 FA A8 A8 CB 40 62 E4 B4 6D C5 D6 39 92 11 F3 92 EF 0D 93 92 CB 40 73 1E CE 95 FA A8 A8 CB 40 6D A4 B4 6D C5 D6 39 92 04 EB 92 FC 15 93 92 CB 40 72 FE CE 95 FA A8 A8 CB 40 75 52 5A 36 E2 EB 1C 92 ED E7 92 FF 01 93 92 CB 40 70 9E CE 95 FA A8 A8 CB 40 76 C2 5A 36 E2 EB 1C 92 30 03 92 D0 D0 FD 93 92 CB 40 6A 9D 9D 2B F5 51 50 CB 40 78 62 5A 36 E2 EB 1C 92 15 F2 92 EB 0E 93 92 CB 40 64 3D 9D 2B F5 51 50 CB 40 79 E2 5A 36 E2 EB 1C 92 08 F0 92 F8 10 93 92 CB 40 67 BD 9D 2B F5 51 50 CB 40 7C E2 5A 36 E2 EB 1C 92 D0 D7 FE 92 29 02 93 92 CB 40 72 FE CE 95 FA A8 A8 CB 40 7A 02 5A 36 E2 EB 1C 92 F9 10 92 07 F0 93 92 CB 40 75 1E CE 95 FA A8 A8 CB 40 78 62 5A 36 E2 EB 1C 92 F5 FD 92 0B 03 93 92 CB 40 76 BE CE 95 FA A8 A8 CB 40 79 A2 5A 36 E2 EB 1C 92 E7 F8 92 19 08 93 92 CB 40 78 CE CE 95 FA A8 A8 CB 40 7A 62 5A 36 E2 EB 1C 92 F1 01 92 0F FF 93 92 CB 40 7A 8E CE 95 FA A8 A8 CB 40 7A 62 5A 36 E2 EB 1C 92 F9 08 92 07 F8 93 92 CB 40 7A FE CE 95 FA A8 A8 CB 40 7B 32 5A 36 E2 EB 1C 92 FA FA 92 06 06 93 92 CB 40 7E CE CE 95 FA A8 A8 CB 40 7B F2 5A 36 E2 EB 1C 92 D0 D7 05 92 29 FB 93 92 CB 40 81 A7 67 4A FD 54 54 CB 40 7B 42 5A 36 E2 EB 1C 92 00 02 92 00 FE 93 92 CB 40 81 1F 67 4A FD 54 54 CB 40 7A 92 5A 36 E2 EB 1C 92 12 FF 92 EE 01 93 92 CB 40 80 07 67 4A FD 54 54 CB 40 7A A2 5A 36 E2 EB 1C 92 14 05 92 EC FB 93 92 CB 40 7D CE CE 95 FA A8 A8 CB 40 79 92 5A 36 E2 EB 1C 92 00 12 92 00 EE 93 92 CB 40 7D AE CE 95 FA A8 A8 CB 40 77 B2 5A 36 E2 EB 1C 92 15 0A 92 EB F6 92 CB 40 7D CE CE 95 FA A8 A8 CB 40 75 42 5A 36 E2 EB 1C 93 92 CB 40 7E 1E CE 95 FA A8 A8 CB 40 73 82 5A 36 E2 EB 1C 92 F4 0F 92 0C F1 93 92 CB 40 80 37 67 4A FD 54 54 CB 40 73 62 5A 36 E2 EB 1C 92 01 F3 92 FF 0D 93 92 CB 40 7F BE CE 95 FA A8 A8 CB 40 75 92 5A 36 E2 EB 1C 92 00 F2 92 00 0E 93 92 CB 40 7F DE CE 95 FA A8 A8 CB 40 77 72 5A 36 E2 EB 1C 92 08 ED 92 F8 13 93 92 CB 40 7F 4E CE 95 FA A8 A8 CB 40 79 D2 5A 36 E2 EB 1C 92 FE F9 92 02 07 93 92 CB 40 7F BE CE 95 FA A8 A8 CB 40 7B 22 5A 36 E2 EB 1C 92 F2 02 92 0E FE 93 92 CB 40 80 77 67 4A FD 54 54 CB 40 7A 02 5A 36 E2 EB 1C 92 04 15 92 FC EB 93 92 CB 40 82 57 67 4A FD 54 54 CB 40 73 92 5A 36 E2 EB 1C 92 EA 0E 92 16 F2 93 92 CB 40 84 27 67 4A FD 54 54 CB 40 6E 04 B4 6D C5 D6 39 92 F7 11 92 09 EF 93 92 CB 40 85 B7 67 4A FD 54 54 CB 40 64 04 B4 6D C5 D6 39 92 F9 12 92 07 EE 93 92 CB 40 85 EF 67 4A FD 54 54 CB 40 61 84 B4 6D C5 D6 39 92 05 09 92 16 FB 93 92 CB 40 86 F7 67 4A FD 54 54 CB 40 60 44 B4 6D C5 D6 39 92 FC 09 92 04 F7 93 92 CB 40 87 57 67 4A FD 54 54 CB 40 5A C9 68 DB 8B AC 71 92 05 09 92 FB F7 93 92 CB 40 86 BF 67 4A FD 54 54 CB 40 57 09 68 DB 8B AC 71 92 05 0C 92 FB F4 92 CB 40 86 7F 67 4A FD 54 54 CB 40 51 89 68 DB 8B AC 71 92 CB 40 86 7F 67 4A FD 54 54 CB 40 51 89 68 DB 8B AC 71 A9 66 69 6C 6C 43 6F 6C 6F 72 93 01 01 01 AB 73 74 72 6F 6B 65 57 69 64 74 68 CB 3F EA F2 86 BC A1 AF 28

Converted binary from http://msgpack-json-editor.com/

92 92 A5 4C 61 79 65 72 83 AB 61 70 70 6C 79 4D 61 74 72 69 78 C3 A6 6C 6F 63 6B 65 64 C3 A8 63 68 69 6C 64 72 65 6E 91 92 A6 52 61 73 74 65 72 84 AB 61 70 70 6C 79 4D 61 74 72 69 78 C2 A6 6D 61 74 72 69 78 96 CB 3F F9 DB CC 48 67 6F 30 00 00 CB 3F F9 DB CC 48 67 6F 30 CB 40 79 00 00 00 00 00 01 CB 40 6F 0D 79 43 5E 50 D8 A6 6C 6F 63 6B 65 64 C3 A6 73 6F 75 72 63 65 D9 30 2F 69 2F 63 73 2F 32 31 2F 31 31 2F 66 64 37 63 61 38 32 38 36 62 65 32 66 32 35 36 62 33 65 64 64 35 35 61 38 34 66 33 31 35 36 35 2E 70 6E 67 92 A5 4C 61 79 65 72 82 AB 61 70 70 6C 79 4D 61 74 72 69 78 C3 A8 63 68 69 6C 64 72 65 6E 98 92 A6 4D 79 54 65 78 74 8C AB 61 70 70 6C 79 4D 61 74 72 69 78 C2 A6 6D 61 74 72 69 78 96 01 00 00 01 CB 40 45 0D 79 43 5E 50 D7 CB 40 54 9F FF FF FF FF FF AC 6C 6F 63 6B 53 63 61 6C 69 6E 67 59 C3 AD 6C 6F 63 6B 53 63 61 6C 69 6E 67 58 59 C3 A7 63 6F 6E 74 65 6E 74 AC 43 6F 6D 70 61 6E 79 20 4E 61 6D 65 A6 66 6F 6E 74 49 64 A4 31 34 37 32 AF 74 65 78 74 54 69 74 6C 65 54 79 70 65 49 64 03 AA 66 6F 6E 74 46 61 6D 69 6C 79 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A8 66 6F 6E 74 53 69 7A 65 CB 40 40 56 D4 95 B5 25 6D A4 66 6F 6E 74 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A7 6C 65 61 64 69 6E 67 CB 40 43 9B 65 80 72 F9 B6 A8 6D 61 78 57 69 64 74 68 CB 40 86 5E 50 D7 94 35 E6 92 A6 4D 79 54 65 78 74 8C AB 61 70 70 6C 79 4D 61 74 72 69 78 C2 A6 6D 61 74 72 69 78 96 01 00 00 01 CB 40 45 0D 79 43 5E 50 D7 CB 40 63 42 86 BC A1 AF 29 AC 6C 6F 63 6B 53 63 61 6C 69 6E 67 59 C3 AD 6C 6F 63 6B 53 63 61 6C 69 6E 67 58 59 C3 A7 63 6F 6E 74 65 6E 74 A9 46 75 6C 6C 20 4E 61 6D 65 A6 66 6F 6E 74 49 64 A4 31 34 37 32 AF 74 65 78 74 54 69 74 6C 65 54 79 70 65 49 64 02 AA 66 6F 6E 74 46 61 6D 69 6C 79 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A8 66 6F 6E 74 53 69 7A 65 CB 40 4A BC A1 AF 28 6B C9 A4 66 6F 6E 74 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A7 6C 65 61 64 69 6E 67 CB 40 50 0A C7 69 18 40 AC A8 6D 61 78 57 69 64 74 68 CB 40 86 5E 50 D7 94 35 E6 92 A6 4D 79 54 65 78 74 8C AB 61 70 70 6C 79 4D 61 74 72 69 78 C2 A6 6D 61 74 72 69 78 96 01 00 00 01 CB 40 45 0D 79 43 5E 50 D7 CB 40 68 85 E5 0D 79 43 5E AC 6C 6F 63 6B 53 63 61 6C 69 6E 67 59 C3 AD 6C 6F 63 6B 53 63 61 6C 69 6E 67 58 59 C3 A7 63 6F 6E 74 65 6E 74 A9 4A 6F 62 20 54 69 74 6C 65 A6 66 6F 6E 74 49 64 A4 31 34 37 32 AF 74 65 78 74 54 69 74 6C 65 54 79 70 65 49 64 04 AA 66 6F 6E 74 46 61 6D 69 6C 79 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A8 66 6F 6E 74 53 69 7A 65 CB 40 3A BC A1 AF 28 6B C9 A4 66 6F 6E 74 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A7 6C 65 61 64 69 6E 67 CB 40 40 0A C7 69 18 40 AC A8 6D 61 78 57 69 64 74 68 CB 40 86 5E 50 D7 94 35 E6 92 A6 4D 79 54 65 78 74 8C AB 61 70 70 6C 79 4D 61 74 72 69 78 C2 A6 6D 61 74 72 69 78 96 01 00 00 01 CB 40 45 0D 79 43 5E 50 D7 CB 40 70 78 D7 94 35 E5 0D AC 6C 6F 63 6B 53 63 61 6C 69 6E 67 59 C3 AD 6C 6F 63 6B 53 63 61 6C 69 6E 67 58 59 C3 A7 63 6F 6E 74 65 6E 74 A5 45 6D 61 69 6C A6 66 6F 6E 74 49 64 A4 31 34 37 32 AF 74 65 78 74 54 69 74 6C 65 54 79 70 65 49 64 05 AA 66 6F 6E 74 46 61 6D 69 6C 79 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A8 66 6F 6E 74 53 69 7A 65 CB 40 37 C4 1D F1 07 7C 41 A4 66 6F 6E 74 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A7 6C 65 61 64 69 6E 67 CB 40 3C 84 F0 BA D5 C8 4E A8 6D 61 78 57 69 64 74 68 CB 40 86 5E 50 D7 94 35 E6 92 A6 4D 79 54 65 78 74 8C AB 61 70 70 6C 79 4D 61 74 72 69 78 C2 A6 6D 61 74 72 69 78 96 01 00 00 01 CB 40 45 0D 79 43 5E 50 D7 CB 40 72 D7 28 6B CA 1A F2 AC 6C 6F 63 6B 53 63 61 6C 69 6E 67 59 C3 AD 6C 6F 63 6B 53 63 61 6C 69 6E 67 58 59 C3 A7 63 6F 6E 74 65 6E 74 A5 50 68 6F 6E 65 A6 66 6F 6E 74 49 64 A4 31 34 37 32 AF 74 65 78 74 54 69 74 6C 65 54 79 70 65 49 64 06 AA 66 6F 6E 74 46 61 6D 69 6C 79 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A8 66 6F 6E 74 53 69 7A 65 CB 40 37 C4 1D F1 07 7C 41 A4 66 6F 6E 74 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A7 6C 65 61 64 69 6E 67 CB 40 3C 84 F0 BA D5 C8 4E A8 6D 61 78 57 69 64 74 68 CB 40 86 5E 50 D7 94 35 E6 92 A6 4D 79 54 65 78 74 8C AB 61 70 70 6C 79 4D 61 74 72 69 78 C2 A6 6D 61 74 72 69 78 96 01 00 00 01 CB 40 45 0D 79 43 5E 50 D7 CB 40 75 35 79 43 5E 50 D7 AC 6C 6F 63 6B 53 63 61 6C 69 6E 67 59 C3 AD 6C 6F 63 6B 53 63 61 6C 69 6E 67 58 59 C3 A7 63 6F 6E 74 65 6E 74 AD 41 64 64 72 65 73 73 20 4C 69 6E 65 73 A6 66 6F 6E 74 49 64 A4 31 34 37 32 AF 74 65 78 74 54 69 74 6C 65 54 79 70 65 49 64 15 AA 66 6F 6E 74 46 61 6D 69 6C 79 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A8 66 6F 6E 74 53 69 7A 65 CB 40 37 C4 1D F1 07 7C 41 A4 66 6F 6E 74 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A7 6C 65 61 64 69 6E 67 CB 40 3C 84 F0 BA D5 C8 4E A8 6D 61 78 57 69 64 74 68 CB 40 86 5E 50 D7 94 35 E6 92 A6 4D 79 54 65 78 74 8C AB 61 70 70 6C 79 4D 61 74 72 69 78 C2 A6 6D 61 74 72 69 78 96 01 00 00 01 CB 40 45 0D 79 43 5E 50 D7 CB 40 79 6B 5E 50 D7 94 36 AC 6C 6F 63 6B 53 63 61 6C 69 6E 67 59 C3 AD 6C 6F 63 6B 53 63 61 6C 69 6E 67 58 59 C3 A7 63 6F 6E 74 65 6E 74 A3 57 65 62 A6 66 6F 6E 74 49 64 A4 31 34 37 32 AF 74 65 78 74 54 69 74 6C 65 54 79 70 65 49 64 0A AA 66 6F 6E 74 46 61 6D 69 6C 79 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A8 66 6F 6E 74 53 69 7A 65 CB 40 37 C4 1D F1 07 7C 41 A4 66 6F 6E 74 B3 22 4F 70 65 6E 20 53 61 6E 73 22 2C 22 73 65 72 69 66 22 A7 6C 65 61 64 69 6E 67 CB 40 3C 84 F0 BA D5 C8 4E A8 6D 61 78 57 69 64 74 68 CB 40 86 5E 50 D7 94 35 E6 92 A4 50 61 74 68 84 AB 61 70 70 6C 79 4D 61 74 72 69 78 C3 A8 73 65 67 6D 65 6E 74 73 DC 00 2A 93 92 CB 40 86 7F 67 4A FD 54 54 CB 40 51 49 68 DB 8B AC 71 92 27 13 92 D0 D9 ED 93 92 CB 40 84 07 67 4A FD 54 54 CB 40 4D 12 D1 B7 17 58 E2 92 13 F8 92 ED 08 93 92 CB 40 82 7F 67 4A FD 54 54 CB 40 5A 09 68 DB 8B AC 71 92 06 F4 92 FA 0C 93 92 CB 40 81 EF 67 4A FD 54 54 CB 40 61 C4 B4 6D C5 D6 39 92 09 FA 92 F7 06 93 92 CB 40 81 17 67 4A FD 54 54 CB 40 63 04 B4 6D C5 D6 39 92 04 00 92 FC 00 93 92 CB 40 7B AE CE 95 FA A8 A8 CB 40 60 84 B4 6D C5 D6 39 92 1E 0C 92 E2 F4 93 92 CB 40 76 1E CE 95 FA A8 A8 CB 40 62 E4 B4 6D C5 D6 39 92 11 F3 92 EF 0D 93 92 CB 40 73 1E CE 95 FA A8 A8 CB 40 6D A4 B4 6D C5 D6 39 92 04 EB 92 FC 15 93 92 CB 40 72 FE CE 95 FA A8 A8 CB 40 75 52 5A 36 E2 EB 1C 92 ED E7 92 FF 01 93 92 CB 40 70 9E CE 95 FA A8 A8 CB 40 76 C2 5A 36 E2 EB 1C 92 30 03 92 D0 D0 FD 93 92 CB 40 6A 9D 9D 2B F5 51 50 CB 40 78 62 5A 36 E2 EB 1C 92 15 F2 92 EB 0E 93 92 CB 40 64 3D 9D 2B F5 51 50 CB 40 79 E2 5A 36 E2 EB 1C 92 08 F0 92 F8 10 93 92 CB 40 67 BD 9D 2B F5 51 50 CB 40 7C E2 5A 36 E2 EB 1C 92 D0 D7 FE 92 29 02 93 92 CB 40 72 FE CE 95 FA A8 A8 CB 40 7A 02 5A 36 E2 EB 1C 92 F9 10 92 07 F0 93 92 CB 40 75 1E CE 95 FA A8 A8 CB 40 78 62 5A 36 E2 EB 1C 92 F5 FD 92 0B 03 93 92 CB 40 76 BE CE 95 FA A8 A8 CB 40 79 A2 5A 36 E2 EB 1C 92 E7 F8 92 19 08 93 92 CB 40 78 CE CE 95 FA A8 A8 CB 40 7A 62 5A 36 E2 EB 1C 92 F1 01 92 0F FF 93 92 CB 40 7A 8E CE 95 FA A8 A8 CB 40 7A 62 5A 36 E2 EB 1C 92 F9 08 92 07 F8 93 92 CB 40 7A FE CE 95 FA A8 A8 CB 40 7B 32 5A 36 E2 EB 1C 92 FA FA 92 06 06 93 92 CB 40 7E CE CE 95 FA A8 A8 CB 40 7B F2 5A 36 E2 EB 1C 92 D0 D7 05 92 29 FB 93 92 CB 40 81 A7 67 4A FD 54 54 CB 40 7B 42 5A 36 E2 EB 1C 92 00 02 92 00 FE 93 92 CB 40 81 1F 67 4A FD 54 54 CB 40 7A 92 5A 36 E2 EB 1C 92 12 FF 92 EE 01 93 92 CB 40 80 07 67 4A FD 54 54 CB 40 7A A2 5A 36 E2 EB 1C 92 14 05 92 EC FB 93 92 CB 40 7D CE CE 95 FA A8 A8 CB 40 79 92 5A 36 E2 EB 1C 92 00 12 92 00 EE 93 92 CB 40 7D AE CE 95 FA A8 A8 CB 40 77 B2 5A 36 E2 EB 1C 92 15 0A 92 EB F6 92 CB 40 7D CE CE 95 FA A8 A8 CB 40 75 42 5A 36 E2 EB 1C 93 92 CB 40 7E 1E CE 95 FA A8 A8 CB 40 73 82 5A 36 E2 EB 1C 92 F4 0F 92 0C F1 93 92 CB 40 80 37 67 4A FD 54 54 CB 40 73 62 5A 36 E2 EB 1C 92 01 F3 92 FF 0D 93 92 CB 40 7F BE CE 95 FA A8 A8 CB 40 75 92 5A 36 E2 EB 1C 92 00 F2 92 00 0E 93 92 CB 40 7F DE CE 95 FA A8 A8 CB 40 77 72 5A 36 E2 EB 1C 92 08 ED 92 F8 13 93 92 CB 40 7F 4E CE 95 FA A8 A8 CB 40 79 D2 5A 36 E2 EB 1C 92 FE F9 92 02 07 93 92 CB 40 7F BE CE 95 FA A8 A8 CB 40 7B 22 5A 36 E2 EB 1C 92 F2 02 92 0E FE 93 92 CB 40 80 77 67 4A FD 54 54 CB 40 7A 02 5A 36 E2 EB 1C 92 04 15 92 FC EB 93 92 CB 40 82 57 67 4A FD 54 54 CB 40 73 92 5A 36 E2 EB 1C 92 EA 0E 92 16 F2 93 92 CB 40 84 27 67 4A FD 54 54 CB 40 6E 04 B4 6D C5 D6 39 92 F7 11 92 09 EF 93 92 CB 40 85 B7 67 4A FD 54 54 CB 40 64 04 B4 6D C5 D6 39 92 F9 12 92 07 EE 93 92 CB 40 85 EF 67 4A FD 54 54 CB 40 61 84 B4 6D C5 D6 39 92 05 09 92 16 FB 93 92 CB 40 86 F7 67 4A FD 54 54 CB 40 60 44 B4 6D C5 D6 39 92 FC 09 92 04 F7 93 92 CB 40 87 57 67 4A FD 54 54 CB 40 5A C9 68 DB 8B AC 71 92 05 09 92 FB F7 93 92 CB 40 86 BF 67 4A FD 54 54 CB 40 57 09 68 DB 8B AC 71 92 05 0C 92 FB F4 92 CB 40 86 7F 67 4A FD 54 54 CB 40 51 89 68 DB 8B AC 71 92 CB 40 86 7F 67 4A FD 54 54 CB 40 51 89 68 DB 8B AC 71 A9 66 69 6C 6C 43 6F 6C 6F 72 93 01 01 01 AB 73 74 72 6F 6B 65 57 69 64 74 68 CB 3F EA F2 86 BC A1 AF 28

Reusing Encoder object

See also: Use of Buffer is killing performance. #2

I've been experimenting with an EventEmitter model for processing messages, and so far I can say that it's perf is quite significantly better than using .pipe() on streams.

Reusing Encoder object is one of the most important keys to keep better performance.

Publishing latest releases to NPM?

The latest version of this lib in npm is 0.1.20, but it looks like the latest in github is 0.1.25. Are 0.1.21 - 0.1.25 considered unstable or should they be published to npm?

64bit int decode error: Object doesn't support property or method 'readInt32BE'

msgpack.decode([129, 161, 120, 211, 0, 0, 0, 0, 0, 0, 0, 0]);

Result: Object doesn't support property or method `readInt32BE'

I see #1 about true 64-bit integer support, but this is more of a decoder error. I can work around this in my own code (by adding the missing methods, readInt32BE and readUInt32BE). In my case, I'm dealing with data downloaded from an ASP.Net server running a C# implementation of the msgpack protocol where 64-bit integers (long/ulong) are supported natively.

Publish 0.1.16 to NPM

Just a reminder to publish the most recent version of msgpack-lite to npm, so its dependents can be updated.

Support encoding ArrayBuffer as plain bytes

Right now, typed arrays and array buffers (e.g. Uint8Array) will be encoded using extension types (e.g. 0x11).

> msgpack.encode(new Uint8Array([0x01, 0x02, 0x03]))
< [199, 3, 18, 1, 2, 3]

I'm working with a lot of typed arrays in my application. If I want to send plain arrays to the server, I need to convert those to an Array:

> msgpack.encode(Array.from(new Uint8Array([0x01, 0x02, 0x03])))
< [147, 1, 2, 3]

Sending binary data directly doesn't even seem to be possible in a browser environment without the Buffer library.

I'm pretty sure that this results in a new allocation and a copy of the typed array to the untyped array. In a performance critical application, that might be quite expensive... (Note: I'm only guessing here about the allocation and don't know how to verify the claim...)

If that assumption is true, might it be possible to introduce an encoding mode where an ArrayBuffer is serialized to the msgpack binary format directly? Or is it possible to solve that problem using a codec?

If that were possible, then efficient serialization would be possible:

> let array = new Uint8Array([0x01, 0x02, 0x03]);
> msgpack.encode(array.buffer, simplify=True)
< [196, 3, 1, 2, 3]

Registering application specific EXT formats

See also: Signature: option parameters and streaming destination #6

At the current version, EXT formats are defined by the module.
It should allow applications to register application specific formats.

Support part buffer for decode

It's about that works in this way:

var b = Buffer.alloc(1000);
msgPackBuffer.copy(b, 100);
var obj = m.decode(b, {from: 100, length: msgPackBuffer.length});

My case: https://github.com/KlonD90/node-tarantool-driver. Now work for optimisation and use your implementation. I want less allocation for more speed/less memory usage.

Please help me with improve this. Can i pull request you or do something for this way?

Unpack c# msgpack

I using https://github.com/msgpack/msgpack-cli and here are my classes

[DataContract]
public class Client
{
    [DataMember(Order = 0)]
    public int Id { get; set; }
    [DataMember(Order = 1)]
    public Information Information { get; set; }
}

[DataContract]
public class Information
{
    [DataMember(Order = 0)]
    public string Name { get; set; }
}

When I unpack it from server side I get

[1, ['John']]

The data is correct but it's not an object. I understand the reason but is there any way to convert it to my model?

speed or compression optimization

see #10

var mplite = require('msgpack-lite');
var mpnat = require('msgpack');
mplite.encode({65535: 0}); // <Buffer 81 a5 36 35 35 33 35 00>
mpnat.pack({65535: 0}); // <Buffer 81 cd ff ff 00>

The integer map key cd ff ff is 3 bytes shorter than the string map key a5 36 35 35 33 35 at this example above.

TypeScript Definitions

Would some TypeScript definitions be possible in the near future? If I were more familiar with the project I'd offer.

reading from a messagepack stream

Hello,
I'm trying to use msgpack-lite to read from a messagepack stream and I'm using the code straight out of the examples, but I'm getting 'msgpack.createDecodeStream is not a function'. Did the API change? What is the correct way to read from a messagpack stream? Thanks.

msgpack-lite with browserify

msgpack-lite is definitely available with browserify.

Using require("msgpack-lite") in a browserify project may increase compilation time, however.

Using msgpack global object exported by msgpack.min.js would make compilation faster.

UTF-8 isn't encoded/decoded correctly

msgpack.encode('๐Ÿฆ')
  • Produces: [166, 237, 160, 189, 237, 176, 166]
  • Expected: [164, 240, 159, 144, 166]

The UTF-16 surrogate pair is incorrectly encoded as two pairs of 3 byte UTF-8 codepoints instead of a single 4 byte codepoint.

It seems intentional, given this comment (buffer-lite.js:21):

// JavaScript's string uses UTF-16 surrogate pairs for characters other than BMP.
// This encodes string as CESU-8 which never reaches 4 octets per character.

I don't see the ability to encode CESU-8 instead of UTF-8 in the msgpack spec though. This will lead to interoperability issues with other msgpack implementations at best, crashing with incorrectly decoded codepoints at worst.

I wrote a plain JavaScript UTF-8 implementation before, will make a PR when I get a moment.

Encode and decode ArrayBuffer

Hi @kawanet, thanks for this library.

I am interested in encoding and decoding ArrayBuffer in addition to Buffer. The motivation is to be able to use msgpack for efficient cross-origin communication in a browser, using postMessage API and transferable object. It can work currently by converting between Buffer <-> ArrayBuffer, but this can be a slow operation since it's basically like memcpy.

There is already an implementation here: https://github.com/creationix/msgpack-js-browser

Intermittent BUFFER_SHORTAGE errors

I have no idea what triggers this error, but every so often, when decoding (apparently large) msgpack data, the BUFFER_SHORTAGE error gets thrown.

Why does this happen? Is this a bug?

Signature: option parameters and flexible streaming destination

See also: Use of Buffer is killing performance. #2
See also: new option: concat encoding buffer per message #5

At the current version, Encoder and Decoder classes are private and NOT documented yet.

  • individual usage: msgpack.encode() and msgpack.decode() functions available
  • streaming usage: msgpack.createEncodeStream() and msgpack.createDecodeStream() transformers available.

The only reason is that Encoder and Decoder classes' parameters signature is not decided. It's time to decide it to make Encoder and Decoder classes public.

Compatibility mode

If this library is supporting a newer version of the spec it should document if it supports compatibility mode with the old spec and how to use that:

excerpt from https://github.com/msgpack/msgpack/blob/master/spec.md

"In a major release, serializers distinguish Binary type and String type using bin format family and str format family
At the same time, serializers should offer "compatibility mode" which doesn't use bin format family and str 8 format"

Benchmarks innacurate

Hey @kawanet,

That's not really an issue.

I just want to share that I've been doing some benchmarks recently, and it seems that msgpack-javascript and msgpack-js-v5 performs better in some cases.

Maybe it would be nice to have different inputs for the benchmarks in your README, since some projects may have different needs when choosing a library like this.

Congrats for your implementation, which seems really great!
Cheers

Custom Extension Types (Codecs) for TypeScript class

I want to write Custom Extension Types (Codecs) for TypeScript class but I got the following error.
Please let me know how I can fix this issue. Thanks!

my target TypeScript code

import * as msgpack from "msgpack-lite";

var codec = msgpack.createCodec();
codec.addExtPacker(0x3F, MyVector, myVectorPacker);
codec.addExtUnpacker(0x3F, myVectorUnpacker);

var data = new MyVector(1, 2);
var encoded = msgpack.encode(data, {codec: codec});
var decoded = msgpack.decode(encoded, {codec: codec});

console.log("encoded = " + JSON.stringify(encoded));
console.log("decoded = " + JSON.stringify(decoded));

class MyVector {
  x: number;
  y: number;
  constructor (x: number, y: number) {
    this.x = x;
    this.y = y;
  }
}

// return Buffer serialized
function myVectorPacker(vector: MyVector) {
  var array = [vector.x, vector.y];
  return msgpack.encode(array);
}

// return Object deserialized
function myVectorUnpacker(buffer: Buffer) {
  var array = msgpack.decode(buffer);
  return new MyVector(array[0], array[1]);
}

compiled JS code

"use strict";
var msgpack = require("msgpack-lite");
var codec = msgpack.createCodec();
codec.addExtPacker(0x3F, MyVector, myVectorPacker);
codec.addExtUnpacker(0x3F, myVectorUnpacker);
var data = new MyVector(1, 2);
var encoded = msgpack.encode(data, { codec: codec });
var decoded = msgpack.decode(encoded, { codec: codec });
console.log("encoded = " + JSON.stringify(encoded));
console.log("decoded = " + JSON.stringify(decoded));
var MyVector = (function () {
    function MyVector(x, y) {
        this.x = x;
        this.y = y;
    }
    return MyVector;
}());
// return Buffer serialized
function myVectorPacker(vector) {
    var array = [vector.x, vector.y];
    return msgpack.encode(array);
}
// return Object deserialized
function myVectorUnpacker(buffer) {
    var array = msgpack.decode(buffer);
    return new MyVector(array[0], array[1]);
}

run time error

D:\work\msgpack-lite-cutome-extention-types>node .
D:\work\msgpack-lite-cutome-extention-types\node_modules\msgpack-lite\lib\write-core.js:40
  var name = Class.name;
                  ^

TypeError: Cannot read property 'name' of undefined
    at Codec.addExtPacker (D:\work\msgpack-lite-cutome-extention-types\node_modules\msgpack-lite\lib\write-core.js:40:19)
    at Object.<anonymous> (D:\work\msgpack-lite-cutome-extention-types\dist\index.js:4:7)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.