Skip to main content

CacheCodecImpl

Trait CacheCodecImpl 

Source
pub trait CacheCodecImpl: Send + Sync {
    const TYPE_ID: &'static str;
    const CURRENT_VERSION: u32;
    const SUPPORTS_ROW_SELECTION: bool = false;

    // Required methods
    fn serialize(&self, writer: &mut CacheEntryWriter<'_>) -> Result<()>;
    fn deserialize(reader: &mut CacheEntryReader<'_>) -> Result<Self>
       where Self: Sized;

    // Provided methods
    fn deserialize_rows(
        _reader: &dyn CacheRangeReader,
        _body_offset: usize,
        _version: u32,
        _rows: &[u32],
    ) -> Result<Self>
       where Self: Sized { ... }
    fn plan_row_ranges(
        _reader: &dyn CacheRangeReader,
        _body_offset: usize,
        _version: u32,
        _rows: &[u32],
    ) -> Result<Option<Vec<Range<usize>>>>
       where Self: Sized { ... }
}
Expand description

Serialization trait for cache entries.

Experimental: the serialized format is not yet covered by a stability guarantee and may change between releases. When it does stabilize, the rules are: TYPE_ID, protobuf field numbers, and enum values are append-only forever; format changes that protobuf cannot express transparently bump CURRENT_VERSION.

Implement this on concrete types that need to survive serialization through a persistent cache backend, then wire it into a CacheKey via CacheCodec::from_impl.

The envelope (magic/version/type_id/type_version) is written and validated by the CacheCodec wrapper. serialize writes only the body — a header followed by sections in a fixed, version-keyed order — and deserialize reads them back in that same order. The read sequence mirroring the write sequence for each type_version is the invariant the implementor owns.

Required Associated Constants§

Source

const TYPE_ID: &'static str

Stable identity for this entry type. Must not change once shipped. This is a deliberate author-assigned string, not std::any::type_name (which is not stable across compiler versions).

Source

const CURRENT_VERSION: u32

Body schema version this build writes. Bump when the body layout changes in a way protobuf field additions cannot express transparently (adding/removing/reordering sections, a raw-blob encoding change, etc.).

Provided Associated Constants§

Source

const SUPPORTS_ROW_SELECTION: bool = false

Whether this body supports gathering sorted, unique row offsets.

Required Methods§

Source

fn serialize(&self, writer: &mut CacheEntryWriter<'_>) -> Result<()>

Write the body: a header, then sections in a fixed order.

Source

fn deserialize(reader: &mut CacheEntryReader<'_>) -> Result<Self>
where Self: Sized,

Reconstruct from the body. Branch on reader.version() for backward compat; sections are read in write order.

Provided Methods§

Source

fn deserialize_rows( _reader: &dyn CacheRangeReader, _body_offset: usize, _version: u32, _rows: &[u32], ) -> Result<Self>
where Self: Sized,

Source

fn plan_row_ranges( _reader: &dyn CacheRangeReader, _body_offset: usize, _version: u32, _rows: &[u32], ) -> Result<Option<Vec<Range<usize>>>>
where Self: Sized,

Payload byte ranges that deserialize_rows requests for rows, in request order, excluding the envelope and any body header it reads through reader while planning.

Lets a backend issue those reads concurrently before decoding. The default None means the body cannot plan, and backends read serially.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§