Struct Packet

Source
pub struct Packet<'a> { /* private fields */ }

Implementations§

Source§

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.

Source

pub fn connect( variable_header: Connect<'a>, payload: Connect<'a>, ) -> Result<Self, EncodeError>

Create a CONNECT packet.

Source

pub fn subscribe( variable_header: PacketIdentifier, payload: Subscribe<'a>, ) -> Result<Self, EncodeError>

Create a SUBSCRIBE packet.

Source

pub fn publish( flags: PublishFlags, variable_header: Publish<'a>, payload: &'a [u8], ) -> Result<Self, EncodeError>

Create a PUBLISH packet.

Source

pub fn puback(variable_header: PacketIdentifier) -> Result<Self, EncodeError>

Source

pub fn pingreq() -> Self

Create a PINGREQ packet.

Source

pub fn pingresp() -> Self

Create a PINGRESP packet.

Source

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.

Source

pub fn variable_header(&self) -> &Option<VariableHeader<'_>>

Return a reference to the variable header of the packet.

Source

pub fn payload(&self) -> &Payload<'_>

Return a reference to the payload of the packet.

Trait Implementations§

Source§

impl<'a> Debug for Packet<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Decodable<'a> for Packet<'a>

Source§

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.

Source§

impl<'a> Encodable for Packet<'a>

Source§

fn encoded_len(&self) -> usize

Calculate the exact length of the fully encoded packet.

The encode buffer will need to hold at least this number of bytes.

Source§

fn encode(&self, bytes: &mut [u8]) -> Result<usize, EncodeError>

Encode a packet for sending over a network connection.

If encoding fails an Err(x) is returned.

If encoding succeeds an Ok(written) is returned with the number of bytes written to the buffer.

Auto Trait Implementations§

§

impl<'a> Freeze for Packet<'a>

§

impl<'a> RefUnwindSafe for Packet<'a>

§

impl<'a> Send for Packet<'a>

§

impl<'a> Sync for Packet<'a>

§

impl<'a> Unpin for Packet<'a>

§

impl<'a> UnwindSafe for Packet<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.