# `OmniBuf.Codec`
[🔗](https://github.com/omnibuf/omnibuf-elixir/blob/v0.1.0/lib/omnibuf/codec.ex#L1)

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).

# `decode_array`

```elixir
@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`

```elixir
@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`

```elixir
@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`

```elixir
@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`

```elixir
@spec default_value(term()) :: term()
```

Default zero value for a schema field type.

# `encode_array_value`

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

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

# `encode_element`

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

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

# `encode_map_value`

```elixir
@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`

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

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
