OmniBuf.Codec (omnibuf v0.1.0)

Copy Markdown View Source

Shared high-performance OmniBuf v0.1 field encoders and decoders used by generated plugin code (Tier 1), Protobuf integration (Tier 2), and declarative OmniBuf.Schema structs (Tier 3).

Summary

Functions

Decodes a WireArray field, enforcing ElementType match against elem_type (collection header mismatch MUST return a parse error) and max nesting depth.

Decodes a single collection element or map key/value.

Decodes a WireMap field, merging entries into existing (duplicate keys replace prior values outright) and enforcing KeyType/ValueType match and depth limits.

Decodes a length-prefixed WireSubMsg into mod, merging onto existing if non-nil.

Default zero value for a schema field type.

Encodes a WireArray value ([ByteLen][ElementType: 1B][Count][Elements]).

Encodes a value for inclusion inside a WireArray or WireMap (no field tag).

Encodes a WireMap value ([ByteLen][KeyType: 1B][ValueType: 1B][Count][Entries]) with deterministic key ordering (unsigned UTF-8 byte order for strings, numeric order for integers, false before true for booleans).

Maps an OmniBuf schema type descriptor to its wire type code (for tags/headers).

Functions

decode_array(bin, elem_type, depth)

@spec decode_array(binary(), term(), non_neg_integer()) ::
  {:ok, list(), binary()} | {:error, OmniBuf.Error.t()}

Decodes a WireArray field, enforcing ElementType match against elem_type (collection header mismatch MUST return a parse error) and max nesting depth.

decode_element(t, bin, depth)

@spec decode_element(term(), binary(), non_neg_integer()) ::
  {:ok, term(), binary()} | {:error, OmniBuf.Error.t()}

Decodes a single collection element or map key/value.

decode_map(bin, key_type, val_type, existing, depth)

@spec decode_map(binary(), term(), term(), map(), non_neg_integer()) ::
  {:ok, map(), binary()} | {:error, OmniBuf.Error.t()}

Decodes a WireMap field, merging entries into existing (duplicate keys replace prior values outright) and enforcing KeyType/ValueType match and depth limits.

decode_submsg(mod, bin, existing, depth)

@spec decode_submsg(module(), binary(), struct() | nil, non_neg_integer()) ::
  {:ok, struct(), binary()} | {:error, OmniBuf.Error.t()}

Decodes a length-prefixed WireSubMsg into mod, merging onto existing if non-nil.

default_value(mod)

@spec default_value(term()) :: term()

Default zero value for a schema field type.

encode_array_value(elem_type, list)

@spec encode_array_value(term(), list()) :: iodata()

Encodes a WireArray value ([ByteLen][ElementType: 1B][Count][Elements]).

encode_element(mod, v)

@spec encode_element(term(), term()) :: iodata()

Encodes a value for inclusion inside a WireArray or WireMap (no field tag).

encode_map_value(key_type, val_type, map)

@spec encode_map_value(term(), term(), map()) :: iodata()

Encodes a WireMap value ([ByteLen][KeyType: 1B][ValueType: 1B][Count][Entries]) with deterministic key ordering (unsigned UTF-8 byte order for strings, numeric order for integers, false before true for booleans).

wire_type_for(mod)

@spec wire_type_for(term()) :: 0..15

Maps an OmniBuf schema type descriptor to its wire type code (for tags/headers).