pub struct Snapshot<Data> {
pub header: SnapshotHdr,
pub data: Data,
}Expand description
Outer envelope wrapping a state blob.
Fields§
§header: SnapshotHdrHeader (magic + version).
data: DataWrapped state data.
Implementations§
Source§impl<Data: Serialize> Snapshot<Data>
impl<Data: Serialize> Snapshot<Data>
Sourcepub fn save<W: Write>(&self, writer: &mut W) -> Result<(), SnapshotError>
pub fn save<W: Write>(&self, writer: &mut W) -> Result<(), SnapshotError>
Save self into writer as bitcode(envelope) || crc64-le.
The CRC is computed over the bitcode bytes only (the trailing 8 bytes are
not folded into the checksum) — same shape as upstream Firecracker so a
firecracker --describe-snapshot succeeds.
§Errors
SnapshotError::Bitcode for an encoding failure; SnapshotError::Io
for a writer-side I/O failure.
Source§impl<Data: DeserializeOwned> Snapshot<Data>
impl<Data: DeserializeOwned> Snapshot<Data>
Sourcepub fn load<R: Read>(reader: &mut R) -> Result<Self, SnapshotError>
pub fn load<R: Read>(reader: &mut R) -> Result<Self, SnapshotError>
Load and validate the envelope from a Read.
Validates, in order:
- Size is below the DoS-guard limit.
- Trailing 8-byte CRC matches the body.
- Magic equals the architecture-specific value.
- Major version matches; minor version ≤ ours.
The “load_without_crc_check” variant is exposed for --describe-snapshot
against a possibly-corrupt file: an operator wants to see the version even
if the CRC has been clobbered, so the describe path can downgrade CRC
errors to warnings.
§Errors
SnapshotError::SizeLimitExceeded, SnapshotError::TooShort,
SnapshotError::CrcMismatch, SnapshotError::MagicMismatch,
SnapshotError::VersionMismatch, SnapshotError::Bitcode,
SnapshotError::Io.
Sourcepub fn load_from_slice(buf: &[u8]) -> Result<Self, SnapshotError>
pub fn load_from_slice(buf: &[u8]) -> Result<Self, SnapshotError>
Load + validate from an in-memory slice. The slice must include the trailing 8-byte CRC.
§Errors
Same as Self::load.
Sourcepub fn load_without_crc_check(data_buf: &[u8]) -> Result<Self, SnapshotError>
pub fn load_without_crc_check(data_buf: &[u8]) -> Result<Self, SnapshotError>
Decode the envelope without checking the CRC.
Used by --describe-snapshot to emit a useful diagnostic on a CRC-clobbered
file (the version + magic are still meaningful). Production load paths must
go through Self::load / Self::load_from_slice which validate the CRC
first.
§Errors
SnapshotError::SizeLimitExceeded, SnapshotError::Bitcode,
SnapshotError::MagicMismatch, SnapshotError::VersionMismatch.