pub struct Packet<'a> { /* private fields */ }
Implementations§
Source§impl<'a> Packet<'a>
A full MQTT packet with fixed header, variable header and payload.
impl<'a> Packet<'a>
A full MQTT packet with fixed header, variable header and payload.
Variable header and payload are optional for some packet types.
Sourcepub fn connect(
variable_header: Connect<'a>,
payload: Connect<'a>,
) -> Result<Self, EncodeError>
pub fn connect( variable_header: Connect<'a>, payload: Connect<'a>, ) -> Result<Self, EncodeError>
Create a CONNECT packet.
Sourcepub fn subscribe(
variable_header: PacketIdentifier,
payload: Subscribe<'a>,
) -> Result<Self, EncodeError>
pub fn subscribe( variable_header: PacketIdentifier, payload: Subscribe<'a>, ) -> Result<Self, EncodeError>
Create a SUBSCRIBE packet.
Sourcepub fn publish(
flags: PublishFlags,
variable_header: Publish<'a>,
payload: &'a [u8],
) -> Result<Self, EncodeError>
pub fn publish( flags: PublishFlags, variable_header: Publish<'a>, payload: &'a [u8], ) -> Result<Self, EncodeError>
Create a PUBLISH packet.
pub fn puback(variable_header: PacketIdentifier) -> Result<Self, EncodeError>
Sourcepub fn fixed_header(&self) -> &FixedHeader
pub fn fixed_header(&self) -> &FixedHeader
Return a reference to the fixed header of the packet.
The len field of the returned header will be valid.
Sourcepub fn variable_header(&self) -> &Option<VariableHeader<'_>>
pub fn variable_header(&self) -> &Option<VariableHeader<'_>>
Return a reference to the variable header of the packet.
Trait Implementations§
Source§impl<'a> Decodable<'a> for Packet<'a>
impl<'a> Decodable<'a> for Packet<'a>
Source§fn decode(bytes: &'a [u8]) -> Result<Status<(usize, Self)>, DecodeError>
fn decode(bytes: &'a [u8]) -> Result<Status<(usize, Self)>, DecodeError>
Decode any MQTT packet from a pre-allocated buffer.
If an unrecoverable error occurs an Err(x)
is returned, the caller should
disconnect and network connection and discard the contents of the connection
receive buffer.
Decoding may return an Ok(Status::Partial(x))
in which case the caller
should buffer at most x
more bytes and then attempt decoding again.
If decoding succeeds an Ok(Status::Complete(x))
will be returned
containing the number of bytes read from the buffer and the decoded packet.
The lifetime of the decoded packet is tied to the input buffer.