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

MQTT Variable Byte Integer encoding and decoding (1 to 4 bytes, max 268,435,455).

# `decode`

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

Decodes a Variable Byte Integer from the front of `binary`.

Returns:
- `{:ok, value, rest}` on success
- `:incomplete` when more bytes are needed
- `{:error, :malformed_varint}` when the encoding exceeds 4 bytes

# `encode`

```elixir
@spec encode(non_neg_integer()) :: {:ok, binary()} | {:error, :varint_out_of_range}
```

Encodes a non-negative integer (`0..268_435_455`) into a Variable Byte Integer binary.

# `encode!`

```elixir
@spec encode!(non_neg_integer()) :: binary()
```

Same as `encode/1` but returns the binary directly or raises `ArgumentError`.

---

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