pub struct PublishPacket {
pub topic_name: String,
pub packet_id: Option<u16>,
pub payload: Vec<u8>,
pub qos: QoS,
pub retain: bool,
pub dup: bool,
pub properties: Properties,
pub protocol_version: u8,
}Expand description
MQTT PUBLISH packet
Fields§
§topic_name: StringTopic name
packet_id: Option<u16>Packet identifier (required for QoS > 0)
payload: Vec<u8>Message payload
qos: QoSQuality of Service level
retain: boolRetain flag
dup: boolDuplicate delivery flag
properties: PropertiesPUBLISH properties (v5.0 only)
protocol_version: u8Protocol version (4 = v3.1.1, 5 = v5.0)
Implementations§
Source§impl PublishPacket
impl PublishPacket
Sourcepub fn new(
topic_name: impl Into<String>,
payload: impl Into<Vec<u8>>,
qos: QoS,
) -> Self
pub fn new( topic_name: impl Into<String>, payload: impl Into<Vec<u8>>, qos: QoS, ) -> Self
Creates a new PUBLISH packet (v5.0)
Sourcepub fn new_v311(
topic_name: impl Into<String>,
payload: impl Into<Vec<u8>>,
qos: QoS,
) -> Self
pub fn new_v311( topic_name: impl Into<String>, payload: impl Into<Vec<u8>>, qos: QoS, ) -> Self
Creates a new PUBLISH packet for v3.1.1
Sourcepub fn with_packet_id(self, id: u16) -> Self
pub fn with_packet_id(self, id: u16) -> Self
Sets the packet identifier
Sourcepub fn with_retain(self, retain: bool) -> Self
pub fn with_retain(self, retain: bool) -> Self
Sets the retain flag
Sourcepub fn with_payload_format_indicator(self, is_utf8: bool) -> Self
pub fn with_payload_format_indicator(self, is_utf8: bool) -> Self
Sets the payload format indicator
Sourcepub fn with_message_expiry_interval(self, seconds: u32) -> Self
pub fn with_message_expiry_interval(self, seconds: u32) -> Self
Sets the message expiry interval
Sourcepub fn with_topic_alias(self, alias: u16) -> Self
pub fn with_topic_alias(self, alias: u16) -> Self
Sets the topic alias
Sourcepub fn with_response_topic(self, topic: String) -> Self
pub fn with_response_topic(self, topic: String) -> Self
Sets the response topic
Sourcepub fn with_correlation_data(self, data: Vec<u8>) -> Self
pub fn with_correlation_data(self, data: Vec<u8>) -> Self
Sets the correlation data
Sourcepub fn with_user_property(self, key: String, value: String) -> Self
pub fn with_user_property(self, key: String, value: String) -> Self
Adds a user property
Sourcepub fn with_subscription_identifier(self, id: u32) -> Self
pub fn with_subscription_identifier(self, id: u32) -> Self
Adds a subscription identifier
Sourcepub fn with_content_type(self, content_type: String) -> Self
pub fn with_content_type(self, content_type: String) -> Self
Sets the content type
Sourcepub fn topic_alias(&self) -> Option<u16>
pub fn topic_alias(&self) -> Option<u16>
Gets the topic alias from properties
Sourcepub fn message_expiry_interval(&self) -> Option<u32>
pub fn message_expiry_interval(&self) -> Option<u32>
Gets the message expiry interval from properties
Source§impl PublishPacket
impl PublishPacket
Sourcepub fn decode_body_with_version<B: Buf>(
buf: &mut B,
fixed_header: &FixedHeader,
protocol_version: u8,
) -> Result<Self>
pub fn decode_body_with_version<B: Buf>( buf: &mut B, fixed_header: &FixedHeader, protocol_version: u8, ) -> Result<Self>
Trait Implementations§
Source§impl Clone for PublishPacket
impl Clone for PublishPacket
Source§fn clone(&self) -> PublishPacket
fn clone(&self) -> PublishPacket
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PublishPacket
impl Debug for PublishPacket
Source§impl From<PublishPacket> for Message
impl From<PublishPacket> for Message
Source§fn from(packet: PublishPacket) -> Self
fn from(packet: PublishPacket) -> Self
Converts to this type from the input type.
Source§impl MqttPacket for PublishPacket
impl MqttPacket for PublishPacket
Source§fn packet_type(&self) -> PacketType
fn packet_type(&self) -> PacketType
Returns the packet type
Source§fn encode_body<B: BufMut>(&self, buf: &mut B) -> Result<()>
fn encode_body<B: BufMut>(&self, buf: &mut B) -> Result<()>
Encodes the packet body (without fixed header) Read more
Source§fn decode_body<B: Buf>(buf: &mut B, fixed_header: &FixedHeader) -> Result<Self>
fn decode_body<B: Buf>(buf: &mut B, fixed_header: &FixedHeader) -> Result<Self>
Decodes the packet body (without fixed header) Read more
Auto Trait Implementations§
impl Freeze for PublishPacket
impl RefUnwindSafe for PublishPacket
impl Send for PublishPacket
impl Sync for PublishPacket
impl Unpin for PublishPacket
impl UnwindSafe for PublishPacket
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
Mutably borrows from an owned value. Read more