Skip to main content

Binary

MessagePack binary (bin) formats encode raw byte sequences without any UTF-8 requirement. bin 8 (0xc4), bin 16 (0xc5), and bin 32 (0xc6) cover 0-255, 0-65535, and 0-2^32-1 bytes respectively. Use bin for non-text data – cryptographic keys, images, file contents.

Description

The bin format was introduced in the MessagePack v2 spec to clearly separate binary data from text strings. Before v2, both were encoded as 'raw' with the same format bytes, requiring out-of-band knowledge to distinguish text from binary.

bin 8 (0xc4): 1 prefix byte + 1 byte length + data bin 16 (0xc5): 1 prefix byte + 2 byte length + data bin 32 (0xc6): 1 prefix byte + 4 byte length + data

Use cases: binary fields that would require base64 in JSON, cryptographic values (hashes, signatures, keys), image thumbnails embedded in messages, and protocol-specific byte sequences.

Format Variants

NameFirst ByteRangeDescription
bin 80xc40-255 bytes1-byte length follows, then data bytes.
bin 160xc50-65535 bytes2-byte big-endian length follows, then data.
bin 320xc60-2^32-1 bytes4-byte big-endian length follows, then data.

Examples

LabelHexValue
Emptyc4 00bin8, length=0
0xDEADBEEFc4 04 de ad be efbin8, 4 bytes
SHA-256c4 20 [32 bytes]bin8, 32-byte hash

See Also