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
| Name | First Byte | Range | Description |
|---|---|---|---|
| fixext 1 | 0xd4 | 1 byte | 1-byte type code + 1 data byte. |
| fixext 2 | 0xd5 | 2 bytes | 1-byte type code + 2 data bytes. |
| fixext 4 | 0xd6 | 4 bytes | 1-byte type code + 4 data bytes. |
| fixext 8 | 0xd7 | 8 bytes | 1-byte type code + 8 data bytes. |
| fixext 16 | 0xd8 | 16 bytes | 1-byte type code + 16 data bytes. |
| ext 8 | 0xc7 | 0-255 bytes | 1-byte length + 1-byte type + data. |
| ext 16 | 0xc8 | 0-65535 bytes | 2-byte length + 1-byte type + data. |
| ext 32 | 0xc9 | 0-2^32-1 bytes | 4-byte length + 1-byte type + data. |
Examples
| Label | Hex | Value |
|---|---|---|
| Timestamp (4-byte) | d6 ff 63 f0 44 d0 | fixext4, type=-1, seconds 2026-08-25T00:00:00Z |
| Timestamp (8-byte) | d7 ff 00 00 00 00 63 f0 44 d0 | fixext8, type=-1, ns+seconds |
| Custom type 42 | d5 2a 01 02 | fixext2, type=42, data=[0x01,0x02] |