pub struct KeyCodec { /* private fields */ }Expand description
Bit-packed key layout: a small prefix id in the leading reserved bits, payload in the remainder.
For example, with 4 reserved bits the first nibble selects the prefix and the rest of the key carries the encoded logical payload.
Implementations§
Source§impl KeyCodec
impl KeyCodec
Sourcepub const fn new(reserved_bits: u8, prefix: u16) -> Self
pub const fn new(reserved_bits: u8, prefix: u16) -> Self
Build a codec with reserved_bits high bits reserved for prefix.
Sourcepub const fn reserved_bits(self) -> u8
pub const fn reserved_bits(self) -> u8
The number of reserved high bits at the start of the key.
Sourcepub const fn min_key_len(self) -> usize
pub const fn min_key_len(self) -> usize
Minimum key length in bytes needed to store this codec’s reserved bits.
Sourcepub const fn max_payload_capacity_bytes(self) -> usize
pub const fn max_payload_capacity_bytes(self) -> usize
Maximum logical payload bytes that can ever fit under this codec.
Sourcepub const fn payload_capacity_bytes(self) -> usize
pub const fn payload_capacity_bytes(self) -> usize
Maximum logical payload bytes that fit under this codec.
This reflects the global physical key cap rather than a per-key fixed
width. Families that need an exact key length should use
Self::payload_capacity_bytes_for_key_len.
Sourcepub const fn payload_capacity_bytes_for_key_len(self, key_len: usize) -> usize
pub const fn payload_capacity_bytes_for_key_len(self, key_len: usize) -> usize
Maximum logical payload bytes that fit in a key of key_len bytes.
Sourcepub const fn min_key_len_for_payload(self, payload_len: usize) -> usize
pub const fn min_key_len_for_payload(self, payload_len: usize) -> usize
Smallest physical key length that can store payload_len bytes.
Sourcepub const fn payload_bit_offset(self, payload_byte_offset: usize) -> usize
pub const fn payload_bit_offset(self, payload_byte_offset: usize) -> usize
Absolute bit offset for a payload byte offset within the physical key.
Sourcepub fn new_key_with_len(
self,
total_bytes: usize,
) -> Result<KeyMut, KeyCodecError>
pub fn new_key_with_len( self, total_bytes: usize, ) -> Result<KeyMut, KeyCodecError>
Create a zero-filled key buffer with the prefix id written in the reserved bits.
Sourcepub fn encode(self, payload: &[u8]) -> Result<Key, KeyCodecError>
pub fn encode(self, payload: &[u8]) -> Result<Key, KeyCodecError>
Encode an entire logical payload into a physical key.
Sourcepub fn decode(
self,
key: &Key,
payload_len: usize,
) -> Result<Vec<u8>, KeyCodecError>
pub fn decode( self, key: &Key, payload_len: usize, ) -> Result<Vec<u8>, KeyCodecError>
Decode payload_len bytes from a key that belongs to this codec.
Sourcepub fn write_payload(
self,
key: &mut KeyMut,
payload_byte_offset: usize,
bytes: &[u8],
) -> Result<(), KeyCodecError>
pub fn write_payload( self, key: &mut KeyMut, payload_byte_offset: usize, bytes: &[u8], ) -> Result<(), KeyCodecError>
Write logical payload bytes at a byte offset within the shifted payload.
Sourcepub fn fill_payload(
self,
key: &mut KeyMut,
payload_byte_offset: usize,
len: usize,
value: u8,
) -> Result<(), KeyCodecError>
pub fn fill_payload( self, key: &mut KeyMut, payload_byte_offset: usize, len: usize, value: u8, ) -> Result<(), KeyCodecError>
Fill a payload byte range with a repeated byte value.
Sourcepub fn read_payload(
self,
key: &Key,
payload_byte_offset: usize,
len: usize,
) -> Result<Vec<u8>, KeyCodecError>
pub fn read_payload( self, key: &Key, payload_byte_offset: usize, len: usize, ) -> Result<Vec<u8>, KeyCodecError>
Read logical payload bytes at a byte offset within the shifted payload.
Sourcepub fn read_payload_exact<const N: usize>(
self,
key: &Key,
payload_byte_offset: usize,
) -> Result<[u8; N], KeyCodecError>
pub fn read_payload_exact<const N: usize>( self, key: &Key, payload_byte_offset: usize, ) -> Result<[u8; N], KeyCodecError>
Read an exact-size payload slice into an array.
Sourcepub fn copy_payload(
self,
src: &Key,
src_payload_byte_offset: usize,
dst: &mut KeyMut,
dst_payload_byte_offset: usize,
len: usize,
) -> Result<(), KeyCodecError>
pub fn copy_payload( self, src: &Key, src_payload_byte_offset: usize, dst: &mut KeyMut, dst_payload_byte_offset: usize, len: usize, ) -> Result<(), KeyCodecError>
Copy payload bytes from one codec-managed key into another.
Sourcepub fn prefix_bounds_for_len(
self,
total_bytes: usize,
) -> Result<(Key, Key), KeyCodecError>
pub fn prefix_bounds_for_len( self, total_bytes: usize, ) -> Result<(Key, Key), KeyCodecError>
Inclusive lower and upper bounds for keys in this prefix with a fixed byte length.
Sourcepub fn prefix_bounds(self) -> (Key, Key)
pub fn prefix_bounds(self) -> (Key, Key)
Inclusive lower and upper bounds for this prefix across the full supported key-length domain.
Trait Implementations§
impl Copy for KeyCodec
impl Eq for KeyCodec
impl StructuralPartialEq for KeyCodec
Auto Trait Implementations§
impl Freeze for KeyCodec
impl RefUnwindSafe for KeyCodec
impl Send for KeyCodec
impl Sync for KeyCodec
impl Unpin for KeyCodec
impl UnsafeUnpin for KeyCodec
impl UnwindSafe for KeyCodec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.