.MSGPACK
MessagePack
Introduction
MessagePack is a binary form of the same values JSON holds: maps, arrays, strings, numbers, booleans and nil, plus raw binary data. Sadayuki Furuhashi created it in 2008. Small values take a single byte, so encoded data is usually much smaller than JSON and faster to read. Unlike Protocol Buffers it needs no schema: every value says what type it is.
Software
- MessagePack libraries for more than fifty languages, listed on the official site
- Python with the
msgpackpackage - Fluentd, the log collector, which uses MessagePack for its records
Structure
A MessagePack file has no header. It is one value, or a run of values one after another. Each value starts with a type byte; multi-byte numbers and lengths that follow it are big-endian.
| First byte | Type | Value |
|---|---|---|
00–7F | positive fixint | the byte itself, 0 to 127 |
80–8F | fixmap | a map of up to 15 key and value pairs |
90–9F | fixarray | an array of up to 15 values |
A0–BF | fixstr | a UTF-8 string of up to 31 bytes |
C0 | nil | no value |
C2, C3 | false, true | booleans |
C4–C6 | bin 8, 16, 32 | a length, then raw bytes |
C7–C9 | ext 8, 16, 32 | a length, a type number, then data |
CA, CB | float 32, 64 | IEEE 754 numbers |
CC–CF | uint 8 to 64 | unsigned integers |
D0–D3 | int 8 to 64 | signed integers |
D4–D8 | fixext 1 to 16 | a type number and 1, 2, 4, 8 or 16 bytes of data |
D9–DB | str 8, 16, 32 | a length, then a UTF-8 string |
DC, DD | array 16, 32 | a count, then that many values |
DE, DF | map 16, 32 | a count, then that many key and value pairs |
E0–FF | negative fixint | −32 to −1 |
The byte C1 is never used. Extension type −1 is reserved for timestamps.