Introduction
CBOR is an IETF standard for compact binary data, with the same kinds of value as JSON plus raw bytes and tagged types such as dates. It was first published as RFC 7049 in 2013 and is now RFC 8949. Like MessagePack, which it resembles, it needs no schema.
CBOR is used in small devices and in security standards: WebAuthn passkeys and the COSE signing format are built on it.
Structure
A CBOR file is one value, or a run of values, with no header. Each value starts with one byte. Its top three bits are the major type; its low five bits hold a small number directly (0 to 23), or say that 1, 2, 4 or 8 bytes follow with the number (24 to 27), or mark an indefinite length (31). Multi-byte numbers are big-endian.
| Major type | First byte | Holds |
|---|---|---|
| 0 | 00–1B | an unsigned integer |
| 1 | 20–3B | a negative integer, −1 minus the number |
| 2 | 40–5F | a byte string: a length, then the bytes |
| 3 | 60–7F | a UTF-8 text string |
| 4 | 80–9F | an array: a count, then that many values |
| 5 | A0–BF | a map: a count, then key and value pairs |
| 6 | C0–DB | a tag number, then the value it describes |
| 7 | E0–FF | false (F4), true (F5), null (F6), floats, and the break byte FF |
A file may start with tag 55799, the bytes D9 D9 F7, which marks it as
CBOR without changing the value.
Links
Software
- cbor.me, a web page that converts between CBOR bytes and readable text
Developers
- cbor2, Python
- TinyCBOR, C
- Implementations in other languages, listed on cbor.io
Reference
- RFC 8949, Concise Binary Object Representation (CBOR)