# `ExMqtt.Protocol.Types`
[🔗](https://github.com/Ultraluv/ex_mqtt_uv/blob/v0.1.0/lib/ex_mqtt/protocol/types.ex#L1)

Primitive MQTT wire-format encoding and decoding helpers (UTF-8 strings,
binary data, fixed headers, and packet type constants).

# `auth`

# `bool_to_bit`

```elixir
@spec bool_to_bit(boolean()) :: 0 | 1
```

Converts a boolean to `1` or `0`.

# `connack`

# `connect`

# `decode_binary`

```elixir
@spec decode_binary(binary()) :: {:ok, binary(), binary()} | {:error, atom()}
```

Decodes a length-prefixed binary payload from `binary`.

# `decode_string`

```elixir
@spec decode_string(binary()) :: {:ok, String.t(), binary()} | {:error, atom()}
```

Decodes a length-prefixed UTF-8 string from `binary`.

# `deframe`

```elixir
@spec deframe(binary()) ::
  {:ok, non_neg_integer(), non_neg_integer(), binary(), binary()}
  | :incomplete
  | {:error, atom()}
```

Extracts one complete MQTT frame `{packet_type, flags, body, rest}` from a TCP stream buffer.
Returns `:incomplete` when the buffer does not yet contain a full packet.

# `disconnect`

# `encode_binary`

```elixir
@spec encode_binary(binary()) :: {:ok, iodata()} | {:error, atom()}
```

Encodes a length-prefixed binary payload (2-byte big-endian length prefix).

# `encode_string`

```elixir
@spec encode_string(binary()) :: {:ok, iodata()} | {:error, atom()}
```

Encodes a UTF-8 string with a 2-byte big-endian length prefix.
Validates UTF-8 and rejects U+0000 null characters per MQTT spec.

# `frame`

```elixir
@spec frame(non_neg_integer(), non_neg_integer(), iodata()) ::
  {:ok, iodata()} | {:error, atom()}
```

Wraps a variable header + payload iodata with the MQTT Fixed Header.

# `pingreq`

# `pingresp`

# `puback`

# `pubcomp`

# `publish`

# `pubrec`

# `pubrel`

# `suback`

# `subscribe`

# `unsuback`

# `unsubscribe`

---

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