The decode boundary + dispatcher for the logical-replication stream.
decode/2 dispatches one XLogData payload to the configured decoder plugin
(ADR-0009; opts[:decoder], default :pgoutput) and is the value-free-error
boundary (Critical Rule 1): it catches every raise/throw/exit from ANY plugin's
parser — the vendored pgoutput byte parser raises on malformed input, the pglogical
parser throws on malformed frames, the wal2json JSON decoder errors on malformed
JSON — scrubs the raw bytes, and returns a value-free {:error, %Replicant.Error{}}.
No row value or raw WAL byte ever escapes the decode boundary.
The pgoutput byte parser (pgoutput_decode/2, @doc false) is vendored from walex
(MIT; see NOTICE), itself derived from cainophile and supabase-realtime; it
produces %Unsupported{data: binary} (carrying raw bytes) for unknown message types,
which decode/2 normalises value-free. Callers MUST use decode/2.
Summary
Functions
Decode one replication payload through the configured decoder plugin, value-free on failure.
Functions
@spec decode( binary(), keyword() ) :: {:ok, [struct()], term()} | {:error, Replicant.Error.t()}
Decode one replication payload through the configured decoder plugin, value-free on failure.
opts[:decoder] selects the plugin (:pgoutput default, :pglogical, :wal2json);
opts[:cache] is the plugin's per-connection state (threaded by the Connection).
Returns {:ok, messages, cache} (zero or more decoded structs — wal2json emits a
synthesized %Relation{} ahead of a schema-drifted change) or
{:error, %Error{reason: :decode_failure | :unsupported_message | ...}} — never
raises, never surfaces raw bytes.