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)
Implementations§
Source§impl Property
impl Property
Sourcepub fn id(&self) -> PropertyId
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);
Sourcepub fn size(&self) -> usize
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
Sourcepub fn to_buffers(&self) -> Vec<IoSlice<'_>>
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)?;
Sourcepub fn parse(bytes: &[u8]) -> Result<(Self, usize), MqttError>
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 consumedErr(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 From<AssignedClientIdentifier> for Property
impl From<AssignedClientIdentifier> for Property
Source§fn from(v: AssignedClientIdentifier) -> Self
fn from(v: AssignedClientIdentifier) -> Self
Source§impl From<AuthenticationData> for Property
impl From<AuthenticationData> for Property
Source§fn from(v: AuthenticationData) -> Self
fn from(v: AuthenticationData) -> Self
Source§impl From<AuthenticationMethod> for Property
impl From<AuthenticationMethod> for Property
Source§fn from(v: AuthenticationMethod) -> Self
fn from(v: AuthenticationMethod) -> Self
Source§impl From<ContentType> for Property
impl From<ContentType> for Property
Source§fn from(v: ContentType) -> Self
fn from(v: ContentType) -> Self
Source§impl From<CorrelationData> for Property
impl From<CorrelationData> for Property
Source§fn from(v: CorrelationData) -> Self
fn from(v: CorrelationData) -> Self
Source§impl From<MaximumPacketSize> for Property
impl From<MaximumPacketSize> for Property
Source§fn from(v: MaximumPacketSize) -> Self
fn from(v: MaximumPacketSize) -> Self
Source§impl From<MaximumQos> for Property
impl From<MaximumQos> for Property
Source§fn from(v: MaximumQos) -> Self
fn from(v: MaximumQos) -> Self
Source§impl From<MessageExpiryInterval> for Property
impl From<MessageExpiryInterval> for Property
Source§fn from(v: MessageExpiryInterval) -> Self
fn from(v: MessageExpiryInterval) -> Self
Source§impl From<PayloadFormatIndicator> for Property
impl From<PayloadFormatIndicator> for Property
Source§fn from(v: PayloadFormatIndicator) -> Self
fn from(v: PayloadFormatIndicator) -> Self
Source§impl From<ReasonString> for Property
impl From<ReasonString> for Property
Source§fn from(v: ReasonString) -> Self
fn from(v: ReasonString) -> Self
Source§impl From<ReceiveMaximum> for Property
impl From<ReceiveMaximum> for Property
Source§fn from(v: ReceiveMaximum) -> Self
fn from(v: ReceiveMaximum) -> Self
Source§impl From<RequestProblemInformation> for Property
impl From<RequestProblemInformation> for Property
Source§fn from(v: RequestProblemInformation) -> Self
fn from(v: RequestProblemInformation) -> Self
Source§impl From<RequestResponseInformation> for Property
impl From<RequestResponseInformation> for Property
Source§fn from(v: RequestResponseInformation) -> Self
fn from(v: RequestResponseInformation) -> Self
Source§impl From<ResponseInformation> for Property
impl From<ResponseInformation> for Property
Source§fn from(v: ResponseInformation) -> Self
fn from(v: ResponseInformation) -> Self
Source§impl From<ResponseTopic> for Property
impl From<ResponseTopic> for Property
Source§fn from(v: ResponseTopic) -> Self
fn from(v: ResponseTopic) -> Self
Source§impl From<RetainAvailable> for Property
impl From<RetainAvailable> for Property
Source§fn from(v: RetainAvailable) -> Self
fn from(v: RetainAvailable) -> Self
Source§impl From<ServerKeepAlive> for Property
impl From<ServerKeepAlive> for Property
Source§fn from(v: ServerKeepAlive) -> Self
fn from(v: ServerKeepAlive) -> Self
Source§impl From<ServerReference> for Property
impl From<ServerReference> for Property
Source§fn from(v: ServerReference) -> Self
fn from(v: ServerReference) -> Self
Source§impl From<SessionExpiryInterval> for Property
impl From<SessionExpiryInterval> for Property
Source§fn from(v: SessionExpiryInterval) -> Self
fn from(v: SessionExpiryInterval) -> Self
Source§fn from(v: SharedSubscriptionAvailable) -> Self
fn from(v: SharedSubscriptionAvailable) -> Self
Source§impl From<SubscriptionIdentifier> for Property
impl From<SubscriptionIdentifier> for Property
Source§fn from(v: SubscriptionIdentifier) -> Self
fn from(v: SubscriptionIdentifier) -> Self
Source§impl From<SubscriptionIdentifierAvailable> for Property
impl From<SubscriptionIdentifierAvailable> for Property
Source§fn from(v: SubscriptionIdentifierAvailable) -> Self
fn from(v: SubscriptionIdentifierAvailable) -> Self
Source§impl From<TopicAlias> for Property
impl From<TopicAlias> for Property
Source§fn from(v: TopicAlias) -> Self
fn from(v: TopicAlias) -> Self
Source§impl From<TopicAliasMaximum> for Property
impl From<TopicAliasMaximum> for Property
Source§fn from(v: TopicAliasMaximum) -> Self
fn from(v: TopicAliasMaximum) -> Self
Source§impl From<UserProperty> for Property
impl From<UserProperty> for Property
Source§fn from(v: UserProperty) -> Self
fn from(v: UserProperty) -> Self
Source§impl From<WildcardSubscriptionAvailable> for Property
impl From<WildcardSubscriptionAvailable> for Property
Source§fn from(v: WildcardSubscriptionAvailable) -> Self
fn from(v: WildcardSubscriptionAvailable) -> Self
Source§impl From<WillDelayInterval> for Property
impl From<WillDelayInterval> for Property
Source§fn from(v: WillDelayInterval) -> Self
fn from(v: WillDelayInterval) -> Self
Source§impl PropertyValueAccess for Property
impl PropertyValueAccess for Property
impl Eq for Property
impl StructuralPartialEq for Property
Auto Trait Implementations§
impl Freeze for Property
impl RefUnwindSafe for Property
impl Send for Property
impl Sync for Property
impl Unpin for Property
impl UnwindSafe for Property
Blanket Implementations§
Source§impl<T> AsConcrete<T> for T
impl<T> AsConcrete<T> for T
fn as_concrete(&self) -> Option<&T>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.