msgpuck
A fast and memory-efficient MessagePack serialization library.
Features
- Fully compliant with the latest MessagePack specification
- Supports low-level methods
- Supports safe/big 64-bit integers handling
- Supports custom Extension Types (Serialization Codecs)
- Fully tested, including V8 JIT optimizations
Future works (not implemented yet)
- Decoder low-level methods
- Zero-copy stream handler
- Web browsers, WebAssembly, Bundler plugins
Installation
# npm npm install msgpuck # yarn yarn add msgpuck
Usage
Encoding
To encode values you can either use an instance of Encoder
:
const Encoder = ; const encoder = ; ... encoder; // string(encoded values)
A list of all low-level encoder methods:
encoder; // MP nilencoder; // MP boolencoder; // MP intencoder; // MP int64encoder; // MP floatencoder; // MP strencoder; // MP binencoder; // MP arrayencoder; // MP mapencoder
Encoding options
The Encoder
object supports options for fine-tuning the encoding process (defaults are in bold):
Name | Description |
---|---|
float: '64' | Forces floats to be encoded as 64-bits MessagePack floats |
float: '32' | Forces floats to be encoded as 32-bits MessagePack floats |
float: 'auto' | Detects MessagePack floats type automatically |
bufferMinLen: 15 | The minimum length of the string to use the Buffer |
codecs: false | An array of codecs |
Decoding
To decode data (buffer) you can either use an instance of Decoder
:
const Decoder = ; const decoder = ; ... decoder;
Extensions
To define application-specific types use the Ext
class:
const Encoder Decoder Ext = ; const encoded = ; const buffer = Buffer;const ext = ; console; // bool(true)console; // bool(true)
Tests
Run tests as follows:
npm run test
License
Copyright © 2018-present Alex Masterov <alex.masterow@gmail.com>
msgpuck is licensed under MIT and can be used for any personal or commercial project.