SessionOp

Enum SessionOp 

pub enum SessionOp<'a> {
    StoreOutbox {
        packet_id: PacketId,
        qos: QoS,
        topic: &'a Topic,
        payload: &'a [u8],
        retain: bool,
        properties: &'a PublishProperties,
    },
    RemoveOutbox {
        packet_id: PacketId,
    },
    MarkSent {
        packet_id: PacketId,
    },
    StorePubrelPending {
        packet_id: PacketId,
    },
    RemovePubrelPending {
        packet_id: PacketId,
    },
    StoreIncomingQos2 {
        packet_id: PacketId,
    },
    RemoveIncomingQos2 {
        packet_id: PacketId,
    },
    Clear,
    StoreFilter {
        filter: &'a TopicFilter,
        state: FilterState,
    },
    RemoveFilter {
        filter: &'a TopicFilter,
    },
}
Expand description

A single mutation to session state, in a form that can be serialized and replayed.

Passed to super::SessionState::apply to mutate the session. A persistence backend can also match on it to map each operation onto its own representation (e.g. SQL statements), the same way Property is matched.

The store_* / remove_* constructors build the variants and are handy at call sites; the wire op code is an encoding detail derived from the variant.

Variants§

§

StoreOutbox

Store (or replace) an outgoing publish in the outbox.

Fields

§packet_id: PacketId

Packet identifier of the publish.

§qos: QoS

Delivery quality of service (QoS 1 or 2).

§topic: &'a Topic

Publish topic.

§payload: &'a [u8]

Publish payload.

§retain: bool

Whether the publish carries the RETAIN flag.

§properties: &'a PublishProperties

v5 publish properties.

§

RemoveOutbox

Remove an outgoing publish from the outbox.

Fields

§packet_id: PacketId

Packet identifier of the publish to remove.

§

MarkSent

Mark a stored outgoing publish as having been written to the wire, so a post-restart retransmit carries DUP=1 as required by MQTT §3.3.1.1 [MQTT-3.3.1-1].

Fields

§packet_id: PacketId

Packet identifier of the publish.

§

StorePubrelPending

Store a QoS 2 entry directly in the awaiting-PUBCOMP (pubrel-pending) state.

Fields

§packet_id: PacketId

Packet identifier of the entry.

§

RemovePubrelPending

Remove a QoS 2 entry from the pubrel-pending set.

Fields

§packet_id: PacketId

Packet identifier of the entry.

§

StoreIncomingQos2

Store an incoming QoS 2 publish in the awaiting-PUBREL state.

Fields

§packet_id: PacketId

Packet identifier of the incoming publish.

§

RemoveIncomingQos2

Remove an incoming QoS 2 publish.

Fields

§packet_id: PacketId

Packet identifier of the incoming publish.

§

Clear

Clear all in-flight state. Confirmed subscriptions are preserved.

§

StoreFilter

Store (or replace) a filter entry verbatim. Persists the per-filter subscription model: a confirmed subscription, an in-flight SUBSCRIBE, or an in-flight UNSUBSCRIBE. The state carries the subscription options and identifier where they apply.

Fields

§filter: &'a TopicFilter

Topic filter.

§state: FilterState

Lifecycle state, including options and subscription id where they apply.

§

RemoveFilter

Remove a filter entry.

Fields

§filter: &'a TopicFilter

Topic filter to remove.

Implementations§

§

impl<'a> SessionOp<'a>

pub const fn store_outbox(packet_id: PacketId, entry: &OutboxEntry<'a>) -> Self

Creates an operation to store an outgoing publish from an OutboxEntry, preserving its QoS.

pub const fn remove_outbox(packet_id: PacketId) -> Self

Creates an operation to remove an outgoing publish from the outbox.

Removal is keyed by packet id alone; the entry’s QoS is irrelevant.

pub const fn store_qos2_pubcomp(packet_id: PacketId) -> Self

Creates an operation to store a QoS 2 entry directly in the awaiting-PUBCOMP state.

pub const fn remove_pubrel(packet_id: PacketId) -> Self

Creates an operation to remove a QoS 2 entry from the awaiting-PUBCOMP phase (pubrel-pending set).

pub const fn store_incoming_qos2(packet_id: PacketId) -> Self

Creates an operation to store an incoming QoS 2 publish in the “awaiting PUBREC” phase.

pub const fn remove_incoming_qos2(packet_id: PacketId) -> Self

Creates an operation to remove an incoming QoS 2 publish.

pub const fn clear() -> Self

Creates an operation to clear all in-flight session state.

pub const fn store_filter(filter: &'a TopicFilter, state: FilterState) -> Self

Creates an operation to store (or replace) a filter entry verbatim.

pub const fn remove_filter(filter: &'a TopicFilter) -> Self

Creates an operation to remove a filter entry.

pub const fn mark_sent(packet_id: PacketId) -> Self

Creates an operation that marks a pending QoS 1 or QoS 2 publish as having been written to the wire at least once.

Journaling this ensures that, after a process restart, retransmissions carry DUP=1 as required by MQTT §3.3.1.1 [MQTT-3.3.1-1].

const fn op_code(&self) -> u8

Returns the op code byte for this operation.

pub const fn encoded_len(&self) -> usize

Returns the total length of the encoded operation.

pub fn encode_to_vec(&self, buf: &mut Vec<u8>)

Available on crate feature alloc only.

Encodes this operation into the provided buffer.

pub const fn encode(&self, w: &mut Writer<'_>) -> Result<(), EncodeError>

Encodes this operation into the provided writer.

§Errors

Returns EncodeError::InsufficientSpace if the writer does not have enough remaining capacity.

pub fn decode(r: &mut Reader<'a>) -> Result<Self, OpDecodeError>

Decodes an operation from the provided reader.

§Errors

Returns OpDecodeError if the reader contains invalid data.

Trait Implementations§

§

impl<'a> Clone for SessionOp<'a>

§

fn clone(&self) -> SessionOp<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<'a> Debug for SessionOp<'a>

§

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

Formats the value using the given formatter. Read more
§

impl<'a> Copy for SessionOp<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for SessionOp<'a>

§

impl<'a> RefUnwindSafe for SessionOp<'a>

§

impl<'a> Send for SessionOp<'a>

§

impl<'a> Sync for SessionOp<'a>

§

impl<'a> Unpin for SessionOp<'a>

§

impl<'a> UnwindSafe for SessionOp<'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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.