spec
ModuleControl packet encoders for each protocol version: v3 (MQTT 3.1.1)
and v5 (MQTT 5.0).
Contents
2 submodules.
spec::v3
Own pageMQTT 3.1.1 encoders. There are no property blocks and no reason codes: CONNACK carries a return code, SUBACK a granted QoS (or failure) byte per filter, and there is no AUTH.
use utopia_mqtt::spec::v3::connack;pub fn connack(return_code: u8) -> Vec<u8>CONNACK: no acknowledge flags, then the return code.
use utopia_mqtt::spec::v3::connect;pub fn connect(client_id: &[u8], keep_alive: u16, clean_session: bool, username: &[u8], password: &[u8]) -> Vec<u8>CONNECT: protocol header and client id, plus the user name and password when they are not empty.
use utopia_mqtt::spec::v3::disconnect;pub fn disconnect() -> Vec<u8>DISCONNECT: no reason code, no properties.
use utopia_mqtt::spec::v3::puback;pub fn puback(packet_id: &[u8]) -> Vec<u8>PUBACK: the two-byte packet id, as given.
use utopia_mqtt::spec::v3::publish;pub fn publish(topic: &[u8], payload: &[u8], qos: u8, packet_id: u16, dup: bool) -> Vec<u8>PUBLISH: topic, packet id (above QoS 0), then payload. dup marks a
re-delivery of a QoS 1 message and is ignored at QoS 0.
use utopia_mqtt::spec::v3::suback;pub fn suback(packet_id: &[u8], return_codes: &[u8]) -> Vec<u8>SUBACK: the packet id, then one granted QoS (or failure) byte per filter.
use utopia_mqtt::spec::v3::subscribe;pub fn subscribe<T: AsRef<[u8]>>(packet_id: u16, filters: &[T], qos: u8) -> Vec<u8>SUBSCRIBE: packet id, then each topic filter with qos as its options
byte.
use utopia_mqtt::spec::v3::unsuback;pub fn unsuback(packet_id: &[u8]) -> Vec<u8>UNSUBACK: the two-byte packet id (3.1.1 has no reason codes).
use utopia_mqtt::spec::v3::unsubscribe;pub fn unsubscribe<T: AsRef<[u8]>>(packet_id: u16, filters: &[T]) -> Vec<u8>UNSUBSCRIBE: packet id, then each topic filter.
pub const PROTOCOL_LEVEL: u8 = 4The protocol level of MQTT 3.1.1.
pub const RETURN_ACCEPTED: u8 = 0x00CONNACK: accepted.
pub const RETURN_BAD_CREDENTIALS: u8 = 0x04CONNACK: bad user name or password.
pub const RETURN_IDENTIFIER_REJECTED: u8 = 0x02CONNACK: identifier rejected.
pub const RETURN_NOT_AUTHORIZED: u8 = 0x05CONNACK: not authorized.
pub const RETURN_SERVER_UNAVAILABLE: u8 = 0x03CONNACK: server unavailable.
pub const RETURN_UNACCEPTABLE_PROTOCOL: u8 = 0x01CONNACK: unacceptable protocol version.
pub const SUBSCRIBE_FAILURE: u8 = 0x80SUBACK: the failure marker (a granted QoS otherwise).
spec::v5
Own pageMQTT 5.0 encoders. Every acknowledgement carries a reason code and a
property block (empty when None); PUBLISH carries the block before its
payload. Encoding fails only for a property with an unknown identifier.
use utopia_mqtt::spec::v5::auth;pub fn auth(reason_code: u8, properties: Option<&Properties>) -> Result<Vec<u8>, Error>AUTH: the reason code, then properties (the Authentication Method and Data live in the block).
use utopia_mqtt::spec::v5::connack;pub fn connack(reason_code: u8, properties: Option<&Properties>) -> Result<Vec<u8>, Error>CONNACK: no acknowledge flags, the reason code, then properties.
use utopia_mqtt::spec::v5::connect;pub fn connect(client_id: &[u8], keep_alive: u16, clean_start: bool, properties: Option<&Properties>) -> Result<Vec<u8>, Error>CONNECT: protocol header, properties (authentication, metadata), then the client id.
use utopia_mqtt::spec::v5::disconnect;pub fn disconnect(reason_code: u8, properties: Option<&Properties>) -> Result<Vec<u8>, Error>DISCONNECT: the reason code, then properties.
use utopia_mqtt::spec::v5::puback;pub fn puback(packet_id: &[u8]) -> Vec<u8>PUBACK: the two-byte packet id (reason and properties are omitted for a success).
use utopia_mqtt::spec::v5::publish;pub fn publish(topic: &[u8], payload: &[u8], qos: u8, packet_id: u16, properties: Option<&Properties>, dup: bool) -> Result<Vec<u8>, Error>PUBLISH: topic, packet id (above QoS 0), properties, then payload.
dup marks a re-delivery of a QoS 1 message and is ignored at QoS 0.
use utopia_mqtt::spec::v5::suback;pub fn suback(packet_id: &[u8], reason_codes: &[u8], properties: Option<&Properties>) -> Result<Vec<u8>, Error>SUBACK: packet id, properties, then one reason code per filter.
use utopia_mqtt::spec::v5::subscribe;pub fn subscribe<T: AsRef<[u8]>>(packet_id: u16, filters: &[T], qos: u8, properties: Option<&Properties>) -> Result<Vec<u8>, Error>SUBSCRIBE: packet id, properties, then each topic filter with qos
as its options byte.
use utopia_mqtt::spec::v5::unsuback;pub fn unsuback(packet_id: &[u8], count: usize, properties: Option<&Properties>) -> Result<Vec<u8>, Error>UNSUBACK: packet id, properties, then a success code for each of
count filters.
use utopia_mqtt::spec::v5::unsubscribe;pub fn unsubscribe<T: AsRef<[u8]>>(packet_id: u16, filters: &[T], properties: Option<&Properties>) -> Result<Vec<u8>, Error>UNSUBSCRIBE: packet id, properties, then each topic filter.
pub const AUTH_CONTINUE: u8 = 0x18AUTH: continue authentication.
pub const AUTH_REAUTH: u8 = 0x19AUTH: re-authenticate.
pub const AUTH_SUCCESS: u8 = 0x00AUTH: success.
pub const PROTOCOL_LEVEL: u8 = 5The protocol level of MQTT 5.0.
pub const REASON_NOT_AUTHORIZED: u8 = 0x87Not authorized.
pub const REASON_SUCCESS: u8 = 0x00Success, in every acknowledgement.