MQTT 5.0 Properties encoding and decoding.
Supports all 27 MQTT 5.0 property types, each checked against the packet that carries it (§2.2.2.2).
Shapes
Properties decode to a map keyed by name. :user_properties is a list of
{key, value} pairs in wire order. :subscription_identifier is an
integer when a packet carries one — a SUBSCRIBE always, a PUBLISH matching
one subscription — and a list of integers when a PUBLISH matches several
subscriptions (one identifier per subscription, §3.3.2.3.8). Every other
property is a single value.
Summary
Functions
Decode properties from binary.
decode/2 for a known packet type: a property the type does not define
makes the packet malformed (§2.2.2.2).
The first property in properties that packet_type does not define, or nil.
Encode properties map to binary with length prefix.
encode/2 for a known packet type: a property the type does not define
(§2.2.2.2) is refused. The throw is caught at the Codec.encode boundary
and becomes {:error, {:property_not_allowed, name, packet_type}}.
Types
Functions
Decode properties from binary.
Returns {:ok, properties_map, rest} or {:error, reason}.
decode/2 for a known packet type: a property the type does not define
makes the packet malformed (§2.2.2.2).
@spec disallowed(map(), packet_type()) :: atom() | nil
The first property in properties that packet_type does not define, or nil.
Encode properties map to binary with length prefix.
Only encodes properties for MQTT 5.0 (a zero length when there are none); other versions get no bytes at all.
@spec encode(integer(), map(), packet_type()) :: iodata()
encode/2 for a known packet type: a property the type does not define
(§2.2.2.2) is refused. The throw is caught at the Codec.encode boundary
and becomes {:error, {:property_not_allowed, name, packet_type}}.