Enum Property

Source
pub enum Property {
Show 27 variants PayloadFormatIndicator(PayloadFormatIndicator), MessageExpiryInterval(MessageExpiryInterval), ContentType(ContentType), ResponseTopic(ResponseTopic), CorrelationData(CorrelationData), SubscriptionIdentifier(SubscriptionIdentifier), SessionExpiryInterval(SessionExpiryInterval), AssignedClientIdentifier(AssignedClientIdentifier), ServerKeepAlive(ServerKeepAlive), AuthenticationMethod(AuthenticationMethod), AuthenticationData(AuthenticationData), RequestProblemInformation(RequestProblemInformation), WillDelayInterval(WillDelayInterval), RequestResponseInformation(RequestResponseInformation), ResponseInformation(ResponseInformation), ServerReference(ServerReference), ReasonString(ReasonString), ReceiveMaximum(ReceiveMaximum), TopicAliasMaximum(TopicAliasMaximum), TopicAlias(TopicAlias), MaximumQos(MaximumQos), RetainAvailable(RetainAvailable), UserProperty(UserProperty), MaximumPacketSize(MaximumPacketSize), WildcardSubscriptionAvailable(WildcardSubscriptionAvailable), SubscriptionIdentifierAvailable(SubscriptionIdentifierAvailable), SharedSubscriptionAvailable(SharedSubscriptionAvailable),
}
Expand description

MQTT v5.0 Property enum

This enum represents all possible MQTT v5.0 properties that can be included in various packet types. Each variant wraps a specific property type with its associated data and validation rules.

Properties provide extensibility to MQTT packets, allowing clients and servers to communicate additional metadata, control flow information, and authentication data.

§Usage

Properties are typically collected in a Vec<Property> and included in MQTT packets during construction or parsing.

§Examples

use mqtt_protocol_core::mqtt;

// Create a message expiry property
let expiry = mqtt::packet::MessageExpiryInterval::new(3600).unwrap();
let property = mqtt::packet::Property::MessageExpiryInterval(expiry);

// Create user property
let user_prop = mqtt::packet::UserProperty::new("key", "value").unwrap();
let property = mqtt::packet::Property::UserProperty(user_prop);

Variants§

§

PayloadFormatIndicator(PayloadFormatIndicator)

§

MessageExpiryInterval(MessageExpiryInterval)

§

ContentType(ContentType)

§

ResponseTopic(ResponseTopic)

§

CorrelationData(CorrelationData)

§

SubscriptionIdentifier(SubscriptionIdentifier)

§

SessionExpiryInterval(SessionExpiryInterval)

§

AssignedClientIdentifier(AssignedClientIdentifier)

§

ServerKeepAlive(ServerKeepAlive)

§

AuthenticationMethod(AuthenticationMethod)

§

AuthenticationData(AuthenticationData)

§

RequestProblemInformation(RequestProblemInformation)

§

WillDelayInterval(WillDelayInterval)

§

RequestResponseInformation(RequestResponseInformation)

§

ResponseInformation(ResponseInformation)

§

ServerReference(ServerReference)

§

ReasonString(ReasonString)

§

ReceiveMaximum(ReceiveMaximum)

§

TopicAliasMaximum(TopicAliasMaximum)

§

TopicAlias(TopicAlias)

§

MaximumQos(MaximumQos)

§

RetainAvailable(RetainAvailable)

§

UserProperty(UserProperty)

§

MaximumPacketSize(MaximumPacketSize)

§

WildcardSubscriptionAvailable(WildcardSubscriptionAvailable)

§

SubscriptionIdentifierAvailable(SubscriptionIdentifierAvailable)

§

SharedSubscriptionAvailable(SharedSubscriptionAvailable)

Implementations§

Source§

impl Property

Source

pub fn id(&self) -> PropertyId

Get the property identifier for this property

Returns the PropertyId that corresponds to this property type. This is useful for determining the property type without matching on the enum variant.

§Examples
use mqtt_protocol_core::mqtt;

let prop = mqtt::packet::Property::MessageExpiryInterval(
    mqtt::packet::MessageExpiryInterval::new(3600).unwrap()
);
assert_eq!(prop.id(), mqtt::packet::PropertyId::MessageExpiryInterval);
Source

pub fn size(&self) -> usize

Get the encoded size of this property in bytes

Returns the total number of bytes required to encode this property in the MQTT wire format, including the property identifier and any length prefixes.

§Examples
use mqtt_protocol_core::mqtt;

let prop = mqtt::packet::Property::MessageExpiryInterval(
    mqtt::packet::MessageExpiryInterval::new(3600).unwrap()
);
let size = prop.size(); // 1 byte ID + 4 bytes value = 5 bytes
Source

pub fn to_buffers(&self) -> Vec<IoSlice<'_>>

Create IoSlice buffers for efficient network I/O

Returns a vector of IoSlice objects that can be used for vectored I/O operations, allowing zero-copy writes to network sockets. The buffers include the property identifier and the encoded property value.

§Examples
use mqtt_protocol_core::mqtt;

let prop = mqtt::packet::Property::ContentType(
    mqtt::packet::ContentType::new("application/json").unwrap()
);
let buffers = prop.to_buffers();
// Can be used with vectored write operations
// socket.write_vectored(&buffers)?;
Source

pub fn parse(bytes: &[u8]) -> Result<(Self, usize), MqttError>

Parse a property from a byte sequence

Decodes a single MQTT property from a byte buffer according to the MQTT v5.0 specification. The buffer must start with a property identifier byte followed by the property value in the appropriate format.

§Parameters
  • bytes - Byte buffer containing the encoded property data
§Returns
  • Ok((Property, bytes_consumed)) - Successfully parsed property and number of bytes consumed
  • Err(MqttError::MalformedPacket) - If the buffer is too short, contains an invalid property ID, or malformed property data
§Examples
use mqtt_protocol_core::mqtt;

// Buffer: [property_id, property_data...]
let buffer = &[0x02, 0x00, 0x00, 0x0E, 0x10]; // MessageExpiryInterval = 3600
let (property, consumed) = mqtt::packet::Property::parse(buffer).unwrap();

match property {
    mqtt::packet::Property::MessageExpiryInterval(prop) => {
        assert_eq!(prop.val(), 3600);
    }
    _ => panic!("Wrong property type"),
}
assert_eq!(consumed, 5);

Trait Implementations§

Source§

impl Clone for Property

Source§

fn clone(&self) -> Property

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Property

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Property

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<AssignedClientIdentifier> for Property

Source§

fn from(v: AssignedClientIdentifier) -> Self

Converts to this type from the input type.
Source§

impl From<AuthenticationData> for Property

Source§

fn from(v: AuthenticationData) -> Self

Converts to this type from the input type.
Source§

impl From<AuthenticationMethod> for Property

Source§

fn from(v: AuthenticationMethod) -> Self

Converts to this type from the input type.
Source§

impl From<ContentType> for Property

Source§

fn from(v: ContentType) -> Self

Converts to this type from the input type.
Source§

impl From<CorrelationData> for Property

Source§

fn from(v: CorrelationData) -> Self

Converts to this type from the input type.
Source§

impl From<MaximumPacketSize> for Property

Source§

fn from(v: MaximumPacketSize) -> Self

Converts to this type from the input type.
Source§

impl From<MaximumQos> for Property

Source§

fn from(v: MaximumQos) -> Self

Converts to this type from the input type.
Source§

impl From<MessageExpiryInterval> for Property

Source§

fn from(v: MessageExpiryInterval) -> Self

Converts to this type from the input type.
Source§

impl From<PayloadFormatIndicator> for Property

Source§

fn from(v: PayloadFormatIndicator) -> Self

Converts to this type from the input type.
Source§

impl From<ReasonString> for Property

Source§

fn from(v: ReasonString) -> Self

Converts to this type from the input type.
Source§

impl From<ReceiveMaximum> for Property

Source§

fn from(v: ReceiveMaximum) -> Self

Converts to this type from the input type.
Source§

impl From<RequestProblemInformation> for Property

Source§

fn from(v: RequestProblemInformation) -> Self

Converts to this type from the input type.
Source§

impl From<RequestResponseInformation> for Property

Source§

fn from(v: RequestResponseInformation) -> Self

Converts to this type from the input type.
Source§

impl From<ResponseInformation> for Property

Source§

fn from(v: ResponseInformation) -> Self

Converts to this type from the input type.
Source§

impl From<ResponseTopic> for Property

Source§

fn from(v: ResponseTopic) -> Self

Converts to this type from the input type.
Source§

impl From<RetainAvailable> for Property

Source§

fn from(v: RetainAvailable) -> Self

Converts to this type from the input type.
Source§

impl From<ServerKeepAlive> for Property

Source§

fn from(v: ServerKeepAlive) -> Self

Converts to this type from the input type.
Source§

impl From<ServerReference> for Property

Source§

fn from(v: ServerReference) -> Self

Converts to this type from the input type.
Source§

impl From<SessionExpiryInterval> for Property

Source§

fn from(v: SessionExpiryInterval) -> Self

Converts to this type from the input type.
Source§

impl From<SharedSubscriptionAvailable> for Property

Source§

fn from(v: SharedSubscriptionAvailable) -> Self

Converts to this type from the input type.
Source§

impl From<SubscriptionIdentifier> for Property

Source§

fn from(v: SubscriptionIdentifier) -> Self

Converts to this type from the input type.
Source§

impl From<SubscriptionIdentifierAvailable> for Property

Source§

fn from(v: SubscriptionIdentifierAvailable) -> Self

Converts to this type from the input type.
Source§

impl From<TopicAlias> for Property

Source§

fn from(v: TopicAlias) -> Self

Converts to this type from the input type.
Source§

impl From<TopicAliasMaximum> for Property

Source§

fn from(v: TopicAliasMaximum) -> Self

Converts to this type from the input type.
Source§

impl From<UserProperty> for Property

Source§

fn from(v: UserProperty) -> Self

Converts to this type from the input type.
Source§

impl From<WildcardSubscriptionAvailable> for Property

Source§

fn from(v: WildcardSubscriptionAvailable) -> Self

Converts to this type from the input type.
Source§

impl From<WillDelayInterval> for Property

Source§

fn from(v: WillDelayInterval) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Property

Source§

fn eq(&self, other: &Property) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PropertyValueAccess for Property

Source§

fn as_u8(&self) -> Option<u8>

Extract u8 value from byte-based properties Read more
Source§

fn as_u16(&self) -> Option<u16>

Extract u16 value from two-byte properties Read more
Source§

fn as_u32(&self) -> Option<u32>

Extract u32 value from four-byte properties Read more
Source§

fn as_str(&self) -> Option<&str>

Extract string value from string-based properties Read more
Source§

fn as_bytes(&self) -> Option<&[u8]>

Extract binary data from binary-based properties Read more
Source§

fn as_key_value(&self) -> Option<(&str, &str)>

Extract key-value pair from UserProperty Read more
Source§

impl Serialize for Property

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Property

Source§

impl StructuralPartialEq for Property

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsConcrete<T> for T

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoConcreteOwned<T> for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more