Struct Property
pub struct Property {
pub(crate) cprop: MQTTProperty,
}Expand description
A single MQTT v5 property.
An MQTT v5 property consists of both a property “code” and a value. The code indicates what the property contains (Response Topic, Will Delay Interval, etc), and also the data type for the value. Each copde corresponds to a single, specific data type as described in the v5 spec, here: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901027
There are only a limited number of data types that are possible for
properties:
“Byte” - u8
“Two Byte Integer” - u16
“Four Byte Integer” - u32
“Binary Data” - Vec<u8>
“UTF-8 Encoded String” - String
“UTF-8 String Pair” - (String,String)
Fields§
§cprop: MQTTPropertyImplementations§
§impl Property
impl Property
pub fn new<T>(code: PropertyCode, val: T) -> Result<Property, Error>where
T: Any + 'static,
pub fn new<T>(code: PropertyCode, val: T) -> Result<Property, Error>where
T: Any + 'static,
Creates a new property for a given code and value.
The type for the value must match the type expected for the given property code exactly, otherwise it will be rejected and return None.
pub fn new_byte(code: PropertyCode, val: u8) -> Result<Property, Error>
pub fn new_byte(code: PropertyCode, val: u8) -> Result<Property, Error>
Creates a single-byte property
pub fn new_u16(code: PropertyCode, val: u16) -> Result<Property, Error>
pub fn new_u16(code: PropertyCode, val: u16) -> Result<Property, Error>
Creates a 2-byte integer property
pub fn new_u32(code: PropertyCode, val: u32) -> Result<Property, Error>
pub fn new_u32(code: PropertyCode, val: u32) -> Result<Property, Error>
Creates a 4-byte integer property
pub fn new_int(code: PropertyCode, val: i32) -> Result<Property, Error>
pub fn new_int(code: PropertyCode, val: i32) -> Result<Property, Error>
Creates a new integer property.
This works for any sized integer type, from byte on up.
pub fn new_binary<V>(code: PropertyCode, bin: V) -> Result<Property, Error>
pub fn new_binary<V>(code: PropertyCode, bin: V) -> Result<Property, Error>
Creates a new binary property.
pub fn new_string(code: PropertyCode, s: &str) -> Result<Property, Error>
pub fn new_string(code: PropertyCode, s: &str) -> Result<Property, Error>
Creates a new string property.
pub fn new_string_pair(
code: PropertyCode,
key: &str,
val: &str,
) -> Result<Property, Error>
pub fn new_string_pair( code: PropertyCode, key: &str, val: &str, ) -> Result<Property, Error>
Creates a new string pair property.
pub fn property_code(&self) -> PropertyCode
pub fn property_code(&self) -> PropertyCode
Gets the MQTT code for the property.
pub fn property_type(&self) -> PropertyType
pub fn property_type(&self) -> PropertyType
Gets the type of this property.
pub fn get_int(&self) -> Option<i32>
pub fn get_int(&self) -> Option<i32>
Gets the property value as an integer. This extracts an integer value from the property. It works with any of the int types, one, two, or four bytes. If the Property contains an integer type it will be returned as Some(val), otherwise it will return None.
pub fn get_binary(&self) -> Option<Vec<u8>>
pub fn get_binary(&self) -> Option<Vec<u8>>
Gets the property value as a binary blob.
pub fn get_string(&self) -> Option<String>
pub fn get_string(&self) -> Option<String>
Gets the property value as a string.
pub fn get_string_pair(&self) -> Option<(String, String)>
pub fn get_string_pair(&self) -> Option<(String, String)>
Gets the property value as a string pair.