Skip to main content

CacheCodec

Trait CacheCodec 

Source
pub trait CacheCodec:
    Send
    + Sync
    + Clone
    + 'static {
    const CODEC_ID: u8 = envelope::CODEC_USER;

    // Required methods
    fn encode(&self, entry: &CacheEntry) -> Result<Vec<u8>, CacheError>;
    fn decode(&self, bytes: &[u8]) -> Result<CacheEntry, CacheError>;
}
Expand description

Trait representing a serialization strategy for cached entries.

The payload produced by encode is stored inside the envelope, which supplies the timing metadata. Implementations therefore only need to round-trip the entry itself.

Provided Associated Constants§

Source

const CODEC_ID: u8 = envelope::CODEC_USER

Identifies this codec in byte 4 of the envelope header.

Entries are only decoded by a codec whose CODEC_ID matches the byte recorded when they were written; a mismatch is reported as a miss rather than decoded with the wrong codec.

0x00..=0x7F is reserved for this crate (0x01 is PostcardCodec). 0x80..=0xFF is free for downstream codecs, and the default value is envelope::CODEC_USER (0x80).

Required Methods§

Source

fn encode(&self, entry: &CacheEntry) -> Result<Vec<u8>, CacheError>

Source

fn decode(&self, bytes: &[u8]) -> Result<CacheEntry, CacheError>

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl CacheCodec for PostcardCodec

Source§

const CODEC_ID: u8 = envelope::CODEC_POSTCARD