ExMqtt.Protocol.Types (ex_mqtt_uv v0.1.0)

Copy Markdown View Source

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

auth()

bool_to_bit(bool)

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

Converts a boolean to 1 or 0.

connack()

connect()

decode_binary(arg1)

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

Decodes a length-prefixed binary payload from binary.

decode_string(arg1)

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

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

deframe(arg)

@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(bin)

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

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

encode_string(str)

@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(packet_type, flags, body)

@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()