Package Exports
- @thi.ng/msgpack
- @thi.ng/msgpack/deserialize
- @thi.ng/msgpack/serialize
Readme
This project is part of the @thi.ng/umbrella monorepo and anti-framework.
About
Small & fast msgpack serialization & deserialization.
This implementation is a full rewrite & refactor of @ygoe/msgpack.js, based on this specification.
Status
ALPHA - bleeding edge / work-in-progress
Search or submit any issues for this package
Installation
yarn add @thi.ng/msgpackES module import:
<script type="module" src="https://cdn.skypack.dev/@thi.ng/msgpack"></script>For Node.js REPL:
const msgpack = await import("@thi.ng/msgpack");Package sizes (brotli'd, pre-treeshake): ESM: 1.56 KB
Dependencies
API
import { deserialize, serialize } from "@thi.ng/msgpack";
import { equiv } from "@thi.ng/equiv";
const obj = {
small_i8: -0x0f,
i8: -0x80,
small_u8: 0xff,
i16: -0x8000,
u16: 0xfedc,
i32: -0x8000_0000,
u32: 0xffff_ffff,
utf8_array: ["👋 Hello", "msgpack!", "🔥🤌"],
now: new Date()
};
// encode to byte array
const bytes = serialize(obj);
console.log(bytes);
// Uint8Array(114) [ 137, 168, 115, 109, 97, 108, 108, ... ]
// comparison with JSON
const json = JSON.stringify(obj);
const ratio = bytes.length / json.length;
console.log(`msgpack: ${bytes.length}, json: ${json.length}, ratio: ${ratio.toFixed(2)}`);
// msgpack: 114, json: 178, ratio: 0.64
// roundtrip
const obj2 = deserialize(bytes);
// check equality
console.log(equiv(obj, obj2));
// trueAuthors
If this project contributes to an academic publication, please cite it as:
@misc{thing-msgpack,
title = "@thi.ng/msgpack",
author = "Karsten Schmidt",
note = "https://thi.ng/msgpack",
year = 2023
}License
© 2023 Karsten Schmidt // Apache License 2.0