Skip to main content

ExtentCodec

Trait ExtentCodec 

Source
pub trait ExtentCodec:
    Debug
    + Send
    + Sync {
    // Required methods
    fn encode(&self, body: &[u8], out: &mut Vec<u8>);
    fn decode(&self, stored: &[u8], body: &mut [u8]);
}
Available on Unix and crate feature pool only.
Expand description

A chunk-provided transform between a chunk’s body bytes and the stored bytes its extent holds. The pool owns scheduling: spill threads, the residency state machine, cancellation, and the ledger. It invokes the codec on opaque bytes at the extent boundary, encode when backing a chunk (on a spill thread, or inline under overload) and decode when reading an evicted one, under the chunk’s state lock. The pool itself has no opinion on the stored form: framing, compression, and validation all belong to the codec.

Implementations must be pure transforms: no locking, no calls back into the pool (the state lock is held at decode sites), and no panic on bytes their own encode produced. decode must exactly invert encode, and encode’s output must never exceed max_stored_len(body.len()), the bound the extent store’s size classes are provisioned to.

Required Methods§

Source

fn encode(&self, body: &[u8], out: &mut Vec<u8>)

Transforms body into its stored form, replacing out’s contents. out’s capacity is reused across calls; implementations size it themselves.

Source

fn decode(&self, stored: &[u8], body: &mut [u8])

Inverts ExtentCodec::encode: reconstructs into body exactly the bytes whose encoding produced stored. body is exactly the original body’s length, and implementations must panic on a length mismatch rather than truncate or pad.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§