kawanet/msgpack-lite

Compatibility mode

hungryblank opened this issue · 7 comments

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"

Hi, The library supports the current version of msgpack spec.
The spec was released 3 years ago.
Do you know any use cases which still depend on the older binary/string type spec?

They say, by the way, msgpack would add a new official ext format for nano precision date time.
The library would follow it.

We run systems that were written longer than 3 years ago. For these systems there's no drop in replacement for the newer spec implementation so updating msgpack would mean getting involved in much larger scope updates or manually port the newer spec.

If you're not keen on implementing compatibility mode yourself but would consider accepting patches, could you outline an implementation for which you would consider accepting a pull request.

I see. Do you have any reference implementation of compatibility_mode on the other npm modules to have compatibility / interoperability?

Ruby implementation have compatibility_mode option for instance.
https://github.com/msgpack/msgpack-ruby/blob/master/ext/msgpack/packer.h#L418

Hi,

We did some research and found no other node/JavaScript library implementing compatibility mode.
I opened an issue on this library as this would be our preferred choice for a plain JavaScript implementation

As you pointed out Here's the PR for the ruby compatibility implementation

https://github.com/msgpack/msgpack-ruby/pull/68/files

Also there's this python lib that implements compatibility mode

https://github.com/vsergeev/u-msgpack-python#compatibility-mode

The compatibility mode added at version 0.1.19!

https://www.npmjs.com/package/msgpack-lite#compatibility-mode

// 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) 

thanks a lot!
Do i understand well that useraw is basically the flag that means "compatibility mode?"

useraw is basically the flag that means "compatibility mode?"

Right. The most difference is old raw format vs new str+bin formats.

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

The useraw flag itself affects nothing on ext format which is not exist on the old spec.
That is why the flag's named useraw instead of compatibility_mode.