Struct JournalReader
pub struct JournalReader {
state: ReaderState,
consumed: u64,
max_frame_len: usize,
}alloc only.Expand description
Decodes CRC-framed journal records one frame at a time.
See the module-level documentation for the streaming protocol.
Fields§
§state: ReaderState§consumed: u64§max_frame_len: usizeUpper bound on a single frame’s declared payload length. A header
claiming more is rejected as corruption before the oversized read is
demanded. usize::MAX (the new default) disables the
bound.
Implementations§
§impl JournalReader
impl JournalReader
pub const fn new() -> Self
pub const fn new() -> Self
Creates a fresh reader positioned at the start of a journal, with no bound on frame length.
pub const fn with_max_frame_len(max_frame_len: usize) -> Self
pub const fn with_max_frame_len(max_frame_len: usize) -> Self
Creates a reader that rejects any frame whose declared payload length
exceeds max_frame_len, reporting it as Step::Corrupt before
demanding the oversized read.
A streaming driver should pass the journal’s total byte length: no single frame can legitimately exceed the whole source, so a header claiming more is corruption (a flipped length byte or a crash-truncated tail) and must not be allowed to demand a multi-gigabyte read for a frame that cannot exist. The CRC, which covers the payload, can only be checked after the payload has been read, so this length bound is the only thing standing between a single bad byte and a huge allocation.
pub const fn bytes_consumed(&self) -> u64
pub const fn bytes_consumed(&self) -> u64
Returns the number of bytes successfully decoded and applied to the session.
If the reader reports corruption or the source ends mid-frame, this is the offset at which the source should be truncated.
pub const fn is_frame_boundary(&self) -> bool
pub const fn is_frame_boundary(&self) -> bool
Returns true if the reader is positioned exactly on a frame
boundary, so EOF here is a clean shutdown (not corruption).
pub fn feed<S: SessionState>(
&mut self,
chunk: &[u8],
session: &mut S,
) -> Result<Step, JournalFrameError>
pub fn feed<S: SessionState>( &mut self, chunk: &[u8], session: &mut S, ) -> Result<Step, JournalFrameError>
Feeds a chunk of exactly the size requested by the previous
demand call.
§Errors
Returns JournalFrameError::Decode only if a CRC-validated payload
contains malformed ops (a bug, not crash corruption). All other
problems (size mismatch, CRC mismatch) are reported as
Step::Corrupt so the caller can self-heal by truncating.
pub fn replay_slice<S: SessionState>(
&mut self,
bytes: &[u8],
session: &mut S,
) -> Result<u64, JournalFrameError>
pub fn replay_slice<S: SessionState>( &mut self, bytes: &[u8], session: &mut S, ) -> Result<u64, JournalFrameError>
Drives the reader over an in-memory journal slice, applying every
valid frame to session and stopping at the first truncated or
CRC-mismatched frame.
Returns the number of bytes successfully consumed; everything before that offset is known-good and everything after (if any) is the corrupt or truncated tail.
§Errors
Returns JournalFrameError::Decode only if a CRC-validated frame
contains malformed ops (indicating a bug, not crash corruption).