CBOR and RFC 8949

CBOR (Concise Binary Object Representation) is an Internet Standard: RFC 8949 (December 2020, STD 94) replaced RFC 7049 without changing the encoding. It favors tiny decoders and carries WebAuthn and COSE data. A first byte holds a major type (one of eight) in its top three bits and a length below, so aa above is a map of 10 pairs; major type 6, the tag, gives the next item a meaning:

typed.py: a decimal and a timestamp in both formatsPython
from datetime import datetime
from decimal import Decimal
import cbor2, msgpack
total, ts = Decimal("40.20"), datetime.fromisoformat("2025-01-01T00:02:38Z")
blob = cbor2.dumps(total)
print("CBOR decimal:", blob.hex(" "), "->", repr(cbor2.loads(blob)))
print("MessagePack datetime:", msgpack.packb(ts, datetime=True).hex(" "))
try:
    msgpack.packb(total)
except TypeError as e:
    print("MessagePack decimal:", e)
Output
CBOR decimal: c4 82 21 19 0f b4 -> Decimal('40.20')
MessagePack datetime: d6 ff 67 74 86 1e
MessagePack decimal: can not serialize 'decimal.Decimal' object

c4 is tag 4, a decimal fraction: an array of two (82), exponent -2 (21), mantissa 4020 (19 0f b4). MessagePack 229,447 writes the timestamp as ext type -1 (d6 ff) plus four bytes of epoch seconds, but money must become cents, a string or a custom ext type.