Struct Reader
pub struct Reader {
state: ReaderState,
consumed: u64,
max_frame_len: usize,
layout: Layout,
}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 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.
layout: LayoutThe encoding of the ops in the frames.
Implementations§
§impl Reader
impl Reader
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 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 one bad byte and a huge allocation.
pub const fn with_header(self, header: Header) -> Self
pub const fn with_header(self, header: Header) -> Self
Reads the frames of a journal file that starts with header.
Without it, the reader expects frames in the format this crate writes.
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: State>(
&mut self,
chunk: &[u8],
session: &mut S,
) -> Result<Step, FrameError<S::Error>>
pub fn feed<S: State>( &mut self, chunk: &[u8], session: &mut S, ) -> Result<Step, FrameError<S::Error>>
Feeds a chunk of exactly the size requested by the previous
demand call.
§Errors
Returns FrameError::Decode if a CRC-validated payload contains
malformed ops (a bug, not crash corruption), and
FrameError::Session if session has no room for them. 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: State>(
&mut self,
bytes: &[u8],
session: &mut S,
) -> Result<u64, FrameError<S::Error>>
pub fn replay_slice<S: State>( &mut self, bytes: &[u8], session: &mut S, ) -> Result<u64, FrameError<S::Error>>
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 the error of feed.
fn feed_header(&mut self, chunk: &[u8]) -> Step
fn feed_payload<S: State>( &mut self, chunk: &[u8], length: usize, expected_crc: u32, session: &mut S, ) -> Result<Step, FrameError<S::Error>>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Reader
impl RefUnwindSafe for Reader
impl Send for Reader
impl Sync for Reader
impl Unpin for Reader
impl UnsafeUnpin for Reader
impl UnwindSafe for Reader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more