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
impl SaveWriter
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Consume the writer, returning the assembled bytes.
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
The bytes written so far (for a nested writer being spliced into a parent — see
Self::section).
Sourcepub fn write_bytes(&mut self, bytes: &[u8])
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).
Sourcepub fn write_bool(&mut self, v: bool)
pub fn write_bool(&mut self, v: bool)
Write a bool as one byte (0/1).
Sourcepub fn write_len_prefixed(&mut self, bytes: &[u8])
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).
Sourcepub fn section(&mut self, tag: [u8; 4], body: impl FnOnce(&mut Self))
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.