pub struct DefaultBuffer {
pub buffer: Vec<u8>,
pub head: usize,
pub vtables: HashMap<Box<[u8]>, usize, BuildVTableHasher>,
}Expand description
The standard Buffer implementation.
§Fields
buffer— the raw backing allocation. Data grows from the high end toward the low end; bytes belowheadare uninitialized or stale and must never be read.head— index of the first byte of valid data. Always satisfieshead <= buffer.len().vtables— deduplication map from vtable bytes to the slot where that vtable was written. Prevents writing the same vtable multiple times when many table elements share identical schemas (the common case).
Fields§
§buffer: Vec<u8>§head: usize§vtables: HashMap<Box<[u8]>, usize, BuildVTableHasher>Trait Implementations§
Source§impl Buffer for DefaultBuffer
impl Buffer for DefaultBuffer
Source§fn new(initial_size: usize) -> DefaultBuffer
fn new(initial_size: usize) -> DefaultBuffer
Allocate an uninitialized buffer of initial_size bytes.
Uses with_capacity + set_len rather than vec![0; n] — see
the module-level Cook-Mertz discussion for why zero-init is safe
to skip here.
Source§fn grow(&mut self, new_cap: usize)
fn grow(&mut self, new_cap: usize)
Grow the buffer to new_cap bytes, shifting all existing written data
to the right so that slot-based offsets remain valid.
Uses reserve + set_len rather than resize(n, 0) for the same
reason as new: the new bytes in the low region are never read before
being written.
Write vtable to the buffer if not already present, then patch the
4-byte vtable-jump field at the start of the table object.
The vtable jump is a signed 32-bit integer stored at t_pos:
jump = vtable_pos - table_pos (negative when vtable is before table)
Multiple table elements with the same schema share one physical vtable copy, which is why the dedup map is essential for space efficiency.
Source§fn buffer(&self) -> &[u8] ⓘ
fn buffer(&self) -> &[u8] ⓘ
Source§fn buffer_mut(&mut self) -> &mut [u8] ⓘ
fn buffer_mut(&mut self) -> &mut [u8] ⓘ
Source§fn head_mut(&mut self) -> &mut usize
fn head_mut(&mut self) -> &mut usize
*buf.head_mut() -= n.Source§fn clear_vtables(&mut self)
fn clear_vtables(&mut self)
reset.Source§fn load<T>(bytes: &[u8]) -> DefaultBufferwhere
T: Table,
fn load<T>(bytes: &[u8]) -> DefaultBufferwhere
T: Table,
Source§fn reset(&mut self)
fn reset(&mut self)
Source§fn ensure_capacity(&mut self, additional_size: usize)
fn ensure_capacity(&mut self, additional_size: usize)
additional_size bytes are available below head, growing the
buffer if necessary.