Rust

v3

Module

MQTT 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.

Rust
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;
Rust
pub fn connack(return_code: u8) -> Vec<u8>

CONNACK: no acknowledge flags, then the return code.

use utopia_mqtt::spec::v3::connect;
Rust
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;
Rust
pub fn disconnect() -> Vec<u8>

DISCONNECT: no reason code, no properties.

use utopia_mqtt::spec::v3::puback;
Rust
pub fn puback(packet_id: &[u8]) -> Vec<u8>

PUBACK: the two-byte packet id, as given.

use utopia_mqtt::spec::v3::publish;
Rust
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;
Rust
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;
Rust
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;
Rust
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;
Rust
pub fn unsubscribe<T: AsRef<[u8]>>(packet_id: u16, filters: &[T]) -> Vec<u8>

UNSUBSCRIBE: packet id, then each topic filter.

Rust
pub const PROTOCOL_LEVEL: u8 = 4

The protocol level of MQTT 3.1.1.

Rust
pub const RETURN_ACCEPTED: u8 = 0x00

CONNACK: accepted.

Rust
pub const RETURN_BAD_CREDENTIALS: u8 = 0x04

CONNACK: bad user name or password.

Rust
pub const RETURN_IDENTIFIER_REJECTED: u8 = 0x02

CONNACK: identifier rejected.

Rust
pub const RETURN_NOT_AUTHORIZED: u8 = 0x05

CONNACK: not authorized.

Rust
pub const RETURN_SERVER_UNAVAILABLE: u8 = 0x03

CONNACK: server unavailable.

Rust
pub const RETURN_UNACCEPTABLE_PROTOCOL: u8 = 0x01

CONNACK: unacceptable protocol version.

Rust
pub const SUBSCRIBE_FAILURE: u8 = 0x80

SUBACK: the failure marker (a granted QoS otherwise).