pub struct CacheReader { /* private fields */ }Expand description
Reads events from a binary columnar cache file.
The reader validates magic bytes, version, and CRC on open,
then decodes columns using the ColumnCodec traits
to reconstruct Event structs.
§Example
use bones_core::cache::reader::CacheReader;
let reader = CacheReader::open("path/to/events.bin").unwrap();
println!("cache contains {} events", reader.event_count());
let events = reader.read_all().unwrap();Implementations§
Source§impl CacheReader
impl CacheReader
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self, CacheReaderError>
pub fn open(path: impl AsRef<Path>) -> Result<Self, CacheReaderError>
Open and validate a cache file.
Reads the file into memory, validates the magic bytes, format version, and CRC-64 checksum. Returns an error if any validation step fails.
§Errors
Returns CacheError if the file cannot be read, or if magic,
version, or CRC validation fails.
Sourcepub fn from_bytes(data: Vec<u8>) -> Result<Self, CacheReaderError>
pub fn from_bytes(data: Vec<u8>) -> Result<Self, CacheReaderError>
Create a reader from raw bytes (useful for testing).
§Errors
Returns CacheError if validation fails.
Sourcepub fn event_count(&self) -> usize
pub fn event_count(&self) -> usize
Return the number of events (rows) in the cache file without decoding.
Sourcepub const fn header(&self) -> &CacheHeader
pub const fn header(&self) -> &CacheHeader
Return a reference to the cache header.
Sourcepub fn read_all(&self) -> Result<Vec<Event>, CacheReaderError>
pub fn read_all(&self) -> Result<Vec<Event>, CacheReaderError>
Decode all events from the cache.
Note: The event_hash field will be empty on reconstructed events.
Callers needing hashes must recompute them.
§Errors
Returns CacheReaderError if column decoding fails.
Sourcepub fn read_range(
&self,
start: usize,
count: usize,
) -> Result<Vec<Event>, CacheReaderError>
pub fn read_range( &self, start: usize, count: usize, ) -> Result<Vec<Event>, CacheReaderError>
Decode a range of events from the cache.
Returns events [start .. start + count], clamped to the actual row
count. If start >= event_count(), returns an empty Vec.
Implementation note: The current columnar format requires decoding all rows and then slicing. A future optimisation could add per-column offset tables for truly random access.
§Errors
Returns CacheReaderError if column decoding fails.
Sourcepub const fn created_at_us(&self) -> u64
pub const fn created_at_us(&self) -> u64
Return the creation timestamp of the cache file (µs since epoch).
Sourcepub const fn data_crc64(&self) -> u64
pub const fn data_crc64(&self) -> u64
Return the stored CRC-64 checksum of the column data.
Trait Implementations§
Source§impl Clone for CacheReader
impl Clone for CacheReader
Source§fn clone(&self) -> CacheReader
fn clone(&self) -> CacheReader
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more