pub struct AprV2ReaderRef<'a> { /* private fields */ }Expand description
APR v2 format reader with zero-copy (borrows data - for mmap)
This reader borrows the data slice instead of copying it, enabling true zero-copy access when used with memory-mapped files.
§Example
use apr_format::v2::AprV2ReaderRef;
let bytes: &[u8] = /* mmap'd slice */;
let reader = AprV2ReaderRef::from_bytes(bytes)?;
let weights = reader.get_f32_tensor("embed_tokens.weight")?;Implementations§
Source§impl<'a> AprV2ReaderRef<'a>
impl<'a> AprV2ReaderRef<'a>
Sourcepub fn from_bytes(data: &'a [u8]) -> Result<Self, V2FormatError>
pub fn from_bytes(data: &'a [u8]) -> Result<Self, V2FormatError>
Read from bytes (zero-copy - borrows data)
Unlike AprV2Reader::from_bytes, this does NOT copy the input data.
The reader borrows the slice, making it ideal for use with mmap.
§Errors
Returns error if parsing fails.
§LAYOUT-002 Jidoka Guard
Rejects APR files with LAYOUT_COLUMN_MAJOR flag set, as these indicate
improperly converted GGUF files that would produce garbage output.
Sourcepub fn header(&self) -> &AprV2Header
pub fn header(&self) -> &AprV2Header
Get header
Sourcepub fn metadata(&self) -> &AprV2Metadata
pub fn metadata(&self) -> &AprV2Metadata
Get metadata
Sourcepub fn tensor_names(&self) -> Vec<&str>
pub fn tensor_names(&self) -> Vec<&str>
Get tensor names
Sourcepub fn get_tensor(&self, name: &str) -> Option<&TensorIndexEntry>
pub fn get_tensor(&self, name: &str) -> Option<&TensorIndexEntry>
Get tensor by name
Sourcepub fn get_tensor_data(&self, name: &str) -> Option<&[u8]>
pub fn get_tensor_data(&self, name: &str) -> Option<&[u8]>
Get tensor data by name (zero-copy slice into mmap)
Sourcepub fn get_f32_tensor(&self, name: &str) -> Option<Vec<f32>>
pub fn get_f32_tensor(&self, name: &str) -> Option<Vec<f32>>
Get tensor as f32 Vec (copies data from mmap to Vec<f32>)
Note: This allocates memory for the f32 values. For very large tensors,
consider using get_tensor_data and processing in chunks.
Sourcepub fn verify_alignment(&self) -> bool
pub fn verify_alignment(&self) -> bool
Check if all tensors are 64-byte aligned
Sourcepub fn tensor_index(&self) -> &[TensorIndexEntry]
pub fn tensor_index(&self) -> &[TensorIndexEntry]
Borrow the parsed tensor index (used by the core dequant extension).