# `Electric.Postgres.ReplicationClient.MessageConverter`
[🔗](https://github.com/electric-sql/electric/tree/%40core/sync-service%401.6.2/packages/sync-service/lib/electric/postgres/replication_client/message_converter.ex#L1)

Conversion of incoming Postgres logical replication messages
to internal event representation.

It is stateful, consuming the replication messages in sequential order
to keep track of the relation and transaction information needed
to form the operations.

It also enforces a maximum transaction size if configured to do so,
and batches operations up to a maximum batch size before returning
a TransactionFragment.

# `t`

```elixir
@type t() :: %Electric.Postgres.ReplicationClient.MessageConverter{
  max_batch_size: non_neg_integer(),
  max_tx_size: non_neg_integer() | nil,
  relations: %{
    optional(Electric.Postgres.LogicalReplication.Messages.relation_id()) =&gt;
      Electric.Postgres.LogicalReplication.Messages.Relation.t()
  },
  tx_change_count: non_neg_integer(),
  tx_op_index: non_neg_integer() | nil,
  tx_size: non_neg_integer(),
  txn_fragment: Electric.Replication.Changes.TransactionFragment.t() | nil
}
```

# `convert`

```elixir
@spec convert(Electric.Postgres.LogicalReplication.Messages.message(), t()) ::
  {:ok,
   Electric.Replication.Changes.TransactionFragment.t()
   | Electric.Replication.Changes.Relation.t(), t()}
  | {:buffering, t()}
  | {:error, {:replica_not_full, String.t()}}
  | {:error, {:exceeded_max_tx_size, String.t()}}
```

Convert incoming logical replication messages to internal change representation.

Returns:
- `{:ok, %TransactionFragment{}, state}` when a batch is ready (on commit or max_batch_size reached)
- `{:ok, %Relation{}, state}` when a Relation is encountered (returned immediately)
- `{:buffering, state}` if no flush occurred
- `{:error, reason}` on error

# `in_transaction?`
*macro* 

# `new`

---

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