JournalReader

Struct JournalReader 

pub struct JournalReader {
    state: ReaderState,
    consumed: u64,
    max_frame_len: usize,
}
Available on crate feature 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: usize

Upper 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

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

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

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

Returns true if the reader is positioned exactly on a frame boundary, so EOF here is a clean shutdown (not corruption).

pub const fn demand(&self) -> Demand

Returns what the I/O layer should do next.

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>

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).

fn feed_header(&mut self, chunk: &[u8]) -> Step

fn feed_payload<S: SessionState>( &mut self, chunk: &[u8], length: usize, expected_crc: u32, session: &mut S, ) -> Result<Step, JournalFrameError>

Trait Implementations§

§

impl Default for JournalReader

§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> 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, 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.