pub struct SnapshotFsLoader { /* private fields */ }Expand description
A file system backed snapshot loader.
The loader opens a snapshot file and decodes it using the framed binary
format written by SnapshotFsWriter:
- 4 bytes version (currently 4)
- 4 bytes length of payload
- 4 bytes CRC-32 of payload
- JSON-serialized Snapshot
Version checking is performed to ensure compatibility between the writer
and loader. If the snapshot version does not match the expected version,
SnapshotLoaderError::IncompatibleVersion is returned.
If the snapshot file does not exist, load() will return Ok(None)
instead of panicking.
Implementations§
Source§impl SnapshotFsLoader
impl SnapshotFsLoader
Sourcepub fn new(path: PathBuf) -> Self
pub fn new(path: PathBuf) -> Self
Creates a new snapshot loader from the given path.
§Arguments
path- The filesystem path to the snapshot file
Sourcepub fn with_version(path: PathBuf, version: u32) -> Self
pub fn with_version(path: PathBuf, version: u32) -> Self
Creates a new snapshot loader from the given path with a custom version.
This is useful for testing or when the loader needs to support multiple snapshot versions.
§Arguments
path- The filesystem path to the snapshot fileversion- The expected snapshot version
Trait Implementations§
Source§impl SnapshotLoader for SnapshotFsLoader
impl SnapshotLoader for SnapshotFsLoader
Source§fn load(&mut self) -> Result<Option<Snapshot>, SnapshotLoaderError>
fn load(&mut self) -> Result<Option<Snapshot>, SnapshotLoaderError>
Load a snapshot from storage.
The loader reads the version frame, validates it against the expected
version, then reads the length and payload frames. The payload is
decoded from JSON into a Snapshot struct.
If the snapshot file does not exist, returns Ok(None).
§Errors
Returns SnapshotLoaderError::IoError if an I/O error occurs.
Returns SnapshotLoaderError::IncompatibleVersion if the snapshot
version does not match the expected version.
Returns SnapshotLoaderError::DecodeError if the snapshot cannot
be decoded.