Trait Packet

Source
pub trait Packet<'a> {
    // Required methods
    fn new() -> Self;
    fn encode(
        &mut self,
        buffer: &mut [u8],
        buff_len: usize,
    ) -> Result<usize, BufferError>;
    fn decode(
        &mut self,
        buff_reader: &mut BuffReader<'a>,
    ) -> Result<(), BufferError>;
    fn set_property_len(&mut self, value: u32);
    fn get_property_len(&mut self) -> u32;
    fn push_to_properties(&mut self, property: Property<'a>);
    fn property_allowed(&mut self, property: &Property<'a>) -> bool;
    fn set_fixed_header(&mut self, header: u8);
    fn set_remaining_len(&mut self, remaining_len: u32);

    // Provided methods
    fn add_properties<const MAX_PROPERTIES: usize>(
        &mut self,
        properties: &Vec<Property<'a>, MAX_PROPERTIES>,
    ) -> u32 { ... }
    fn decode_properties(
        &mut self,
        buff_reader: &mut BuffReader<'a>,
    ) -> Result<(), BufferError> { ... }
    fn decode_fixed_header(
        &mut self,
        buff_reader: &mut BuffReader<'_>,
    ) -> Result<PacketType, BufferError> { ... }
}
Expand description

This trait provide interface for mapping MQTTv5 packets to human readable structures which can be later modified and used for communication purposes.

Required Methods§

Source

fn new() -> Self

Source

fn encode( &mut self, buffer: &mut [u8], buff_len: usize, ) -> Result<usize, BufferError>

Method encode provide way how to transfer Packet struct into Byte array (buffer)

Source

fn decode( &mut self, buff_reader: &mut BuffReader<'a>, ) -> Result<(), BufferError>

Decode method is opposite of encode - decoding Byte array and mapping it into corresponding Packet struct

Source

fn set_property_len(&mut self, value: u32)

Setter method for packet properties len - not all Packet types support this

Source

fn get_property_len(&mut self) -> u32

Setter method for packet properties len - not all Packet types support this

Source

fn push_to_properties(&mut self, property: Property<'a>)

Method enables pushing new property into packet properties

Source

fn property_allowed(&mut self, property: &Property<'a>) -> bool

Returns if property is allowed for packet

Source

fn set_fixed_header(&mut self, header: u8)

Setter for packet fixed header

Source

fn set_remaining_len(&mut self, remaining_len: u32)

Setter for remaining len

Provided Methods§

Source

fn add_properties<const MAX_PROPERTIES: usize>( &mut self, properties: &Vec<Property<'a>, MAX_PROPERTIES>, ) -> u32

Method enables adding properties from client config - each packet decides if property can be used with that or not

Source

fn decode_properties( &mut self, buff_reader: &mut BuffReader<'a>, ) -> Result<(), BufferError>

Method is decoding Byte array pointing to properties into heapless Vec in packet. If decoding goes wrong method is returning Error

Source

fn decode_fixed_header( &mut self, buff_reader: &mut BuffReader<'_>, ) -> Result<PacketType, BufferError>

Method is decoding packet header into fixed header part and remaining length

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a> Packet<'a> for PingreqPacket

Source§

impl<'a> Packet<'a> for PingrespPacket

Source§

impl<'a, const MAX_FILTERS: usize, const MAX_PROPERTIES: usize> Packet<'a> for SubscriptionPacket<'a, MAX_FILTERS, MAX_PROPERTIES>

Source§

impl<'a, const MAX_FILTERS: usize, const MAX_PROPERTIES: usize> Packet<'a> for UnsubscriptionPacket<'a, MAX_FILTERS, MAX_PROPERTIES>

Source§

impl<'a, const MAX_PROPERTIES: usize> Packet<'a> for AuthPacket<'a, MAX_PROPERTIES>

Source§

impl<'a, const MAX_PROPERTIES: usize> Packet<'a> for ConnackPacket<'a, MAX_PROPERTIES>

Source§

impl<'a, const MAX_PROPERTIES: usize> Packet<'a> for DisconnectPacket<'a, MAX_PROPERTIES>

Source§

impl<'a, const MAX_PROPERTIES: usize> Packet<'a> for PubackPacket<'a, MAX_PROPERTIES>

Source§

impl<'a, const MAX_PROPERTIES: usize> Packet<'a> for PubcompPacket<'a, MAX_PROPERTIES>

Source§

impl<'a, const MAX_PROPERTIES: usize> Packet<'a> for PublishPacket<'a, MAX_PROPERTIES>

Source§

impl<'a, const MAX_PROPERTIES: usize> Packet<'a> for PubrecPacket<'a, MAX_PROPERTIES>

Source§

impl<'a, const MAX_PROPERTIES: usize> Packet<'a> for PubrelPacket<'a, MAX_PROPERTIES>

Source§

impl<'a, const MAX_PROPERTIES: usize, const MAX_WILL_PROPERTIES: usize> Packet<'a> for ConnectPacket<'a, MAX_PROPERTIES, MAX_WILL_PROPERTIES>

Source§

impl<'a, const MAX_REASONS: usize, const MAX_PROPERTIES: usize> Packet<'a> for SubackPacket<'a, MAX_REASONS, MAX_PROPERTIES>

Source§

impl<'a, const MAX_REASONS: usize, const MAX_PROPERTIES: usize> Packet<'a> for UnsubackPacket<'a, MAX_REASONS, MAX_PROPERTIES>