Struct Publish
pub struct Publish<'a> {
pub dup: bool,
pub qos: QoS,
pub retain: bool,
pub topic: Option<&'a Topic>,
pub packet_id: Option<PacketId>,
pub properties: &'a PublishProperties,
pub topic_alias: Option<NonZeroU16>,
pub payload: &'a [u8],
}Expand description
PUBLISH packet carrying an application message.
Fields§
§dup: boolDuplicate delivery flag.
qos: QoSQuality of Service level.
retain: boolRetain flag.
topic: Option<&'a Topic>Topic name. None when resolved via topic alias.
packet_id: Option<PacketId>Packet identifier (present for QoS 1 and 2).
properties: &'a PublishPropertiesPUBLISH properties.
topic_alias: Option<NonZeroU16>Topic Alias (§3.3.2.3.4) to encode alongside
properties.
This is an encode-side convenience for assigning an alias without
allocating a merged property buffer: the encoder appends it as a
TopicAlias property. It is therefore always None after
decode. An inbound alias is reported as part of
properties, so an alias must be set in exactly
one of the two, never both.
payload: &'a [u8]Application message payload.
Implementations§
§impl<'a> Publish<'a>
impl<'a> Publish<'a>
pub const fn flags_byte(&self) -> u8
pub const fn flags_byte(&self) -> u8
Returns the fixed-header flags byte for this PUBLISH.
const fn topic_alias_len(&self) -> usize
const fn topic_alias_len(&self) -> usize
Encoded length of the injected topic-alias property, or 0 if none.
const fn properties_section_len(&self) -> usize
const fn properties_section_len(&self) -> usize
Byte length of the properties section (length prefix + content), including the injected topic-alias property.
pub const fn encoded_len(&self) -> usize
pub const fn encoded_len(&self) -> usize
Returns the encoded size of the variable header + payload in bytes.
pub const fn encode(&self, w: &mut Writer<'_>) -> Result<(), EncodeError>
pub const fn encode(&self, w: &mut Writer<'_>) -> Result<(), EncodeError>
Encodes the PUBLISH variable header + payload into the writer.
§Errors
Returns EncodeError::InsufficientSpace if the writer does not have
enough capacity.
pub const fn decode(flags: u8, r: &mut Reader<'a>) -> Result<Self, DecodeError>
pub const fn decode(flags: u8, r: &mut Reader<'a>) -> Result<Self, DecodeError>
Decodes a PUBLISH packet from the flags byte and reader.
§Errors
Returns DecodeError if the data is malformed, the QoS is invalid,
or properties contain disallowed IDs.