pub struct GenericPublish<PacketIdType>where
PacketIdType: IsPacketId,{
pub props: Properties,
/* private fields */
}
Expand description
MQTT 5.0 PUBLISH packet representation
The PUBLISH packet is used to transport application messages from a client to the server or from the server to a client. It is the primary packet type for delivering messages in MQTT and supports Quality of Service (QoS) levels 0, 1, and 2.
According to MQTT 5.0 specification, the PUBLISH packet contains:
- Fixed header with packet type, flags (DUP, QoS, RETAIN), and remaining length
- Variable header with topic name, packet identifier (for QoS > 0), and properties
- Payload containing the application message data
§Fixed Header Flags
The PUBLISH packet uses the following fixed header flags:
- Bit 0: RETAIN flag - if set, the server retains the message for future subscribers
- Bits 1-2: QoS level (0, 1, or 2) - determines delivery guarantee
- Bit 3: DUP flag - indicates this is a duplicate message (QoS > 0 only)
- Bits 4-7: Packet type (0011 for PUBLISH)
§Quality of Service (QoS)
- QoS 0: At most once delivery - fire and forget, no packet identifier required
- QoS 1: At least once delivery - requires packet identifier and PUBACK response
- QoS 2: Exactly once delivery - requires packet identifier and PUBREC/PUBREL/PUBCOMP sequence
§Topic Names and Topic Aliases
MQTT 5.0 introduces Topic Aliases to reduce packet size for frequently used topics. The topic name can be replaced with a numeric alias after the first use, allowing for more efficient transmission of messages on the same topic.
§Properties
MQTT 5.0 PUBLISH packets can include various properties:
- Payload Format Indicator - indicates if payload is UTF-8 text or binary
- Message Expiry Interval - message expiration time in seconds
- Topic Alias - numeric alias for the topic name
- Response Topic - topic for response messages
- Correlation Data - correlation data for request/response flows
- User Properties - custom key-value pairs
- Subscription Identifier - identifier matching subscription (server to client only)
- Content Type - MIME type of the payload
§Generic Type Parameter
The PacketIdType
generic parameter allows using packet identifiers larger than
the standard u16, which can be useful for broker clusters to avoid packet ID
exhaustion when extending the MQTT protocol.
§Examples
use mqtt_protocol_core::mqtt;
use mqtt_protocol_core::mqtt::packet::qos::Qos;
// Create a simple QoS 0 PUBLISH message
let publish = mqtt::packet::v5_0::Publish::builder()
.topic_name("sensor/temperature")
.unwrap()
.qos(Qos::AtMostOnce)
.payload(b"23.5")
.build()
.unwrap();
assert_eq!(publish.topic_name(), "sensor/temperature");
assert_eq!(publish.qos(), Qos::AtMostOnce);
assert_eq!(publish.payload().as_slice(), b"23.5");
assert!(!publish.retain());
assert!(!publish.dup());
assert_eq!(publish.packet_id(), None);
// Create a QoS 1 PUBLISH message with retain flag
let publish = mqtt::packet::v5_0::Publish::builder()
.topic_name("device/status")
.unwrap()
.qos(Qos::AtLeastOnce)
.packet_id(123)
.retain(true)
.payload(b"online")
.build()
.unwrap();
assert_eq!(publish.qos(), Qos::AtLeastOnce);
assert!(publish.retain());
assert_eq!(publish.packet_id(), Some(123));
// Serialize to bytes for network transmission
let buffers = publish.to_buffers();
let total_size = publish.size();
Fields§
§props: Properties
Implementations§
Source§impl<PacketIdType> GenericPublish<PacketIdType>where
PacketIdType: IsPacketId,
impl<PacketIdType> GenericPublish<PacketIdType>where
PacketIdType: IsPacketId,
pub fn props(&self) -> &Properties
Source§impl<PacketIdType> GenericPublish<PacketIdType>where
PacketIdType: IsPacketId,
impl<PacketIdType> GenericPublish<PacketIdType>where
PacketIdType: IsPacketId,
pub fn topic_name_extracted(&self) -> bool
Source§impl<PacketIdType> GenericPublish<PacketIdType>where
PacketIdType: IsPacketId,
impl<PacketIdType> GenericPublish<PacketIdType>where
PacketIdType: IsPacketId,
Sourcepub fn builder() -> GenericPublishBuilder<PacketIdType>
pub fn builder() -> GenericPublishBuilder<PacketIdType>
Creates a new builder for constructing a PUBLISH packet
The builder pattern allows for flexible construction of PUBLISH packets with various combinations of properties, QoS levels, and content.
§Returns
A GenericPublishBuilder
instance with default values
§Examples
use mqtt_protocol_core::mqtt;
use mqtt_protocol_core::mqtt::packet::qos::Qos;
let publish = mqtt::packet::v5_0::Publish::builder()
.topic_name("sensors/temperature")
.unwrap()
.qos(Qos::AtLeastOnce)
.packet_id(1)
.retain(true)
.payload(b"25.3")
.build()
.unwrap();
Sourcepub fn packet_type() -> PacketType
pub fn packet_type() -> PacketType
Returns the packet type for PUBLISH packets
This is always PacketType::Publish
for PUBLISH packet instances.
§Returns
PacketType::Publish
§Examples
use mqtt_protocol_core::mqtt;
use mqtt_protocol_core::mqtt::packet::packet_type::PacketType;
assert_eq!(mqtt::packet::v5_0::Publish::packet_type(), PacketType::Publish);
Sourcepub fn packet_id(&self) -> Option<PacketIdType>
pub fn packet_id(&self) -> Option<PacketIdType>
Returns the packet identifier if present
The packet identifier is only present for QoS 1 and QoS 2 PUBLISH packets.
For QoS 0 packets, this method returns None
.
§Returns
Some(PacketIdType)
- The packet identifier for QoS > 0 packetsNone
- For QoS 0 packets
§Examples
use mqtt_protocol_core::mqtt;
use mqtt_protocol_core::mqtt::packet::qos::Qos;
// QoS 0 packet has no packet ID
let qos0_publish = mqtt::packet::v5_0::Publish::builder()
.topic_name("topic")
.unwrap()
.qos(Qos::AtMostOnce)
.build()
.unwrap();
assert_eq!(qos0_publish.packet_id(), None);
// QoS 1 packet has packet ID
let qos1_publish = mqtt::packet::v5_0::Publish::builder()
.topic_name("topic")
.unwrap()
.qos(Qos::AtLeastOnce)
.packet_id(42)
.build()
.unwrap();
assert_eq!(qos1_publish.packet_id(), Some(42));
Sourcepub fn qos(&self) -> Qos
pub fn qos(&self) -> Qos
Returns the Quality of Service level for this PUBLISH packet
The QoS level determines the delivery guarantee for the message:
- QoS 0: At most once delivery (fire and forget)
- QoS 1: At least once delivery (acknowledged)
- QoS 2: Exactly once delivery (assured)
§Returns
The Qos
level extracted from the fixed header flags
§Examples
use mqtt_protocol_core::mqtt;
use mqtt_protocol_core::mqtt::packet::qos::Qos;
let publish = mqtt::packet::v5_0::Publish::builder()
.topic_name("topic")
.unwrap()
.qos(Qos::ExactlyOnce)
.packet_id(1)
.build()
.unwrap();
assert_eq!(publish.qos(), Qos::ExactlyOnce);
Sourcepub fn dup(&self) -> bool
pub fn dup(&self) -> bool
Returns the DUP (duplicate) flag status
The DUP flag indicates whether this PUBLISH packet is a duplicate of an earlier packet that may not have been acknowledged. This flag is only meaningful for QoS 1 and QoS 2 packets and should be ignored for QoS 0 packets.
§Returns
true
if this is a duplicate packetfalse
if this is the first transmission attempt
§Examples
use mqtt_protocol_core::mqtt;
use mqtt_protocol_core::mqtt::packet::qos::Qos;
let publish = mqtt::packet::v5_0::Publish::builder()
.topic_name("topic")
.unwrap()
.qos(Qos::AtLeastOnce)
.packet_id(1)
.dup(true)
.build()
.unwrap();
assert!(publish.dup());
Sourcepub fn retain(&self) -> bool
pub fn retain(&self) -> bool
Returns the RETAIN flag status
The RETAIN flag indicates whether the server should retain this message for future subscribers to the topic. When a client subscribes to a topic with a retained message, it will immediately receive the retained message.
§Returns
true
if the message should be retained by the serverfalse
if the message should not be retained
§Examples
use mqtt_protocol_core::mqtt;
use mqtt_protocol_core::mqtt::packet::qos::Qos;
let publish = mqtt::packet::v5_0::Publish::builder()
.topic_name("device/status")
.unwrap()
.qos(Qos::AtMostOnce)
.retain(true)
.payload(b"online")
.build()
.unwrap();
assert!(publish.retain());
Sourcepub fn set_dup(self, dup: bool) -> Self
pub fn set_dup(self, dup: bool) -> Self
Sets the DUP (duplicate) flag and returns the modified packet
This method is typically used when retransmitting a QoS 1 or QoS 2 PUBLISH packet that may not have been acknowledged. The DUP flag helps the receiver identify potential duplicate messages.
§Parameters
dup
: Whether to set the DUP flag (true
) or clear it (false
)
§Returns
The modified GenericPublish
instance with the DUP flag updated
§Examples
use mqtt_protocol_core::mqtt;
use mqtt_protocol_core::mqtt::packet::qos::Qos;
let publish = mqtt::packet::v5_0::Publish::builder()
.topic_name("topic")
.unwrap()
.qos(Qos::AtLeastOnce)
.packet_id(1)
.build()
.unwrap();
assert!(!publish.dup());
let dup_publish = publish.set_dup(true);
assert!(dup_publish.dup());
Sourcepub fn topic_name(&self) -> &str
pub fn topic_name(&self) -> &str
Returns the topic name for this PUBLISH packet
The topic name identifies the information channel to which the payload is published. In MQTT 5.0, the topic name may be empty if a TopicAlias property is used instead.
§Returns
A string slice containing the topic name
§Examples
use mqtt_protocol_core::mqtt;
let publish = mqtt::packet::v5_0::Publish::builder()
.topic_name("sensors/temperature/room1")
.unwrap()
.build()
.unwrap();
assert_eq!(publish.topic_name(), "sensors/temperature/room1");
Sourcepub fn payload(&self) -> &ArcPayload
pub fn payload(&self) -> &ArcPayload
Returns a reference to the payload data
The payload contains the application message data being published. It can be any binary data up to the maximum message size allowed by the MQTT implementation.
§Returns
A reference to the ArcPayload
containing the message data
§Examples
use mqtt_protocol_core::mqtt;
let message_data = b"Hello, MQTT World!";
let publish = mqtt::packet::v5_0::Publish::builder()
.topic_name("greetings")
.unwrap()
.payload(message_data)
.build()
.unwrap();
assert_eq!(publish.payload().as_slice(), message_data);
assert_eq!(publish.payload().len(), message_data.len());
Sourcepub fn remove_topic_alias_add_topic(
self,
topic: String,
) -> Result<Self, MqttError>
pub fn remove_topic_alias_add_topic( self, topic: String, ) -> Result<Self, MqttError>
Remove TopicAlias property and add topic name
This method is used for store regulation - it sets the topic name and removes any TopicAlias property from the packet properties. This is typically done when storing messages where the topic alias needs to be resolved to the actual topic name for persistence.
The method validates that the current topic name is empty (as expected when using topic aliases) and that the new topic name doesn’t contain wildcard characters, which are not allowed in PUBLISH packets.
§Parameters
topic
: The topic name to set, replacing any topic alias
§Returns
Ok(Self)
- The modified packet with topic name set and topic alias removedErr(MqttError)
- If the topic name is invalid or the packet state is incorrect
§Errors
MqttError::TopicNameInvalid
- If the current topic name is not emptyMqttError::MalformedPacket
- If the topic contains wildcard characters
§Examples
use mqtt_protocol_core::mqtt;
// Assume we have a publish packet with a topic alias
let publish_with_alias = // ... created with topic alias
let publish_with_topic = publish_with_alias
.remove_topic_alias_add_topic("sensors/temperature".to_string())
.unwrap();
assert_eq!(publish_with_topic.topic_name(), "sensors/temperature");
// Topic alias property has been removed from properties
Sourcepub fn remove_topic_alias(self) -> Self
pub fn remove_topic_alias(self) -> Self
Remove TopicAlias property
This method removes any TopicAlias property from the packet properties while keeping the topic name unchanged. This is useful when you want to send a packet with the full topic name instead of using a topic alias, or when converting packets for systems that don’t support topic aliases.
The method automatically recalculates the property_length and remaining_length to reflect the removal of the TopicAlias property.
§Returns
The modified GenericPublish
instance with TopicAlias property removed
§Examples
use mqtt_protocol_core::mqtt;
// Assume we have a publish packet with both topic name and topic alias
let publish_with_alias = // ... created with topic alias
let publish_without_alias = publish_with_alias.remove_topic_alias();
// Topic name remains the same, but TopicAlias property is removed
assert_eq!(publish_without_alias.topic_name(), "sensors/temperature");
// props() no longer contains TopicAlias property
Sourcepub fn add_extracted_topic_name(self, topic: &str) -> Result<Self, MqttError>
pub fn add_extracted_topic_name(self, topic: &str) -> Result<Self, MqttError>
Add extracted topic name for TopicAlias resolution
This method is used during packet reception to restore topic names from TopicAlias mappings. It’s typically called by connection handling code when a PUBLISH packet is received with a TopicAlias property but no topic name.
The method requires the current topic name to be empty (as expected when receiving a packet with only a topic alias) and validates that the resolved topic name doesn’t contain wildcard characters. It keeps the TopicAlias property intact and marks the topic name as extracted.
§Parameters
topic
: The resolved topic name from the topic alias mapping
§Returns
Ok(Self)
- The modified packet with topic name set and extraction flag markedErr(MqttError)
- If the topic name is invalid or the packet state is incorrect
§Errors
MqttError::TopicNameInvalid
- If the current topic name is not emptyMqttError::MalformedPacket
- If the topic contains wildcard characters
§Examples
use mqtt_protocol_core::mqtt;
// Assume we received a packet with topic alias but no topic name
let publish_with_alias_only = // ... received packet
let publish_with_extracted_topic = publish_with_alias_only
.add_extracted_topic_name("sensors/temperature".to_string())
.unwrap();
assert_eq!(publish_with_extracted_topic.topic_name(), "sensors/temperature");
assert!(publish_with_extracted_topic.topic_name_extracted());
Sourcepub fn remove_topic_add_topic_alias(self, topic_alias: u16) -> Self
pub fn remove_topic_add_topic_alias(self, topic_alias: u16) -> Self
Remove topic name and add TopicAlias property
This method replaces the topic name with a TopicAlias property, setting the topic name to an empty string and adding the TopicAlias property to the packet properties. This is useful for reducing packet size when sending multiple messages to the same topic.
The method removes any existing TopicAlias property before adding the new one to ensure only one TopicAlias property exists. It automatically recalculates the property_length and remaining_length to reflect these changes.
§Parameters
topic_alias
: The numeric topic alias to use instead of the topic name
§Returns
The modified GenericPublish
instance with empty topic name and TopicAlias property
§Examples
use mqtt_protocol_core::mqtt;
let publish_with_topic = mqtt::packet::v5_0::Publish::builder()
.topic_name("sensors/temperature/room1")
.unwrap()
.payload(b"23.5")
.build()
.unwrap();
let publish_with_alias = publish_with_topic.remove_topic_add_topic_alias(42);
assert_eq!(publish_with_alias.topic_name(), "");
// props() now contains TopicAlias property with value 42
Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Returns the total size of the PUBLISH packet in bytes
This includes the fixed header, variable header, and payload. The size calculation accounts for:
- Fixed header (1 byte)
- Remaining length field (1-4 bytes)
- All variable header and payload data
§Returns
The total packet size in bytes
§Examples
use mqtt_protocol_core::mqtt;
let publish = mqtt::packet::v5_0::Publish::builder()
.topic_name("test")
.unwrap()
.payload(b"hello")
.build()
.unwrap();
let packet_size = publish.size();
println!("PUBLISH packet size: {} bytes", packet_size);
Sourcepub fn to_buffers(&self) -> Vec<IoSlice<'_>>
pub fn to_buffers(&self) -> Vec<IoSlice<'_>>
Converts the PUBLISH packet to a vector of I/O slices for efficient transmission
This method creates a vector of IoSlice
references that can be used with
vectored I/O operations (like write_vectored
) for efficient network transmission
without copying the packet data.
The buffers are arranged in the correct MQTT packet order:
- Fixed header
- Remaining length
- Topic name
- Packet identifier (if QoS > 0)
- Property length
- Properties
- Payload
§Returns
A vector of IoSlice
references representing the complete packet
§Examples
use mqtt_protocol_core::mqtt;
use std::io::Write;
let publish = mqtt::packet::v5_0::Publish::builder()
.topic_name("test/topic")
.unwrap()
.payload(b"test payload")
.build()
.unwrap();
let buffers = publish.to_buffers();
// Use with vectored I/O: stream.write_vectored(&buffers)
Sourcepub fn to_continuous_buffer(&self) -> Vec<u8> ⓘ
pub fn to_continuous_buffer(&self) -> Vec<u8> ⓘ
Create a continuous buffer containing the complete packet data
Returns a vector containing all packet bytes in a single continuous buffer.
This method is compatible with no-std environments and provides an alternative
to to_buffers()
when vectored I/O is not needed.
The returned buffer contains the complete PUBLISH packet serialized according to the MQTT v5.0 protocol specification, including fixed header, remaining length, topic name, packet identifier, properties, and payload.
§Returns
A vector containing the complete packet data
§Examples
use mqtt_protocol_core::mqtt;
let publish = mqtt::packet::v5_0::Publish::builder()
.topic_name("sensors/temperature")
.qos(mqtt::qos::QualityOfService::AtLeastOnce)
.packet_id(1u16)
.payload(b"23.5")
.build()
.unwrap();
let buffer = publish.to_continuous_buffer();
// buffer contains all packet bytes
Sourcepub fn parse(flags: u8, data_arc: Arc<[u8]>) -> Result<(Self, usize), MqttError>
pub fn parse(flags: u8, data_arc: Arc<[u8]>) -> Result<(Self, usize), MqttError>
Parses a PUBLISH packet from raw bytes
This method deserializes PUBLISH packet data from a byte buffer, validating the packet structure and extracting all components including topic name, packet identifier, properties, and payload.
The parsing process:
- Validates QoS flags (QoS 3 is invalid)
- Extracts topic name
- Extracts packet identifier (if QoS > 0)
- Parses properties (if present)
- Extracts payload (remaining bytes)
- Validates property constraints
§Parameters
flags
: The fixed header flags byte containing QoS, DUP, and RETAIN flagsdata_arc
: Shared reference to the packet data bytes
§Returns
Ok((GenericPublish, usize))
- The parsed packet and total bytes consumedErr(MqttError)
- If the packet is malformed or invalid
§Errors
MqttError::MalformedPacket
- If QoS is 3, insufficient data, or invalid structureMqttError::ProtocolError
- If properties are invalid for PUBLISH packets
§Examples
use mqtt_protocol_core::mqtt;
use alloc::sync::Arc;
let packet_data: Arc<[u8]> = // ... raw packet bytes
let flags = 0x00; // QoS 0, no DUP, no RETAIN
match mqtt::packet::v5_0::Publish::parse(flags, packet_data) {
Ok((publish, consumed)) => {
println!("Parsed PUBLISH: topic={}, payload_len={}",
publish.topic_name(), publish.payload().len());
}
Err(e) => println!("Parse error: {:?}", e),
}
Trait Implementations§
Source§impl<PacketIdType> Clone for GenericPublish<PacketIdType>
impl<PacketIdType> Clone for GenericPublish<PacketIdType>
Source§fn clone(&self) -> GenericPublish<PacketIdType>
fn clone(&self) -> GenericPublish<PacketIdType>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<PacketIdType> Debug for GenericPublish<PacketIdType>where
PacketIdType: IsPacketId + Serialize,
Debug trait implementation for PUBLISH packets
impl<PacketIdType> Debug for GenericPublish<PacketIdType>where
PacketIdType: IsPacketId + Serialize,
Debug trait implementation for PUBLISH packets
Uses the same JSON representation as Display for consistent debugging output.
Source§impl<PacketIdType> Display for GenericPublish<PacketIdType>where
PacketIdType: IsPacketId + Serialize,
Display trait implementation for PUBLISH packets
impl<PacketIdType> Display for GenericPublish<PacketIdType>where
PacketIdType: IsPacketId + Serialize,
Display trait implementation for PUBLISH packets
Provides human-readable JSON string representation of PUBLISH packets using the Serialize implementation.
Source§impl<PacketIdType> From<GenericPublish<PacketIdType>> for GenericPacket<PacketIdType>where
PacketIdType: IsPacketId + Serialize,
impl<PacketIdType> From<GenericPublish<PacketIdType>> for GenericPacket<PacketIdType>where
PacketIdType: IsPacketId + Serialize,
Source§fn from(v: GenericPublish<PacketIdType>) -> GenericPacket<PacketIdType>
fn from(v: GenericPublish<PacketIdType>) -> GenericPacket<PacketIdType>
Source§impl<PacketIdType> GenericPacketDisplay for GenericPublish<PacketIdType>where
PacketIdType: IsPacketId + Serialize,
Generic packet display trait implementation for PUBLISH packets
impl<PacketIdType> GenericPacketDisplay for GenericPublish<PacketIdType>where
PacketIdType: IsPacketId + Serialize,
Generic packet display trait implementation for PUBLISH packets
Provides the display interface used by the generic packet handling system.
Source§impl<PacketIdType> GenericPacketTrait for GenericPublish<PacketIdType>where
PacketIdType: IsPacketId,
Generic packet trait implementation for PUBLISH packets
impl<PacketIdType> GenericPacketTrait for GenericPublish<PacketIdType>where
PacketIdType: IsPacketId,
Generic packet trait implementation for PUBLISH packets
Provides the common packet interface used by the MQTT protocol implementation for size calculation and buffer generation.
Source§fn size(&self) -> usize
fn size(&self) -> usize
Returns the total packet size in bytes
Delegates to the packet’s own size method.
§Returns
Total packet size including all headers and payload
Source§impl<PacketIdType> PacketKind for GenericPublish<PacketIdType>where
PacketIdType: IsPacketId,
impl<PacketIdType> PacketKind for GenericPublish<PacketIdType>where
PacketIdType: IsPacketId,
Source§const IS_PUBLISH: bool = true
const IS_PUBLISH: bool = true
true
if this is a PUBLISH packetSource§const IS_CONNECT: bool = false
const IS_CONNECT: bool = false
true
if this is a CONNECT packetSource§const IS_CONNACK: bool = false
const IS_CONNACK: bool = false
true
if this is a CONNACK packetSource§const IS_PUBCOMP: bool = false
const IS_PUBCOMP: bool = false
true
if this is a PUBCOMP packetSource§const IS_SUBSCRIBE: bool = false
const IS_SUBSCRIBE: bool = false
true
if this is a SUBSCRIBE packetSource§const IS_UNSUBSCRIBE: bool = false
const IS_UNSUBSCRIBE: bool = false
true
if this is an UNSUBSCRIBE packetSource§const IS_UNSUBACK: bool = false
const IS_UNSUBACK: bool = false
true
if this is an UNSUBACK packetSource§const IS_PINGREQ: bool = false
const IS_PINGREQ: bool = false
true
if this is a PINGREQ packetSource§const IS_PINGRESP: bool = false
const IS_PINGRESP: bool = false
true
if this is a PINGRESP packetSource§const IS_DISCONNECT: bool = false
const IS_DISCONNECT: bool = false
true
if this is a DISCONNECT packetSource§impl<PacketIdType> PartialEq for GenericPublish<PacketIdType>
impl<PacketIdType> PartialEq for GenericPublish<PacketIdType>
Source§fn eq(&self, other: &GenericPublish<PacketIdType>) -> bool
fn eq(&self, other: &GenericPublish<PacketIdType>) -> bool
self
and other
values to be equal, and is used by ==
.Source§impl<PacketIdType> Serialize for GenericPublish<PacketIdType>where
PacketIdType: IsPacketId + Serialize,
Serde serialization implementation for PUBLISH packets
impl<PacketIdType> Serialize for GenericPublish<PacketIdType>where
PacketIdType: IsPacketId + Serialize,
Serde serialization implementation for PUBLISH packets
Provides JSON serialization support for PUBLISH packets, converting all packet fields to a structured JSON representation. Binary payload data is handled appropriately with escape sequences when necessary.
Source§fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
Serializes the PUBLISH packet to the given serializer
Creates a structured representation including packet type, topic name, QoS level, flags, packet identifier, properties, and payload data. Binary payload data is escaped appropriately for JSON representation.
§Parameters
serializer
: The serde serializer to write to
§Returns
Serializer result containing the serialized packet data
Source§impl<PacketIdType> TryFrom<GenericPublish<PacketIdType>> for GenericStorePacket<PacketIdType>where
PacketIdType: IsPacketId + Serialize,
impl<PacketIdType> TryFrom<GenericPublish<PacketIdType>> for GenericStorePacket<PacketIdType>where
PacketIdType: IsPacketId + Serialize,
Source§impl<PacketIdType> TryInto<GenericPublish<PacketIdType>> for GenericPacket<PacketIdType>where
PacketIdType: IsPacketId + Serialize,
impl<PacketIdType> TryInto<GenericPublish<PacketIdType>> for GenericPacket<PacketIdType>where
PacketIdType: IsPacketId + Serialize,
impl<PacketIdType> Eq for GenericPublish<PacketIdType>
impl<PacketIdType> SendableRole<Any> for GenericPublish<PacketIdType>where
PacketIdType: IsPacketId,
impl<PacketIdType> SendableRole<Client> for GenericPublish<PacketIdType>where
PacketIdType: IsPacketId,
impl<PacketIdType> SendableRole<Server> for GenericPublish<PacketIdType>where
PacketIdType: IsPacketId,
impl<PacketIdType> StructuralPartialEq for GenericPublish<PacketIdType>where
PacketIdType: IsPacketId,
Auto Trait Implementations§
impl<PacketIdType> Freeze for GenericPublish<PacketIdType>
impl<PacketIdType> RefUnwindSafe for GenericPublish<PacketIdType>
impl<PacketIdType> Send for GenericPublish<PacketIdType>
impl<PacketIdType> Sync for GenericPublish<PacketIdType>
impl<PacketIdType> Unpin for GenericPublish<PacketIdType>
impl<PacketIdType> UnwindSafe for GenericPublish<PacketIdType>
Blanket Implementations§
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.