Skip to main content

Crate rustysnes_savestate

Crate rustysnes_savestate 

Source
Expand description

rustysnes-savestate — the shared save-state wire-format primitives (savestate).

A leaf crate in the one-directional chip-crate graph (see docs/architecture.md): every chip crate (rustysnes-cpu/-ppu/-apu/-cart) and rustysnes-core depend on this for a single, versioned binary format, per docs/adr/0006-save-state-format.md. No dependents among the chip crates — this only ever gets DEPENDED ON, keeping the graph acyclic.

Deliberately no serde/reflection: every Board/Cpu/Ppu/Apu implementation writes an explicit save_state/load_state pair using the primitives here (ADR 0006’s “no derive magic” decision — keeps #![no_std] targets byte-identical to native and keeps each component’s on-disk format change local + auditable, matching this project’s existing style for the Board trait itself).

§Format

This crate defines the section framing a save-state’s payload is built from — a full save-state additionally has a top-level header (magic bytes + format version + crate-version string, ADR 0006) that rustysnes-core::System::save_state/load_state writes/checks before ever touching a section; that envelope is out of scope here (see SaveStateError::BadMagic/ SaveStateError::UnsupportedVersion, which exist for that caller to use).

A section is tagged and length-prefixed — a 4-byte ASCII tag, a u32 little-endian byte length, then that many bytes of section-defined content. Wrapping a component’s state as one such section (via SaveWriter::section / SaveReader::section) is what lets a newer format skip a section it doesn’t recognize (a bumped-version load) rather than corrupting the rest of the load, and lets a struct that changed its own internal layout stay self-describing without a central schema registry.

Structs§

SaveReader
A little-endian binary cursor reader over a borrowed byte slice.
SaveWriter
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).

Enums§

SaveStateError
Errors from decoding a save-state.