mqtt_packet_map (mqtt_packet_map v1.3.1)

View Source

MQTT packet encoder/decoder

Summary

Functions

Check if a binary contains a complete packet within the maximum packet size.

Encode a MQTT message to a binary.

Encode a MQTT message to a binary.

Return the full packet size, including the fixed header, when available.

Types

decode_error/0

-type decode_error() ::
          incomplete_packet | malformed_header | unknown_protocol | invalid_packet | invalid_topic |
          malformed_packet |
          {unknown_property, integer()}.

mqtt_packet/0

-type mqtt_packet() :: map().

mqtt_topic/0

-type mqtt_topic() :: [mqtt_topic_part()] | binary().

mqtt_topic_part/0

-type mqtt_topic_part() :: binary() | integer() | atom() | undefined | '+' | '#'.

mqtt_version/0

-type mqtt_version() :: undefined | 3 | 4 | 5.

packet_size_error/0

-type packet_size_error() :: malformed_packet | packet_too_large.

Functions

check_packet_size(Data, MaxPacketSize)

-spec check_packet_size(binary(), pos_integer() | undefined) ->
                           ok | incomplete | {error, packet_size_error()}.

Check if a binary contains a complete packet within the maximum packet size.

decode(Data)

-spec decode(binary()) -> {ok, {mqtt_packet(), binary()}} | {error, decode_error()}.

decode(MQTTVersion, Data)

-spec decode(mqtt_version(), binary()) -> {ok, {mqtt_packet(), binary()}} | {error, decode_error()}.

encode(Msg)

-spec encode(mqtt_packet()) -> {ok, binary()} | {error, term()}.

Encode a MQTT message to a binary.

encode(MQTTVersion, Msg)

-spec encode(mqtt_version(), mqtt_packet()) -> {ok, binary()} | {error, term()}.

Encode a MQTT message to a binary.

packet_size(_)

-spec packet_size(binary()) -> {ok, non_neg_integer()} | incomplete | {error, malformed_packet}.

Return the full packet size, including the fixed header, when available.