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>
impl<'a> SaveReader<'a>
Sourcepub fn read_bytes(&mut self, n: usize) -> Result<&'a [u8], SaveStateError>
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.
Sourcepub fn read_u8(&mut self) -> Result<u8, SaveStateError>
pub fn read_u8(&mut self) -> Result<u8, SaveStateError>
Sourcepub fn read_bool(&mut self) -> Result<bool, SaveStateError>
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.
Sourcepub fn read_u16(&mut self) -> Result<u16, SaveStateError>
pub fn read_u16(&mut self) -> Result<u16, SaveStateError>
Sourcepub fn read_u32(&mut self) -> Result<u32, SaveStateError>
pub fn read_u32(&mut self) -> Result<u32, SaveStateError>
Sourcepub fn read_u64(&mut self) -> Result<u64, SaveStateError>
pub fn read_u64(&mut self) -> Result<u64, SaveStateError>
Sourcepub fn read_len_prefixed(&mut self) -> Result<&'a [u8], SaveStateError>
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.
Sourcepub fn section(&mut self) -> Result<([u8; 4], Self), SaveStateError>
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.
Sourcepub fn expect_section(
&mut self,
expected: [u8; 4],
) -> Result<Self, SaveStateError>
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>
impl<'a> Clone for SaveReader<'a>
Source§fn clone(&self) -> SaveReader<'a>
fn clone(&self) -> SaveReader<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more