MessagePack
ActiveEfficient binary serialization format that encodes the same data model as JSON in a more compact binary form. Small integers encode in a single byte. Used in Redis, Fluentd, MessageBird, and high-performance APIs.
In one line
MessagePack is a binary serialization format defined by the msgpack.org community spec. It encodes strings, numbers, booleans, null, arrays, maps, and binary data in a compact binary form. Small integers (0-127) and short strings encode in a single byte plus content. Used in Redis pub/sub, Fluentd, and anywhere JSON is too verbose.
Quick Reference
| Field | Size | Description |
|---|---|---|
| nil | 0xc0 | Null value. Single byte. |
| false | 0xc2 | Boolean false. Single byte. |
| true | 0xc3 | Boolean true. Single byte. |
| positive fixint | 0x00-0x7f | Integers 0-127. Single byte. Upper bit 0. |
| negative fixint | 0xe0-0xff | Integers -32 to -1. Single byte. Upper 3 bits 111. |
| fixstr | 0xa0-0xbf | Strings 0-31 bytes. Length in lower 5 bits of first byte. |
| fixarray | 0x90-0x9f | Arrays 0-15 elements. Count in lower 4 bits of first byte. |
| fixmap | 0x80-0x8f | Maps 0-15 key-value pairs. Count in lower 4 bits of first byte. |
| ext type -1 | Timestamp | Built-in extension type. Timestamp in 4, 8, or 12 bytes. |
Key Characteristics
Single-byte small values
Integers 0-127, booleans, null, strings ≤31 bytes, arrays ≤15 elements all start with a single type+value byte.
JSON superset
Any valid JSON can be represented in MessagePack. Adds: binary (bin), extension types, 64-bit integers without precision loss.
No schema required
Self-describing like JSON. No IDL. Parsers need no schema to decode a MessagePack byte stream.
Extension types
Custom type codes (-128 to 127) via ext. Built-in: timestamp (-1). Applications can define their own semantics.
Message Format
// MessagePack encoding (hex bytes)
// null → c0
// true → c3
// false → c2
// 0 → 00
// 127 → 7f
// 128 → cc 80 (uint8)
// -1 → ff (negative fixint)
// -32 → e0 (negative fixint)
// "hi" → a2 68 69 (fixstr len=2, then UTF-8)
// [1,2] → 92 01 02 (fixarray len=2, then items)
// {"a":1}→ 81 a1 61 01 (fixmap len=1, fixstr "a", int 1)// Size comparison: {"name":"Alice","age":30}
// JSON (UTF-8): 21 bytes
// MessagePack: 13 bytes (~38% smaller)
// MessagePack bytes for the above:
// 82 -- fixmap(2 entries)
// a4 6e 61 6d 65 -- fixstr(4) "name"
// a5 41 6c 69 63 65 -- fixstr(5) "Alice"
// a3 61 67 65 -- fixstr(3) "age"
// 1e -- positive fixint 30
// Timestamp extension (8-byte form):
// d7 ff -- fixext8, type -1 (timestamp)
// 00 00 00 00 -- nanoseconds adjustment (0)
// 63 f0 44 d0 -- Unix seconds (big-endian)