Skip to main content

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

NameFirst ByteRangeDescription
fixmap0x80-0x8f0-15 pairsCount in lower 4 bits. Single prefix byte.
map 160xde0-65535 pairs2-byte big-endian count follows.
map 320xdf0-2^32-1 pairs4-byte big-endian count follows.

Examples

LabelHexValue
{}80fixmap, 0 pairs
{"a":1}81 a1 61 01fixmap 1 pair: str 'a' → int 1
{0:1,1:2}82 00 01 01 02fixmap: int keys 0→1, 1→2

See Also