pub struct CacheCodec { /* private fields */ }Expand description
Type-erased codec for serializing and deserializing cache entries.
CacheCodec carries the entry’s stable type_id/version plus plain
function pointers — it is Copy and has no heap allocation. Construct one
via CacheCodec::from_impl for types that implement CacheCodecImpl,
or CacheCodec::new for custom cases (e.g. when the orphan rule prevents
a direct impl).
Implementations§
Source§impl CacheCodec
impl CacheCodec
Sourcepub fn new(
type_id: &'static str,
version: u32,
serialize_body: fn(&Arc<dyn Any + Send + Sync>, &mut CacheEntryWriter<'_>) -> Result<()>,
deserialize_body: fn(&mut CacheEntryReader<'_>) -> Result<Arc<dyn Any + Send + Sync>>,
) -> Self
pub fn new( type_id: &'static str, version: u32, serialize_body: fn(&Arc<dyn Any + Send + Sync>, &mut CacheEntryWriter<'_>) -> Result<()>, deserialize_body: fn(&mut CacheEntryReader<'_>) -> Result<Arc<dyn Any + Send + Sync>>, ) -> Self
Create a CacheCodec from explicit body function pointers.
Prefer from_impl when the value type implements
CacheCodecImpl. Use this for types where a direct impl isn’t
possible (e.g. the orphan rule prevents it). type_id and version
play the same role as the corresponding CacheCodecImpl constants.
Sourcepub fn from_impl<T: CacheCodecImpl + 'static>() -> Self
pub fn from_impl<T: CacheCodecImpl + 'static>() -> Self
Create a CacheCodec from a CacheCodecImpl implementation.
Sourcepub fn with_memory_priority(self, priority: u8) -> Self
pub fn with_memory_priority(self, priority: u8) -> Self
Hint for priority-aware memory tiers. Larger values survive pressure first.
pub fn memory_priority(&self) -> u8
Sourcepub fn with_plane_tag(self, plane: u8) -> Self
pub fn with_plane_tag(self, plane: u8) -> Self
Tag the entry as one plane of a layered index so backends can report per-plane metrics without deriving the plane from an admission priority.
Sourcepub fn plane_tag(&self) -> Option<u8>
pub fn plane_tag(&self) -> Option<u8>
The layered plane this entry belongs to, or None for other entries.
Sourcepub const fn type_id(&self) -> &'static str
pub const fn type_id(&self) -> &'static str
Return the stable entry type identity.
Persistent and tiered backends can use this metadata to route encoded values without retaining a readable logical cache key.
Sourcepub fn serialize(
&self,
value: &Arc<dyn Any + Send + Sync>,
writer: &mut dyn Write,
) -> Result<()>
pub fn serialize( &self, value: &Arc<dyn Any + Send + Sync>, writer: &mut dyn Write, ) -> Result<()>
Serialize value into writer: envelope first, then the body.
pub fn supports_row_selection(&self) -> bool
Sourcepub fn deserialize_rows(
&self,
reader: &dyn CacheRangeReader,
rows: &[u32],
) -> CacheDecode<Arc<dyn Any + Send + Sync>>
pub fn deserialize_rows( &self, reader: &dyn CacheRangeReader, rows: &[u32], ) -> CacheDecode<Arc<dyn Any + Send + Sync>>
Gather rows without loading the complete persistent entry.
Sourcepub fn plan_rows(
&self,
reader: &dyn CacheRangeReader,
rows: &[u32],
) -> Option<Vec<Range<usize>>>
pub fn plan_rows( &self, reader: &dyn CacheRangeReader, rows: &[u32], ) -> Option<Vec<Range<usize>>>
Payload ranges that deserialize_rows would
request for rows, beyond the envelope and body header it reads from
reader here. None when the codec cannot plan, the entry is not
compatible, or the rows are invalid; callers then decode serially,
which reports invalid rows as a miss.
Sourcepub fn deserialize(
&self,
data: &Bytes,
) -> CacheDecode<Arc<dyn Any + Send + Sync>>
pub fn deserialize( &self, data: &Bytes, ) -> CacheDecode<Arc<dyn Any + Send + Sync>>
Deserialize an entry from data.
Never fails: any non-fatal failure to interpret the bytes becomes a
CacheDecode::Miss with the reason why (see CacheMissReason).
Reading from an in-memory Bytes cannot do I/O, so there is no fault
channel — a miss is the only non-Hit outcome.