ZTensorReader

Struct ZTensorReader 

Source
pub struct ZTensorReader<R: Read + Seek> {
    pub reader: R,
    pub manifest: Manifest,
}
Expand description

Reader for zTensor v1.1 files.

Fields§

§reader: R§manifest: Manifest

Implementations§

Source§

impl ZTensorReader<BufReader<File>>

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self, ZTensorError>

Opens a zTensor file from path.

Source§

impl ZTensorReader<Cursor<Mmap>>

Source

pub fn open_mmap(path: impl AsRef<Path>) -> Result<Self, ZTensorError>

Opens a zTensor file using memory mapping.

Source

pub fn get_object_slice(&self, name: &str) -> Result<&[u8], ZTensorError>

Gets a zero-copy reference to an object’s data.

This is only available for:

  • Memory-mapped readers
  • Dense objects
  • Raw encoding (not compressed)
Source

pub fn get_object_slice_as<T: Pod>( &self, name: &str, ) -> Result<&[T], ZTensorError>

Gets a typed zero-copy reference to an object’s data.

Source§

impl<R: Read + Seek> ZTensorReader<R>

Source

pub fn new(reader: R) -> Result<Self, ZTensorError>

Creates a new reader and parses the manifest.

Parsing algorithm per spec §4:

  1. Read Footer: EOF - 16
  2. Verify Magic: last 8 bytes == ZTEN1000
  3. Read Size: first 8 bytes as u64 LE
  4. Safety Check: abort if > 1GB
  5. Read Manifest: EOF - 16 - manifest_size
  6. Decode CBOR
Source

pub fn list_objects(&self) -> &BTreeMap<String, Object>

Lists all objects in the file.

Source

pub fn get_object(&self, name: &str) -> Option<&Object>

Gets metadata for an object by name.

Source

pub fn read_component( &mut self, component: &Component, ) -> Result<Vec<u8>, ZTensorError>

Reads raw component data.

Source

pub fn read_object( &mut self, name: &str, verify_checksum: bool, ) -> Result<Vec<u8>, ZTensorError>

Reads raw byte data of a dense object.

Source

pub fn read_objects( &mut self, names: &[&str], verify_checksum: bool, ) -> Result<Vec<Vec<u8>>, ZTensorError>

Reads multiple objects in batch.

Source

pub fn read_object_as<T: Pod>( &mut self, name: &str, ) -> Result<Vec<T>, ZTensorError>

Reads object data as a typed vector.

Source

pub fn read_coo_object<T: Pod>( &mut self, name: &str, ) -> Result<CooTensor<T>, ZTensorError>

Reads a COO sparse object.

Source

pub fn read_csr_object<T: Pod>( &mut self, name: &str, ) -> Result<CsrTensor<T>, ZTensorError>

Reads a CSR sparse object.

Auto Trait Implementations§

§

impl<R> Freeze for ZTensorReader<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for ZTensorReader<R>
where R: RefUnwindSafe,

§

impl<R> Send for ZTensorReader<R>
where R: Send,

§

impl<R> Sync for ZTensorReader<R>
where R: Sync,

§

impl<R> Unpin for ZTensorReader<R>
where R: Unpin,

§

impl<R> UnwindSafe for ZTensorReader<R>
where R: UnwindSafe,

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> Same for T

Source§

type Output = T

Should always be Self
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.