Skip to main content

Page

Struct Page 

Source
pub struct Page {
    pub footer: Footer,
    pub records: Vec<Vec<u8>>,
    /* private fields */
}
Expand description

A slabtastic page containing a header, records, offset array, and footer.

§Wire layout

[magic:4 "SLAB"][page_size:4][record data ...][offsets:(n+1)*4][footer:16]

The offset array contains (record_count + 1) little-endian u32 values. Each value is a byte position measured from the start of the page, so the first record always starts at offset 8 (after the 8-byte header). The extra sentinel offset marks the end of the last record.

§Examples

use slabtastic::{Page, PageType};

let mut page = Page::new(0, PageType::Data);
page.add_record(b"hello");
page.add_record(b"world");

let bytes = page.serialize();
let decoded = Page::deserialize(&bytes).unwrap();
assert_eq!(decoded.record_count(), 2);
assert_eq!(decoded.get_record(0).unwrap(), b"hello");

Fields§

§footer: Footer

The page footer (metadata).

§records: Vec<Vec<u8>>

The raw record data blobs.

Implementations§

Source§

impl Page

Source

pub fn new(start_ordinal: i64, page_type: PageType) -> Self

Create a new empty page.

Source

pub fn add_record(&mut self, data: &[u8])

Append a record to this page.

Source

pub fn add_record_owned(&mut self, data: Vec<u8>)

Append a record by taking ownership of its bytes — no clone.

Identical to add_record but accepts the record as Vec<u8> rather than &[u8]. Callers that already own the bytes (e.g. predicate-merge phases that just produced the buffer) avoid a full record-sized memcpy per call. On a 10K-predicate × 5 MB-each run this saves ~50 GB of memcpy on the SlabWriter intake side.

Source

pub fn serialized_size(&self) -> usize

Compute the total serialized size of this page.

Source

pub fn serialize(&self) -> Vec<u8>

Serialize this page to a byte vector.

Layout: [magic:4][page_size:4][records...][offsets:(n+1)*4][footer:16]

Source

pub fn deserialize(buf: &[u8]) -> Result<Page>

Deserialize a page from a byte buffer.

Source

pub fn get_record(&self, index: usize) -> Option<&[u8]>

Get a record by its local (zero-based) index.

Source

pub fn record_count(&self) -> usize

Return the number of records in this page.

Source

pub fn start_ordinal(&self) -> i64

Return the starting ordinal for this page.

Source

pub fn record_count_from_buf(buf: &[u8]) -> Result<usize>

Read the record count from a serialized page buffer by inspecting only the footer bytes. No heap allocation.

The record count is stored as a 3-byte unsigned LE integer at footer offset 5–7 (bytes [len-11..len-8] of the page buffer).

§Errors
Source

pub fn get_record_ref_from_buf( buf: &[u8], local_index: usize, record_count: usize, ) -> Result<&[u8]>

Return a borrowed slice of a single record from a serialized page buffer without deserializing the entire page.

Like get_record_from_buf but returns &[u8] instead of Vec<u8>, eliminating the per-record heap allocation. The record_count parameter avoids re-parsing the footer on every call when iterating all records in a page.

Magic validation is intentionally skipped since callers are expected to have obtained the buffer through a validated path.

§Errors
Source

pub fn get_record_from_buf(buf: &[u8], local_index: usize) -> Result<Vec<u8>>

Extract a single record from a serialized page buffer without deserializing the entire page.

This reads only the footer and the two offset entries needed to locate the record at local_index, then copies just that record’s bytes. No Vec<Vec<u8>> allocation for all records and no parsing of all N+1 offsets.

Magic validation is intentionally skipped since callers are expected to have obtained the buffer through a validated path.

Note: SlabReader::get performs targeted I/O directly (reading only geometry + record bytes) rather than buffering the full page. This method is useful when a full page buffer is already in memory for other reasons.

§Errors

Trait Implementations§

Source§

impl Clone for Page

Source§

fn clone(&self) -> Page

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Page

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Page

§

impl RefUnwindSafe for Page

§

impl Send for Page

§

impl Sync for Page

§

impl Unpin for Page

§

impl UnsafeUnpin for Page

§

impl UnwindSafe for Page

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.