# `Replicant.Decoder`
[🔗](https://github.com/baselabs/replicant/blob/v0.3.1/lib/replicant/decoder/decoder.ex#L4)

Binary decoder for the Postgres logical-replication `pgoutput` stream.

The byte parser (`decode_message/1`) is vendored from `walex` (MIT; see NOTICE),
itself derived from `cainophile` and `supabase-realtime`. It raises on malformed
input and produces `%Unsupported{data: binary}` (carrying raw bytes) for unknown
message types.

**Callers MUST use `decode/1`, not `decode_message/1`.** `decode/1` is the
value-free-error boundary (Critical Rule 1): it catches every raise, scrubs the
raw bytes, and normalises `%Unsupported{}` into a value-free
`{:error, %Replicant.Error{reason: :unsupported_message}}`. No row value or raw
WAL byte ever escapes the decode boundary.

# `decode`

```elixir
@spec decode(
  binary(),
  keyword()
) :: {:ok, struct()} | {:error, Replicant.Error.t()}
```

Decode one pgoutput message, value-free on failure.

Returns `{:ok, message_struct}` on success, or
`{:error, %Error{reason: :decode_failure | :unsupported_message}}` — never
raises, never surfaces raw bytes.

---

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