Skip to main content

SaveWriter

Struct SaveWriter 

Source
pub struct SaveWriter { /* private fields */ }
Expand description

A growable little-endian binary writer over an in-memory buffer (#![no_std] + alloc, no std::io::Write — every chip crate this feeds is no_std).

Implementations§

Source§

impl SaveWriter

Source

pub const fn new() -> Self

A fresh, empty writer.

Source

pub fn into_bytes(self) -> Vec<u8>

Consume the writer, returning the assembled bytes.

Source

pub fn as_bytes(&self) -> &[u8]

The bytes written so far (for a nested writer being spliced into a parent — see Self::section).

Source

pub fn write_bytes(&mut self, bytes: &[u8])

Append raw bytes verbatim (for a component embedding another’s already-serialized bytes, e.g. a coprocessor’s own sub-engine).

Source

pub fn write_u8(&mut self, v: u8)

Write one byte.

Source

pub fn write_bool(&mut self, v: bool)

Write a bool as one byte (0/1).

Source

pub fn write_u16(&mut self, v: u16)

Write a little-endian u16.

Source

pub fn write_u32(&mut self, v: u32)

Write a little-endian u32.

Source

pub fn write_u64(&mut self, v: u64)

Write a little-endian u64.

Source

pub fn write_len_prefixed(&mut self, bytes: &[u8])

Write a byte slice prefixed with its u32 length (for a variable-length payload, e.g. an SRAM image — distinct from Self::section, which additionally carries a 4-byte tag for forward-compatible skipping; a length-prefixed blob has no tag because its meaning is implied by its fixed position in the caller’s own section).

Source

pub fn section(&mut self, tag: [u8; 4], body: impl FnOnce(&mut Self))

Write a nested, self-describing section: a 4-byte ASCII tag, a u32 byte length, then whatever body writes. tag should be a short, stable, human-legible identifier (e.g. *b"CPU0", *b"BRD1") — stable across releases even if the section’s internal layout changes, since SaveReader::section uses it to skip a section it doesn’t recognize.

body writes directly into this writer’s own buffer (no nested Vec allocation — a save-state gets created and restored repeatedly during rewind/run-ahead, so allocating one throwaway buffer per (possibly nested) section on every such call would add up); the length header is a zero placeholder written up front and patched in place once body returns and the section’s true length is known.

Trait Implementations§

Source§

impl Debug for SaveWriter

Source§

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

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

impl Default for SaveWriter

Source§

fn default() -> SaveWriter

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.