Map
MessagePack map formats encode key-value pairs. fixmap (0x80-0x8f) handles 0-15 pairs. map 16 (0xde) and map 32 (0xdf) handle larger maps. Keys and values can be any MessagePack type. Integer keys are common for compact encoding.
Description
MessagePack maps are equivalent to JSON objects but with important differences: fixmap (0x80-0x8f): 0-15 key-value pairs. Count in lower 4 bits of prefix byte. map 16 (0xde): 0-65535 pairs. 2-byte count. map 32 (0xdf): 0-2^32-1 pairs. 4-byte count.
Key type flexibility: unlike JSON, MessagePack map keys can be integers, floats, or any other type. Integer keys are common in protocol design to minimize message size: key 1 = 1 byte vs key 'algorithm' = 10+ bytes.
Key ordering: not required by the spec. Implementations may output in any order.
Format Variants
| Name | First Byte | Range | Description |
|---|---|---|---|
| fixmap | 0x80-0x8f | 0-15 pairs | Count in lower 4 bits. Single prefix byte. |
| map 16 | 0xde | 0-65535 pairs | 2-byte big-endian count follows. |
| map 32 | 0xdf | 0-2^32-1 pairs | 4-byte big-endian count follows. |
Examples
| Label | Hex | Value |
|---|---|---|
| {} | 80 | fixmap, 0 pairs |
| {"a":1} | 81 a1 61 01 | fixmap 1 pair: str 'a' → int 1 |
| {0:1,1:2} | 82 00 01 01 02 | fixmap: int keys 0→1, 1→2 |