Description
As part of the work done to remove support for versionize, we realized that we could improve the API of the snapshot module.
The pattern that would like to follow is as follows:
#[derive(Serialize, Deserialize)]
pub struct SnapshotHeader {
magic: u64,
version: Version
}
impl SnapshotHeader {
fn load<R: Read>(reader: &mut R) -> Result<Self> { ... }
fn store<W: Write>(writer: &mut W) -> Result<Self> { ... }
}
#[derive(Serialize, Deserialize)]
pub struct Snapshot<Data> {
header: SnapshotHeader,
data: Data
}
impl<Data: Deserialize> Snapshot<Data> {
fn load_unchecked<R: Read>(reader: &mut R) -> Result<Self> { ... }
fn load<R: Read>(reader: &mut R) -> Result<Self> { ... }
}
impl<Data: Serialize> Snapshot<Data> {
fn save<W: Write>(&self, writer: &mut W) -> Result<usize> { ... }
fn save_with_crc<W: Write>(&self, writer: &mut W) -> Result<usize> { ... }
}
Checklist:
- Modify the API of the module to fit the above pattern.
- Modify the code of Firecracker making use of the new API.
- All the existing snapshot testing pass.