Skip to main content

SaveReader

Struct SaveReader 

Source
pub struct SaveReader<'a> { /* private fields */ }
Expand description

A little-endian binary cursor reader over a borrowed byte slice.

Bounds-checked reads return SaveStateError::Truncated instead of panicking on malformed/corrupt input (external, untrusted data — a save-state file the user can hand-edit or a corrupted disk write) — “validate at boundaries” / “never unwrap on untrusted data” (project-wide house rules, master-core/modules/60-security.md).

Implementations§

Source§

impl<'a> SaveReader<'a>

Source

pub const fn new(buf: &'a [u8]) -> Self

A reader positioned at the start of buf.

Source

pub const fn remaining(&self) -> usize

Bytes remaining unread.

Source

pub fn read_bytes(&mut self, n: usize) -> Result<&'a [u8], SaveStateError>

Read raw bytes verbatim (the counterpart to SaveWriter::write_bytes for a component that embeds another’s already-serialized bytes at a caller-known fixed length).

§Errors

SaveStateError::Truncated if fewer than n bytes remain.

Source

pub fn read_u8(&mut self) -> Result<u8, SaveStateError>

Read one byte.

§Errors

SaveStateError::Truncated if the buffer is exhausted.

Source

pub fn read_bool(&mut self) -> Result<bool, SaveStateError>

Read a bool (any nonzero byte is true, matching how write_bool only ever emits 0/1 but a hand-corrupted file might not — never a hard error for either value).

§Errors

SaveStateError::Truncated if the buffer is exhausted.

Source

pub fn read_u16(&mut self) -> Result<u16, SaveStateError>

Read a little-endian u16.

§Errors

SaveStateError::Truncated if fewer than 2 bytes remain.

Source

pub fn read_u32(&mut self) -> Result<u32, SaveStateError>

Read a little-endian u32.

§Errors

SaveStateError::Truncated if fewer than 4 bytes remain.

Source

pub fn read_u64(&mut self) -> Result<u64, SaveStateError>

Read a little-endian u64.

§Errors

SaveStateError::Truncated if fewer than 8 bytes remain.

Source

pub fn read_len_prefixed(&mut self) -> Result<&'a [u8], SaveStateError>

Read a u32-length-prefixed byte slice (the counterpart to SaveWriter::write_len_prefixed).

§Errors

SaveStateError::Truncated if the declared length exceeds what remains.

Source

pub fn section(&mut self) -> Result<([u8; 4], Self), SaveStateError>

Read a nested section written by SaveWriter::section: consumes its 4-byte tag + u32 length, and returns (tag, sub_reader) scoped to exactly that section’s bytes — reading past the sub-reader’s end fails with SaveStateError::Truncated even if the OUTER buffer has more data, which is what makes an unrecognized/truncated-by-a-bug section fail locally instead of desynchronizing every section after it.

§Errors

SaveStateError::Truncated if the tag/length header or the declared body is truncated.

Source

pub fn expect_section( &mut self, expected: [u8; 4], ) -> Result<Self, SaveStateError>

Self::section, additionally checking the tag matches expected — the common case where the caller knows exactly which section should come next (most of the format is a fixed sequence; only the top-level Board-family dispatch genuinely branches on tag).

§Errors

SaveStateError::Truncated per Self::section, or SaveStateError::UnexpectedTag if the next section’s tag doesn’t match expected.

Trait Implementations§

Source§

impl<'a> Clone for SaveReader<'a>

Source§

fn clone(&self) -> SaveReader<'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
Source§

impl<'a> Debug for SaveReader<'a>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a> Copy for SaveReader<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for SaveReader<'a>

§

impl<'a> RefUnwindSafe for SaveReader<'a>

§

impl<'a> Send for SaveReader<'a>

§

impl<'a> Sync for SaveReader<'a>

§

impl<'a> Unpin for SaveReader<'a>

§

impl<'a> UnsafeUnpin for SaveReader<'a>

§

impl<'a> UnwindSafe for SaveReader<'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.