High-performance MQTT packet encoder and decoder.
Supports MQTT 3.1, 3.1.1, and 5.0 protocols with all 15 packet types.
Encoding
packet = %{type: :publish, topic: "test", payload: "hello", qos: 0, retain: false}
{:ok, binary} = MqttX.Packet.Codec.encode(4, packet)Decoding
{:ok, {packet, rest}} = MqttX.Packet.Codec.decode(4, binary)
Summary
Functions
Total on-the-wire size a buffered packet declares in its fixed header, without decoding the body.
Decode an MQTT packet from binary data.
Encode an MQTT packet to binary.
Encode an MQTT packet to iodata (more efficient, avoids binary copy).
Functions
@spec declared_length(binary()) :: {:ok, non_neg_integer()} | :incomplete | {:error, :malformed_header}
Total on-the-wire size a buffered packet declares in its fixed header, without decoding the body.
Returns {:ok, total_bytes} (fixed header + remaining length) once enough
of the header has arrived, :incomplete if the header itself is still
partial, or {:error, :malformed_header}. Lets transports reject oversized
packets (§3.1.2.11.4) before buffering up to the declared size.
Decode an MQTT packet from binary data.
Returns {:ok, {packet, rest}} on success, {:error, reason} on failure,
or {:error, :incomplete} if more data is needed.
Encode an MQTT packet to binary.
Returns {:ok, binary} on success or {:error, reason} on failure.
Encode an MQTT packet to iodata (more efficient, avoids binary copy).