MessagePack

MessagePack's Compact Type System

MessagePack 229,447 (msgpack.org (https://msgpack.org/ 229,447 )) is a community specification. One leading byte often holds type and size: 0x8a is a fixmap of 10 pairs, 0xa8 a fixstr of 8 bytes, and integers 0 to 127 take one byte. Python's msgpack 1.2.2 (Apache 2.0) and cbor2 6.1.4 (MIT) encode order 1:

first_bytes.py: order 1 in MessagePack and CBORPython
import json
import cbor2, msgpack
line = open("data/orders.jsonl").readline().rstrip("\n")
order = json.loads(line)
mp, cb = msgpack.packb(order), cbor2.dumps(order)
print(f"JSON {len(line)} bytes, MessagePack {len(mp)}, CBOR {len(cb)}")
print("MessagePack:", mp[:14].hex(" "), "...")
print("CBOR:       ", cb[:14].hex(" "), "...")
Output
JSON 253 bytes, MessagePack 216, CBOR 216
MessagePack: 8a a8 6f 72 64 65 72 5f 69 64 01 ab 63 75 ...
CBOR:        aa 68 6f 72 64 65 72 5f 69 64 01 6b 63 75 ...

Both save only 15 percent, since every record still spells out its field names. Beyond JSON's types, MessagePack has binary strings and ext items: codes 0 to 127 belong to applications, and -1 is the predefined timestamp.