Skip to main content

Extension

MessagePack extension formats allow applications to define custom type codes (type -128 to 127). fixext encodes 1, 2, 4, 8, or 16 bytes in a single prefix byte. ext 8/16/32 handle arbitrary lengths. Built-in: Timestamp extension uses type code -1. Applications define their own semantics for other codes.

Description

The extension type is MessagePack's escape hatch for application-specific data. Each ext value has a type code (-128 to 127) that identifies the semantic, and raw bytes for the value. The runtime does not interpret the bytes – that's up to the application.

fixext formats have fixed data sizes encoded in the format byte: 0xd4 = fixext 1 (type + 1 byte) 0xd5 = fixext 2 (type + 2 bytes) 0xd6 = fixext 4 (type + 4 bytes) 0xd7 = fixext 8 (type + 8 bytes) 0xd8 = fixext 16 (type + 16 bytes)

Variable-length ext: 0xc7 = ext 8 (type + 1-byte length + data) 0xc8 = ext 16 (type + 2-byte length + data) 0xc9 = ext 32 (type + 4-byte length + data)

Built-in: Timestamp (type -1, 0xff) encodes Unix timestamps in 4, 8, or 12 bytes.

Format Variants

NameFirst ByteRangeDescription
fixext 10xd41 byte1-byte type code + 1 data byte.
fixext 20xd52 bytes1-byte type code + 2 data bytes.
fixext 40xd64 bytes1-byte type code + 4 data bytes.
fixext 80xd78 bytes1-byte type code + 8 data bytes.
fixext 160xd816 bytes1-byte type code + 16 data bytes.
ext 80xc70-255 bytes1-byte length + 1-byte type + data.
ext 160xc80-65535 bytes2-byte length + 1-byte type + data.
ext 320xc90-2^32-1 bytes4-byte length + 1-byte type + data.

Examples

LabelHexValue
Timestamp (4-byte)d6 ff 63 f0 44 d0fixext4, type=-1, seconds 2026-08-25T00:00:00Z
Timestamp (8-byte)d7 ff 00 00 00 00 63 f0 44 d0fixext8, type=-1, ns+seconds
Custom type 42d5 2a 01 02fixext2, type=42, data=[0x01,0x02]

See Also