wire / wire-format / cbor-encoding
CBOR encodes each data item as an initial byte split into a 3-bit major type (0-7) and a 5-bit additional-information value. The additional info is the argument directly (0-23), or signals that 1/2/4/8 following bytes hold it (24-27). Strings, arrays, and maps then use that argument as a length, a self-describing tag-then-value/length scheme.
aka: CBOR encoding · Concise Binary Object Representation · CBOR head
spec: RFC 8949
Every item begins with one 'initial byte': the high 3 bits are the major type, the low 5 bits the additional information. Major types: 0 unsigned int, 1 negative int, 2 byte string, 3 text string, 4 array, 5 map, 6 tag, 7 simple/float. Additional info 0-23 is the value itself; 24/25/26/27 mean a 1/2/4/8-byte big-endian argument follows; 31 marks an indefinite-length item ending in a 0xFF break. For strings/arrays/maps the argument is the length — a tag/length-then-value (TLV-flavored) form, but self-describing.
| field | size | meaning |
|---|---|---|
| Major type | 3 bits | Item category: 0 uint, 1 negative int, 2 byte string, 3 text string, 4 array, 5 map, 6 tag, 7 simple value / float / break. |
| Additional info | 5 bits | 0-23 = the argument inline; 24/25/26/27 = a 1/2/4/8-byte argument follows; 28-30 reserved; 31 = indefinite length (terminated by 0xFF break). |
| Argument | 0/1/2/4/8 bytes | Big-endian value when additional info is 24-27; e.g. for a text string this is the byte length. |
| Content | = argument (for strings/arrays/maps) | For byte/text strings: that many bytes. For arrays: that many items. For maps: that many key/value item pairs. |
example:
63 66 6F 6F
Text string "foo": 0x63 = major type 3 (text string), additional info 3 => length 3; 66 6F 6F = ASCII 'foo'.
agent: curl -H 'accept: application/json' wire.phall.io/wire-format/cbor-encoding
or /wire-format/cbor-encoding.json