# `ExMqtt.State.TopicAlias`
[🔗](https://github.com/Ultraluv/ex_mqtt_uv/blob/v0.1.0/lib/ex_mqtt/state/topic_alias.ex#L1)

MQTT 5.0 bidirectional Topic Alias table.

- `inbound` maps broker-assigned alias integers to topic names (bounded by
  the client's `topic_alias_maximum`).
- `outbound` maps topic names to client-assigned alias integers (bounded by
  the broker's `topic_alias_maximum` received in CONNACK).

# `t`

```elixir
@type t() :: %ExMqtt.State.TopicAlias{
  inbound: %{optional(pos_integer()) =&gt; String.t()},
  inbound_max: non_neg_integer(),
  next_outbound_alias: pos_integer(),
  outbound: %{optional(String.t()) =&gt; pos_integer()},
  outbound_max: non_neg_integer()
}
```

# `apply_outbound`

```elixir
@spec apply_outbound(t(), String.t(), map()) :: {String.t(), map(), t()}
```

Applies automatic outbound Topic Alias compression for a PUBLISH packet.

- If the broker advertised `outbound_max == 0` or the caller already set `:topic_alias`,
  the topic and properties are left unchanged.
- On first publish of a topic (while `next_outbound_alias <= outbound_max`), registers
  the alias and keeps the full topic name + `topic_alias: alias_id`.
- On subsequent publishes of that same topic on the same connection, replaces the
  wire topic with `""` and sets `topic_alias: alias_id`.

# `new`

```elixir
@spec new(non_neg_integer(), non_neg_integer()) :: t()
```

Creates a fresh TopicAlias table (reset on every new network connection).

# `reset`

```elixir
@spec reset(t(), non_neg_integer()) :: t()
```

Resets all alias mappings (required by MQTT 5.0 spec on disconnect/reconnect).

# `resolve_inbound`

```elixir
@spec resolve_inbound(t(), String.t(), pos_integer() | nil) ::
  {:ok, String.t(), t()} | {:error, :topic_alias_invalid}
```

Resolves an incoming PUBLISH topic and optional `:topic_alias` property.

---

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