macula_record_cbor (macula v7.0.0)
View SourceDeterministic CBOR encoder/decoder.
Implements the subset of RFC 8949 needed by Macula records: unsigned ints, negative ints, floats, byte strings, text strings, arrays, maps, and null.
Encoding follows RFC 8949 §4.2.1 (deterministic):
- Smallest length encoding.
- Definite lengths only (no indefinite items).
- Map keys sorted by bytewise lexicographic order of their deterministic encoding.
Internal value representation:
non_neg_integer()— uint (major 0)neg_integer()— negative integer (major 1)binary()— byte string (major 2){text, binary()}— UTF-8 text string (major 3)atom()— UTF-8 text string (major 3) viaatom_to_binary/1. Accepted for round-trip robustness: the frame decoder atomizes binary keys via binary_to_existing_atom/1, so a record decoded from the wire and re-encoded for sig verify carries atom keys inside the payload sub-map. Encoding atoms as text reproduces the original wire bytes byte-for-byte (atom names round-trip exactly through utf8).nullhas a dedicated clause and is NOT routed here.[value()]— array (major 4)#{value() => value()}— map (major 5)null— simple null (major 7, value 22)float()— IEEE 754 binary64 (major 7, value 27)
Summary
Functions
Can this integer be rendered as major 0 / major 1?
Types
Functions
Can this integer be rendered as major 0 / major 1?
Exported so callers that must decide admissibility BEFORE encoding (see macula_frame:check_payload/1) can ask rather than restate the bound. A bignum past 64 bits matches no encode/1 clause and would otherwise crash whichever process happens to be encoding.