Rust

spec

Module

Control packet encoders for each protocol version: v3 (MQTT 3.1.1) and v5 (MQTT 5.0).

Contents

2 submodules.

spec::v3

Own page

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.

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

spec::v5

Own page

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

Rust
pub const AUTH_CONTINUE: u8 = 0x18

AUTH: continue authentication.

Rust
pub const AUTH_REAUTH: u8 = 0x19

AUTH: re-authenticate.

Rust
pub const AUTH_SUCCESS: u8 = 0x00

AUTH: success.

Rust
pub const PROTOCOL_LEVEL: u8 = 5

The protocol level of MQTT 5.0.

Rust
pub const REASON_NOT_AUTHORIZED: u8 = 0x87

Not authorized.

Rust
pub const REASON_SUCCESS: u8 = 0x00

Success, in every acknowledgement.