Skip to main content

SnapshotCodec

Trait SnapshotCodec 

Source
pub trait SnapshotCodec: Send + Sync {
    // Required methods
    fn format(&self) -> u8;
    fn encode(
        &self,
        snapshot: Snapshot<'_>,
        out: &mut Vec<u8>,
    ) -> Result<(), Error>;
    fn decode(&self, record: &[u8]) -> Result<Value, Error>;

    // Provided method
    fn compact(&self) -> bool { ... }
}
Expand description

Snapshots as records: XState’s SystemSnapshot (its JSON, or the runtime’s view of it) to bytes, and bytes back to the JSON a restore reads.

Required Methods§

Source

fn format(&self) -> u8

The first byte of every record this codec writes, which tells its records from other codecs’ (Codecs::decode_snapshot).

Source

fn encode(&self, snapshot: Snapshot<'_>, out: &mut Vec<u8>) -> Result<(), Error>

Appends a record of snapshot to out, starting with SnapshotCodec::format. On an error, part of it may have been written: the caller truncates out.

Source

fn decode(&self, record: &[u8]) -> Result<Value, Error>

Decodes a record this codec wrote (format byte included) to the snapshot’s JSON.

Provided Methods§

Source

fn compact(&self) -> bool

Whether this codec always takes the compact form of a snapshot (one without what a restore rebuilds identically), whatever form a host writes by default.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§