Primitive MQTT wire-format encoding and decoding helpers (UTF-8 strings, binary data, fixed headers, and packet type constants).
Summary
Functions
Converts a boolean to 1 or 0.
Decodes a length-prefixed binary payload from binary.
Decodes a length-prefixed UTF-8 string from binary.
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.
Encodes a length-prefixed binary payload (2-byte big-endian length prefix).
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.
Wraps a variable header + payload iodata with the MQTT Fixed Header.
Functions
@spec bool_to_bit(boolean()) :: 0 | 1
Converts a boolean to 1 or 0.
Decodes a length-prefixed binary payload from binary.
Decodes a length-prefixed UTF-8 string from binary.
@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.
Encodes a length-prefixed binary payload (2-byte big-endian length prefix).
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.
@spec frame(non_neg_integer(), non_neg_integer(), iodata()) :: {:ok, iodata()} | {:error, atom()}
Wraps a variable header + payload iodata with the MQTT Fixed Header.