[][src]Struct rumq_client::MqttState

pub struct MqttState {
    pub connection_status: MqttConnectionStatus,
    pub await_pingresp: bool,
    pub last_incoming: Instant,
    pub last_outgoing: Instant,
    pub last_pkid: PacketIdentifier,
    pub outgoing_pub: VecDeque<Publish>,
    pub outgoing_rel: VecDeque<PacketIdentifier>,
    pub incoming_pub: VecDeque<PacketIdentifier>,
}

MqttState saves the state of the mqtt connection. Methods will just modify the state of the object without doing any network operations Methods returns so that n/w methods or n/w eventloop can operate directly. This abstracts the functionality better so that it's easy to switch between synchronous code, tokio (or) async/await

Fields

connection_status: MqttConnectionStatus

Connection status

await_pingresp: bool

Status of last ping

last_incoming: Instant

Last incoming packet time

last_outgoing: Instant

Last outgoing packet time

last_pkid: PacketIdentifier

Packet id of the last outgoing packet

outgoing_pub: VecDeque<Publish>

Outgoing QoS 1, 2 publishes which aren't acked yet

outgoing_rel: VecDeque<PacketIdentifier>

Packet ids of released QoS 2 publishes

incoming_pub: VecDeque<PacketIdentifier>

Packet ids on incoming QoS 2 publishes

Methods

impl MqttState[src]

pub fn new() -> Self[src]

Creates new mqtt state. Same state should be used during a connection for persistent sessions while new state should instantiated for clean sessions

pub fn handle_packet(
    &mut self,
    packet: Packet
) -> Result<(Option<Notification>, Option<Packet>), StateError>
[src]

pub fn handle_request(
    &mut self,
    request: Packet
) -> Result<(Option<Notification>, Option<Packet>), StateError>
[src]

pub fn handle_outgoing_mqtt_packet(
    &mut self,
    packet: Packet
) -> Result<Packet, StateError>
[src]

Consolidates handling of all outgoing mqtt packet logic. Returns a packet which should be put on to the network by the eventloop

pub fn handle_incoming_mqtt_packet(
    &mut self,
    packet: Packet
) -> Result<(Option<Notification>, Option<Packet>), StateError>
[src]

Consolidates handling of all incoming mqtt packets. Returns a Notification which for the user to consume and Packet which for the eventloop to put on the network E.g For incoming QoS1 publish packet, this method returns (Publish, Puback). Publish packet will be forwarded to user and Pubck packet will be written to network

pub fn handle_outgoing_publish(
    &mut self,
    publish: Publish
) -> Result<Packet, StateError>
[src]

Adds next packet identifier to QoS 1 and 2 publish packets and returns it buy wrapping publish in packet

pub fn handle_incoming_puback(
    &mut self,
    pkid: PacketIdentifier
) -> Result<(Option<Notification>, Option<Packet>), StateError>
[src]

Iterates through the list of stored publishes and removes the publish with the matching packet identifier. Removal is now a O(n) operation. This should be usually ok in case of acks due to ack ordering in normal conditions. But in cases where the broker doesn't guarantee the order of acks, the performance won't be optimal

pub fn handle_incoming_suback(
    &mut self,
    suback: Suback
) -> Result<(Option<Notification>, Option<Packet>), StateError>
[src]

pub fn handle_incoming_unsuback(
    &mut self,
    pkid: PacketIdentifier
) -> Result<(Option<Notification>, Option<Packet>), StateError>
[src]

pub fn handle_incoming_pubrec(
    &mut self,
    pkid: PacketIdentifier
) -> Result<(Option<Notification>, Option<Packet>), StateError>
[src]

Iterates through the list of stored publishes and removes the publish with the matching packet identifier. Removal is now a O(n) operation. This should be usually ok in case of acks due to ack ordering in normal conditions. But in cases where the broker doesn't guarantee the order of acks, the performance won't be optimal

pub fn handle_incoming_publish(
    &mut self,
    publish: Publish
) -> Result<(Option<Notification>, Option<Packet>), StateError>
[src]

Results in a publish notification in all the QoS cases. Replys with an ack in case of QoS1 and Replys rec in case of QoS while also storing the message

pub fn handle_outgoing_ping(&mut self) -> Result<Packet, StateError>[src]

check when the last control packet/pingreq packet is received and return the status which tells if keep alive time has exceeded NOTE: status will be checked for zero keepalive times also

pub fn handle_outgoing_connect(&mut self) -> Result<(), StateError>[src]

pub fn handle_incoming_connack(
    &mut self,
    packet: Packet
) -> Result<(), StateError>
[src]

Trait Implementations

impl Clone for MqttState[src]

impl Debug for MqttState[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.