pub struct SnapshotWriter { /* private fields */ }Expand description
Builds a snapshot file from section dumps.
use plugmem_core::snapshot::{Snapshot, SnapshotWriter};
let mut w = SnapshotWriter::new();
w.section(7, b"payload".to_vec()).unwrap();
let bytes = w.finish(b"config-bytes", 0, 1_700_000_000_000, "0.1.0");
let snap = Snapshot::parse(&bytes).unwrap();
assert_eq!(snap.config(), b"config-bytes");
assert_eq!(snap.section(7), Some(&b"payload"[..]));
assert_eq!(snap.section(8), None);Implementations§
Source§impl SnapshotWriter
impl SnapshotWriter
Sourcepub fn section(&mut self, kind: u16, bytes: Vec<u8>) -> Result<(), Error>
pub fn section(&mut self, kind: u16, bytes: Vec<u8>) -> Result<(), Error>
Adds one section. Kinds must be unique within a file.
§Errors
Error::Corrupt when kind was already added (a composition
bug surfaced as a typed error rather than a corrupt file).
Sourcepub fn finish(
self,
config: &[u8],
flags: u16,
created_at: u64,
engine_ver: &str,
) -> Vec<u8> ⓘ
pub fn finish( self, config: &[u8], flags: u16, created_at: u64, engine_ver: &str, ) -> Vec<u8> ⓘ
Assembles the final file: header, config block, table, aligned sections, checksums. Deterministic — identical inputs produce identical bytes.
engine_ver is informational; its first 24 UTF-8 bytes are stored
(callers pass an ASCII semver in practice).
Trait Implementations§
Source§impl Debug for SnapshotWriter
impl Debug for SnapshotWriter
Source§impl Default for SnapshotWriter
impl Default for SnapshotWriter
Source§fn default() -> SnapshotWriter
fn default() -> SnapshotWriter
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for SnapshotWriter
impl RefUnwindSafe for SnapshotWriter
impl Send for SnapshotWriter
impl Sync for SnapshotWriter
impl Unpin for SnapshotWriter
impl UnsafeUnpin for SnapshotWriter
impl UnwindSafe for SnapshotWriter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more