mcollina/msgpack5 is an open-source project on GitHub with 504 stars, written primarily in JavaScript. A msgpack v5 implementation for node.js, with extension points / msgpack.org[Node]
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
A msgpack v5 implementation for node.js, with extension point support.
Install
npm install msgpack5 --save
Usage
var msgpack = require('msgpack5')() // namespace our extensions
, a = new MyType(2, 'a')
, encode = msgpack.encode
, decode = msgpack.decode
msgpack.register(0x42, MyType, mytipeEncode, mytipeDecode)
const hex = encode({ 'hello': 'world' }).toString('hex')
console.log(hex)
// 81a568656c6c6fa5776f726c64
const obj = decode(Buffer.from(hex, 'hex'))
console.log(obj)
// { hello: 'world' }
console.log(decode(encode({ 'hello': 'world' })))
// { hello: 'world' }
console.log(encode(a).toString('hex'))
// d5426161
console.log(decode(encode(a)) instanceof MyType)
// true
console.log(decode(encode(a)))
// { value: 'a', size: 2 }
function MyType(size, value) {
this.value = value
this.size = size
}
function mytipeEncode(obj) {
var buf = new Buffer(obj.size)
buf.fill(obj.value)
return buf
}
function mytipeDecode(data) {
var result = new MyType(data.length, data.toString('utf8', 0, 1))
, i
for (i = 0; i < data.length; i++) {
if (data.readUInt8(0) != data.readUInt8(i)) {
throw new Error('should all be the same')
}
}
return result
}
API
API
msgpack()
msgpack().encode()
msgpack().decode()
msgpack().registerEncoder()
msgpack().registerDecoder()
msgpack().register()
msgpack().encoder()
msgpack().decoder()
msgpack(options(obj))
Creates a new instance on which you can register new types for being
encoded.
options:
forceFloat64, a boolean to that forces all floats to be encoded as 64-bits floats. Defaults to false.
sortKeys, a boolean to force a determinate keys order
compatibilityMode, a boolean that enables "compatibility mode" which doesn't use bin format family and str 8 format. Defaults to false.
disableTimestampEncoding, a boolean that when set disables the encoding of Dates into the timestamp extension type. Defaults to false.
preferMap, a boolean that forces all maps to be decoded to Maps rather than plain objects. This ensures that decode(encode(new Map())) instanceof Map and that iteration order is preserved. Defaults to false.
maxArrayLength, a non-negative integer that limits the number of elements in a decoded array. Arrays over the limit throw a RangeError. Defaults to no limit beyond the MessagePack format maximum.
maxMapLength, a non-negative integer that limits the number of entries in a decoded map. Maps over the limit throw a RangeError. Defaults to no limit beyond the MessagePack format maximum.
maxDepth, a non-negative integer that limits how deeply arrays and maps can be nested when decoding. Defaults to 100.
protoAction, a string which can be error|ignore|remove that determines what happens when decoding a plain object with a __proto__ property which would cause prototype poisoning. error (the default when omitted) throws an error, remove removes the property, ignore (not recommended) allows the property, thereby causing prototype poisoning on the decoded object. Any other value throws a TypeError.
encode(object)
Encodes object in msgpack, returns a Buffer.
decode(buf)
Decodes buf from in msgpack. buf can be a Buffer or a DynamicBuffer instance.
In order to support a stream interface, a user must pass in a DynamicBuffer instance.
registerEncoder(check(obj), encode(obj))
Register a new custom object type for being automatically encoded.
The arguments are:
check, a function that will be called to check if the passed
object should be encoded with the encode function
encode, a function that will be called to encode an object in binary
form; this function must return a Buffer which include the same type
for registerDecoder.
registerDecoder(type, decode(buf))
Register a new custom object type for being automatically decoded.
The arguments are:
type, is a greater than zero integer identificating the type once serialized
decode, a function that will be called to decode the object from
the passed Buffer
Register a new custom object type for being automatically encoded and
decoded. The arguments are:
type, is a greater than zero integer identificating the type once serialized
constructor, the function that will be used to match the objects
with instanceof
encode, a function that will be called to encode an object in binary
form; this function must return a Buffer that can be
deserialized by the decode function
decode, a function that will be called to decode the object from
the passed Buffer
This is just a commodity that calls
registerEncoder and
registerDecoder internally.
encoder(options)
Builds a stream in object mode that encodes msgpack.
Supported options:
wrap, objects should be passed to encoder in wrapped object {value: data}. Wrap option should be used if you need to pass null to encoder.
decoder(options)
Builds a stream in object mode that decodes msgpack.
Supported options:
wrap, decoded objects returned in wrapped object {value: data}. Wrap option should be used if stream contains msgpack nil.
LevelUp Support
msgpack5 can be used as a LevelUp
valueEncoding straight away:
benchmarks/ contains a self-contained throughput harness. It compares msgpack5
against whatever comparison libraries are installed (msgpackr, msgpack-lite,
@msgpack/msgpack) and against JSON, over generated datasets in
benchmarks/data/.
npm install # pulls in the optional comparison libraries
npm run bench # head-to-head encode/decode per dataset (ops/sec + ratios)
npm run bench:stream # streaming .decoder() throughput vs msgpackr
npm run bench:gen # regenerate the datasets in benchmarks/data/
The datasets are generated deterministically by
benchmarks/gen-data.js and written to
benchmarks/data/ (git-ignored). Each function runs under a fixed wall-clock
budget (default 4000 ms, override with BENCH_MS), counting iterations to
produce ops/sec. Round-trips are verified against the source JSON, and missing
comparison libraries are skipped.
To compare two local msgpack5 checkouts (for example an optimization branch
against a baseline worktree), use the A/B harness. It interleaves encode/decode
rounds on benchmarks/data/sample-large.json, then reports the median ops/sec
per build and a new/old ratio (ratio > 1 means the NEW build is faster):
AB_OLD=/path/to/baseline AB_NEW=/path/to/current npm run bench:ab
Related projects
msgpack5rpc: An implementation of the
msgpack-rpc spec
on top of this library.
Disclaimer
This library is built fully on JS and on @platformatic/dynamic-buffer to
simplify the code. Every improvement that keeps the same API is welcome.
Acknowledgements
This project was kindly sponsored by nearForm.
This library was originally built as the data format for
JSChan.
No homepage URL was recorded for mcollina/msgpack5 in TopGit's last sync. The README tab above frequently contains screenshots and demo links, or check the repository description on GitHub.
Does mcollina/msgpack5 have any tags?
TopGit's last sync did not record any GitHub topics for mcollina/msgpack5. GitHub topics appear in the right sidebar of a repository page; that's the authoritative place to check.
How active is development on mcollina/msgpack5?
The most recent commit recorded on mcollina/msgpack5 was 29 days ago, based on the GitHub push timestamp. The repository has 78 forks — one of the better signals of community interest.
How many stars does mcollina/msgpack5 have?
mcollina/msgpack5 has 504 GitHub stars — refresh the page for the live number, or check github.com/mcollina/msgpack5. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
What language is mcollina/msgpack5 written in?
mcollina/msgpack5 is written primarily in JavaScript. GitHub's language field is based on the largest share of bytes in the default branch.
What license does mcollina/msgpack5 use?
mcollina/msgpack5 is released under the MIT license. Always verify the LICENSE file directly on GitHub for the authoritative terms — license strings can be edited out of sync with a project's actual stance.
Where do I read more about mcollina/msgpack5?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/mcollina/msgpack5 is the definitive source.
Read full README in the tab above.
Is msgpack5 worth your time?
ChatGPT, Claude and Perplexity can all read this page. Ask one of them what it makes of msgpack5.