Rust

property

Module

MQTT 5.0 properties: identifier/value pairs carried in a block (a variable byte length, then each property) by every 5.0 packet that has one. MQTT 3.1.1 packets have none.

Contents

use utopia_mqtt::Properties;
Rust
pub struct Properties

An ordered list of [Property]: an MQTT 5.0 property block. It encodes to its length as a variable byte integer followed by each property, and parses the same shape back.

Rust
use utopia_mqtt::{Properties, Property};

let block = Properties::new()
    .with(Property::bytes(Property::REASON_STRING, "ok"))
    .with(Property::user("projectId", "p1"))
    .encode()?;
let (parsed, end) = Properties::parse(&block, 0)?;
assert_eq!(end, block.len());
assert_eq!(parsed.bytes(Property::REASON_STRING), Some(&b"ok"[..]));
assert_eq!(parsed.user(), [(b"projectId".to_vec(), b"p1".to_vec())]);
use utopia_mqtt::Property;
Rust
pub struct Property

One MQTT 5.0 property: an identifier and a value whose wire encoding the identifier fixes (see Property::wire_type).

A User Property (Property::USER) carries one key and value; a block may hold any number of them.

Rust
use utopia_mqtt::{Property, Value};

let expiry = Property::new(Property::SESSION_EXPIRY_INTERVAL, Value::Int(3600));
assert_eq!(expiry.encode()?, [0x11, 0x00, 0x00, 0x0E, 0x10]);
assert_eq!(Property::user("projectId", "p1").encode()?, b"\x26\x00\x09projectId\x00\x02p1");
use utopia_mqtt::Value;
Rust
pub enum Value

The value of a Property.

Also implements From.
use utopia_mqtt::WireType;
Rust
pub enum WireType

The wire encoding of a property's value, fixed by its identifier.