Search documentation of macula

# macula_record_cbor (macula v4.4.9)

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)
- `atom()` — UTF-8 text string (major 3) via `atom_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). `null` has a dedicated clause and is NOT routed here.
- `[value()]` — array (major 4)
- `#{value() => value()}` — map (major 5)
- `null` — simple null (major 7, value 22)

# Summary

## Types

value/0

## Functions

decode(Bin)
encode(N)

# Types

# value/0

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

# Functions

# decode(Bin)

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

# encode(N)

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