v3
ModuleMQTT 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;
assert_eq!(v3::connack(v3::RETURN_ACCEPTED), b"\x20\x02\x00\x00");
assert_eq!(v3::suback(b"\x00\x02", &[v3::SUBSCRIBE_FAILURE]), b"\x90\x03\x00\x02\x80");Contents
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).