Skip to main content

SnapshotWriter

Struct SnapshotWriter 

Source
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

Source

pub fn new() -> Self

An empty writer.

Source

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).

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SnapshotWriter

Source§

fn default() -> SnapshotWriter

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.