MqttX.Payload.Protobuf (MqttX v0.7.0)
View SourceProtocol Buffers payload codec using Protox.
Requires the protox optional dependency.
Unlike JSON, Protobuf requires knowing the message type for decoding. This codec provides both a generic interface and message-specific functions.
Usage
# Encoding (returns iodata by default)
{:ok, binary} = MqttX.Payload.Protobuf.encode(my_proto_struct)
# Decoding (requires message module)
{:ok, struct} = MqttX.Payload.Protobuf.decode(binary, MyMessage)
# For the behaviour interface, use with a message type in the term
{:ok, binary} = MqttX.Payload.Protobuf.encode({MyMessage, data})
Summary
Functions
Decode a Protobuf message with the specified message module.
Encode to iodata (more efficient, avoids binary copy).