Every MessagePack value starts with one byte that gives its format. This page follows the MessagePack specification (last modified 2017-08-09), read 2026-11-12. Multi-byte numbers are big-endian.
Format codes
| First byte | Format | Then |
|---|---|---|
00–7F | positive fixint | Nothing: the byte is the value 0 to 127. |
80–8F | fixmap | Low 4 bits = number of pairs (0–15), then key, value, key, value… |
90–9F | fixarray | Low 4 bits = number of elements. |
A0–BF | fixstr | Low 5 bits = length (0–31), then UTF-8 bytes. |
C0 | nil | |
C1 | (never used) | Invalid. |
C2, C3 | false, true | |
C4, C5, C6 | bin 8, 16, 32 | Length in 1, 2 or 4 bytes, then the bytes. |
C7, C8, C9 | ext 8, 16, 32 | Length in 1, 2 or 4 bytes, a signed type byte, then the data. |
CA | float 32 | 4-byte IEEE 754. |
CB | float 64 | 8-byte IEEE 754. |
CC, CD, CE, CF | uint 8, 16, 32, 64 | Unsigned integer of 1, 2, 4 or 8 bytes. |
D0, D1, D2, D3 | int 8, 16, 32, 64 | Signed (two’s complement) integer. |
D4–D8 | fixext 1, 2, 4, 8, 16 | A signed type byte, then exactly 1, 2, 4, 8 or 16 bytes. |
D9, DA, DB | str 8, 16, 32 | Length in 1, 2 or 4 bytes, then UTF-8 bytes. |
DC, DD | array 16, 32 | Count in 2 or 4 bytes, then the elements. |
DE, DF | map 16, 32 | Number of pairs in 2 or 4 bytes, then the pairs. |
E0–FF | negative fixint | Nothing: the byte as a signed number, −32 to −1. |
Serialisers should use the format that takes the fewest bytes. The bin format family and str 8 were added in a change to the specification (the document is dated 2013-04-21); before it, str 16 and str 32 were raw 16 and raw 32, which carried both strings and binary. The specification asks serialisers to offer a compatibility mode that uses neither bin nor str 8, so such data can hold binary data in str formats.
Extension types
Types 0 to 127 are for applications; −128 to −1 are reserved for the specification. Only −1 is defined:
| Form | Layout | Range |
|---|---|---|
timestamp 32 (D6 FF) | Seconds since 1970-01-01 00:00:00 UTC as an unsigned 32-bit number. | 1970 up to (not including) 2106-02-07 06:28:16 UTC, whole seconds |
timestamp 64 (D7 FF) | 64 bits: nanoseconds in the upper 30 bits, seconds in the lower 34. | 1970 up to (not including) 2514-05-30 01:53:04 UTC |
timestamp 96 (C7 0C FF) | Nanoseconds (unsigned 32-bit), then seconds (signed 64-bit). | From −292277022657-01-27 08:29:52 UTC up to (not including) 292277026596-12-04 15:30:08 UTC |
In timestamp 64 and timestamp 96 the nanoseconds must not be larger than 999999999.
Type system, limits and mapping
From the MessagePack specification (spec.md, read 2026-11-13).
- Types: Integer, Nil, Boolean, Float (an IEEE 754 double, including NaN and infinity), Raw (String, a UTF-8 string; Binary, a byte array), Array, Map, Extension (an integer type with a byte array) and, as a predefined extension, Timestamp with nanosecond precision.
- Limits: an Integer is limited to −263 through 264−1. A Binary object has at most 232−1 bytes, a String at most 232−1 bytes, an Array 232−1 elements, a Map 232−1 key-value pairs.
- Invalid UTF-8: a String may contain an invalid byte sequence; what a deserializer does then depends on the implementation, and it should offer a way to get the original bytes so that the application can decide.
- Extension types: 0 to 127 are for the application; −128 to −1 are reserved for predefined types; the only one defined is Timestamp, −1. A reader that does not know an extension may reject it, accept it as opaque data or pass it on untouched.
- Serialising: Integer becomes the int family (positive fixint, negative fixint, int 8/16/32/64 or uint 8/16/32/64), Nil nil, Boolean false or true, Float float 32 or 64, String the str family (fixstr or str 8/16/32), Binary bin 8/16/32, Array fixarray or array 16/32, Map fixmap or map 16/32, Extension fixext or ext 8/16/32. If several formats fit, a serialiser should use the one with the fewest bytes.
- Deserialising is the reverse, each family giving its one type.
- Profiles: an application may restrict the semantics while keeping the syntax: drop Binary, limit map keys to strings (for JSON compatibility), drop String and Binary in favour of Raw when a schema is used, or sort map keys so that the bytes are deterministic for hashing.
- Upgrade guideline: old data may use
raw 16andraw 32, which arestr 16andstr 32. A minor release should read bin and str 8 as the same type as raw 16/32; a major release should write Binary and String distinctly.
Timestamp pseudo-code for writing: with seconds s and nanoseconds
ns, if s >> 34 == 0 then data64 = (ns << 34) | s;
if the top 32 bits of data64 are zero, write the 4-byte timestamp 32
(d6 ff and data64 as 32 bits); otherwise the 8-byte
timestamp 64 (d7 ff data64). If s does not fit in 34
bits, write timestamp 96: c7 0c ff, ns (32 bits), s (64 bits).
Reading by payload length: 4 gives seconds only (nanoseconds 0); 8 gives
ns = data64 >> 34 and s = data64 & 0x3ffffffff; 12 gives
ns then s; any other length is an error.
Example
{"compact": true, "schema": 0} is 18 bytes:
82 fixmap, 2 pairs
A7 63 6F 6D 70 61 63 74 fixstr 7 "compact"
C3 true
A6 73 63 68 65 6D 61 fixstr 6 "schema"
00 positive fixint 0