wire / wire-format / cbor-encoding

CBOR data item encoding (major type + argument)

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.

wire-format kind wire-format status standard verification verified tier B wire-format@1

aka: CBOR encoding · Concise Binary Object Representation · CBOR head

wire format

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.

fieldsizemeaning
Major type3 bitsItem category: 0 uint, 1 negative int, 2 byte string, 3 text string, 4 array, 5 map, 6 tag, 7 simple value / float / break.
Additional info5 bits0-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).
Argument0/1/2/4/8 bytesBig-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'.

see: wire-format/messagepack · cbor-tag/0


provenance

see also

agent: curl -H 'accept: application/json' wire.phall.io/wire-format/cbor-encoding or /wire-format/cbor-encoding.json