Struct JournaledSession
pub struct JournaledSession {
inner: InMemorySession,
buf: Vec<u8>,
}alloc only.Expand description
A SessionState wrapper that serializes every mutation into raw bytes.
The inner InMemorySession is updated immediately so that queries
always reflect the latest state. Operations accumulate as encoded bytes
in an internal buffer until the caller takes them with
take_journal for persistence.
This is a sans-io building block: it knows nothing about files or async.
The I/O layer (e.g. the tokio crate) is responsible for writing the
journal bytes to stable storage and calling replay on
startup.
Fields§
§inner: InMemorySession§buf: Vec<u8>Implementations§
§impl JournaledSession
impl JournaledSession
pub const fn new() -> Self
pub const fn new() -> Self
Creates a new journaled session with an empty in-memory state.
pub const fn from_inner(inner: InMemorySession) -> Self
pub const fn from_inner(inner: InMemorySession) -> Self
Creates a journaled session wrapping an existing in-memory session.
Useful when replaying a journal: first rebuild the InMemorySession,
then wrap it so that future mutations are recorded.
pub fn take_journal(&mut self) -> Vec<u8>
pub fn take_journal(&mut self) -> Vec<u8>
Takes the accumulated journal bytes, leaving the internal buffer empty.
The caller should persist these bytes (e.g. append to a file) before
acknowledging the corresponding protocol events. The bytes can later
be replayed with replay.
pub const fn journal_is_empty(&self) -> bool
pub const fn journal_is_empty(&self) -> bool
Returns true if no journal bytes have accumulated since the last
take_journal.
pub const fn inner(&self) -> &InMemorySession
pub const fn inner(&self) -> &InMemorySession
Borrow the inner in-memory session.
pub const fn inner_mut(&mut self) -> &mut InMemorySession
pub const fn inner_mut(&mut self) -> &mut InMemorySession
Mutably borrow the inner in-memory session.
Mutations made through this reference are not recorded in the journal. Use this only for replay or testing.
pub fn replay(
data: &[u8],
session: &mut impl SessionState,
) -> Result<(), DecodeError>
pub fn replay( data: &[u8], session: &mut impl SessionState, ) -> Result<(), DecodeError>
Replay journal bytes against a SessionState, reproducing the
mutations that were originally recorded.
This is typically called at startup to rebuild session state from a persisted journal file.
§Errors
Returns DecodeError if the journal bytes are malformed.
fn push_id_op(&mut self, tag: u8, packet_id: PacketId)
fn push_id_op(&mut self, tag: u8, packet_id: PacketId)
Appends raw bytes for a packet-id-only operation.
fn push_store_op(
&mut self,
tag: u8,
packet_id: PacketId,
phase: Option<Qos2Phase>,
msg: (&Topic, &[u8], bool, &PublishProperties),
)
fn push_store_op( &mut self, tag: u8, packet_id: PacketId, phase: Option<Qos2Phase>, msg: (&Topic, &[u8], bool, &PublishProperties), )
Appends raw bytes for a store operation (QoS 1 or 2).
Trait Implementations§
§impl Default for JournaledSession
impl Default for JournaledSession
§impl SessionState for JournaledSession
impl SessionState for JournaledSession
§fn store_outgoing_qos1(
&mut self,
packet_id: PacketId,
topic: &Topic,
payload: &[u8],
retain: bool,
properties: &PublishProperties,
)
fn store_outgoing_qos1( &mut self, packet_id: PacketId, topic: &Topic, payload: &[u8], retain: bool, properties: &PublishProperties, )
QoS 1 outbound publish (PUBLISH sent, awaiting PUBACK). Read more§fn remove_outgoing_qos1(&mut self, packet_id: PacketId)
fn remove_outgoing_qos1(&mut self, packet_id: PacketId)
QoS 1 outbound publish after PUBACK is received.§fn store_outgoing_qos2(
&mut self,
packet_id: PacketId,
phase: Qos2Phase,
topic: &Topic,
payload: &[u8],
retain: bool,
properties: &PublishProperties,
)
fn store_outgoing_qos2( &mut self, packet_id: PacketId, phase: Qos2Phase, topic: &Topic, payload: &[u8], retain: bool, properties: &PublishProperties, )
QoS 2 outbound publish. Read more§fn advance_outgoing_qos2(&mut self, packet_id: PacketId)
fn advance_outgoing_qos2(&mut self, packet_id: PacketId)
QoS 2 outbound publish to the PUBREL-sent phase. Read more§fn remove_outgoing_qos2(&mut self, packet_id: PacketId)
fn remove_outgoing_qos2(&mut self, packet_id: PacketId)
QoS 2 outbound publish after PUBCOMP is received (or PUBREC
with rc ≥ 0x80).§fn store_incoming_qos2(&mut self, packet_id: PacketId)
fn store_incoming_qos2(&mut self, packet_id: PacketId)
QoS 2 inbound packet identifier (PUBREC sent, awaiting
PUBREL from the server).§fn remove_incoming_qos2(&mut self, packet_id: PacketId)
fn remove_incoming_qos2(&mut self, packet_id: PacketId)
QoS 2 inbound packet identifier after PUBREL is received
and PUBCOMP has been sent.§fn has_outgoing_qos1(&self, packet_id: PacketId) -> bool
fn has_outgoing_qos1(&self, packet_id: PacketId) -> bool
QoS 1 outbound publish is stored for this packet ID.§fn has_outgoing_qos2(&self, packet_id: PacketId) -> bool
fn has_outgoing_qos2(&self, packet_id: PacketId) -> bool
QoS 2 outbound publish is stored for this packet ID.§fn has_incoming_qos2(&self, packet_id: PacketId) -> bool
fn has_incoming_qos2(&self, packet_id: PacketId) -> bool
QoS 2 inbound packet identifier is stored (i.e.,
PUBREC was already sent for this packet ID).§fn try_for_each_outgoing_qos1<B>(
&self,
f: Qos1Callback<'_, B>,
) -> ControlFlow<B>
fn try_for_each_outgoing_qos1<B>( &self, f: Qos1Callback<'_, B>, ) -> ControlFlow<B>
QoS 1 messages for retransmission
on reconnect. Read more§fn try_for_each_outgoing_qos2<B>(
&self,
f: &mut dyn FnMut(OutgoingQos2<'_>) -> ControlFlow<B>,
) -> ControlFlow<B>
fn try_for_each_outgoing_qos2<B>( &self, f: &mut dyn FnMut(OutgoingQos2<'_>) -> ControlFlow<B>, ) -> ControlFlow<B>
QoS 2 messages for retransmission
on reconnect. Read more§fn try_for_each_incoming_qos2<B>(
&self,
f: &mut dyn FnMut(PacketId) -> ControlFlow<B>,
) -> ControlFlow<B>
fn try_for_each_incoming_qos2<B>( &self, f: &mut dyn FnMut(PacketId) -> ControlFlow<B>, ) -> ControlFlow<B>
QoS 2 packet identifiers for
re-acknowledging on reconnect. Read more