Skip to main content
MessagePack

MessagePack

Active

Efficient 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.

Data FormatBinaryNo RFCRedisFluentd2008
Formats

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

FieldSizeDescription
nil0xc0Null value. Single byte.
false0xc2Boolean false. Single byte.
true0xc3Boolean true. Single byte.
positive fixint0x00-0x7fIntegers 0-127. Single byte. Upper bit 0.
negative fixint0xe0-0xffIntegers -32 to -1. Single byte. Upper 3 bits 111.
fixstr0xa0-0xbfStrings 0-31 bytes. Length in lower 5 bits of first byte.
fixarray0x90-0x9fArrays 0-15 elements. Count in lower 4 bits of first byte.
fixmap0x80-0x8fMaps 0-15 key-value pairs. Count in lower 4 bits of first byte.
ext type -1TimestampBuilt-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

Request
http
// 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)
Response
http
// 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)

Implementations

linuxsince msgpack (Python, Rust, Go, C/C++, Java, Ruby, Node.js)available
macossince msgpack (Python, Rust, Go, C/C++, Java, Ruby, Node.js)available
windowssince MessagePack-CSharp (.NET), msgpack4j (Java)available
iossince MessagePack.swiftavailable
androidsince msgpack-java, msgpack-androidavailable