macula_record_cbor (macula v3.5.0)

View Source

Deterministic CBOR encoder/decoder.

Implements the subset of RFC 8949 needed by Macula records: unsigned ints, 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)
  • binary() — byte string (major 2)
  • {text, binary()} — UTF-8 text string (major 3)
  • [value()] — array (major 4)
  • #{value() => value()} — map (major 5)
  • null — simple null (major 7, value 22)

Summary

Types

value/0

-type value() ::
          non_neg_integer() | binary() | {text, binary()} | [value()] | #{value() => value()} | null.

Functions

decode(Bin)

-spec decode(binary()) -> value().

encode(N)

-spec encode(value()) -> binary().