pub struct Publish { /* private fields */ }Expand description
Represents an MQTT v5 Publish packet
This is the primary structure for message publication in MQTT, supporting:
- All QoS levels (0, 1, and 2)
- Retained messages
- Duplicate delivery detection
- Extensive message properties (v5 only)
§Example
use bytes::Bytes;
use mqute_codec::protocol::{Flags, QoS};
use mqute_codec::protocol::v5::{Publish, PublishProperties};
// Create a QoS 1 message with properties
let properties = PublishProperties {
content_type: Some("text/plain".into()),
..Default::default()
};
let publish = Publish::new(
"test/topic",
1234,
Some(properties.clone()),
Bytes::from("message payload"),
Flags::new(QoS::AtLeastOnce)
);
assert_eq!(publish.flags(), Flags::new(QoS::AtLeastOnce));
assert_eq!(publish.packet_id(), Some(1234u16));
assert_eq!(publish.properties(), Some(properties));Implementations§
Source§impl Publish
impl Publish
Sourcepub fn new<T: Into<String>>(
topic: T,
packet_id: u16,
properties: Option<PublishProperties>,
payload: Bytes,
flags: Flags,
) -> Self
pub fn new<T: Into<String>>( topic: T, packet_id: u16, properties: Option<PublishProperties>, payload: Bytes, flags: Flags, ) -> Self
Creates a new Publish packet
§Panics
Panics if:
- QoS > 0 but packet_id is 0.
- The topic name is invalid according to MQTT topic naming rules.
Sourcepub fn properties(&self) -> Option<PublishProperties>
pub fn properties(&self) -> Option<PublishProperties>
Returns a copy of the properties (if any)
Trait Implementations§
impl Eq for Publish
impl Publish for Publish
impl StructuralPartialEq for Publish
Auto Trait Implementations§
impl !Freeze for Publish
impl RefUnwindSafe for Publish
impl Send for Publish
impl Sync for Publish
impl Unpin for Publish
impl UnwindSafe for Publish
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Encoded for Twhere
T: Encode,
impl<T> Encoded for Twhere
T: Encode,
Source§fn encoded_len(&self) -> usize
fn encoded_len(&self) -> usize
Calculates the total encoded length of the packet. Read more