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