Skip to main content

SegmentReader

Struct SegmentReader 

Source
pub struct SegmentReader<'a> { /* private fields */ }
Expand description

Read-side handle. Borrows the segment bytes (the catalog or test owns the buffer), parses header + bloom + page index up front, and exposes lookup(key) / scan_keys() over the rest.

For an in-RAM cold-tier segment that the catalog holds across many lookups, prefer OwnedSegment — it owns its bytes and reuses the same parsed metadata across calls without any lifetime gymnastics.

Implementations§

Source§

impl<'a> SegmentReader<'a>

Source

pub fn open(bytes: &'a [u8]) -> Result<Self, SegmentError>

Parse a segment from a contiguous byte slice. Validates magic, CRC32 footer, and structural lengths. v6.6.2: a v2-magic envelope is rejected by the borrowed-slice reader because decompression would need to allocate a fresh Vec — callers with a v2 file must go through OwnedSegment::from_bytes which can own the decompressed bytes.

Source

pub fn meta(&self) -> &SegmentMeta

Source

pub fn codec_version(&self) -> u8

v7.23/v7.27 — the codec version implied by this segment’s inner magic (0 legacy / 46 / 47). Callers thread this into decode_row_body_dense.

Source

pub fn might_contain(&self, key: u64) -> bool

Bloom-only check — false means the key is definitely not in this segment (no false negatives); true means it might be (false-positive rate per the embedded bloom’s target).

Source

pub fn lookup(&self, key: u64) -> Option<Vec<u8>>

Look up key. Returns Some(payload) if found, None if the bloom rejects or the page-internal search misses. Always reads at most one page worth of bytes (4 KiB by default), which is the I/O budget the v5.1 catalog integration relies on.

Source

pub fn scan(&self) -> impl Iterator<Item = (u64, Vec<u8>)> + '_

Iterate all (key, payload) pairs in sorted order. Used by scan-shaped queries and by compaction.

Trait Implementations§

Source§

impl<'a> Debug for SegmentReader<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for SegmentReader<'a>

§

impl<'a> RefUnwindSafe for SegmentReader<'a>

§

impl<'a> Send for SegmentReader<'a>

§

impl<'a> Sync for SegmentReader<'a>

§

impl<'a> Unpin for SegmentReader<'a>

§

impl<'a> UnsafeUnpin for SegmentReader<'a>

§

impl<'a> UnwindSafe for SegmentReader<'a>

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> 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, 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.