Skip to main content

SwmrFileReader

Struct SwmrFileReader 

Source
pub struct SwmrFileReader { /* private fields */ }
Expand description

SWMR reader for monitoring a streaming HDF5 file.

Opens a file being written by a concurrent SwmrFileWriter and periodically calls refresh to pick up new data.

use rust_hdf5::swmr::SwmrFileReader;

let mut reader = SwmrFileReader::open("stream.h5").unwrap();

loop {
    reader.refresh().unwrap();
    let names = reader.dataset_names();
    if let Some(shape) = reader.dataset_shape("frames").ok() {
        println!("frames shape: {:?}", shape);
        if shape[0] > 0 {
            let data = reader.read_dataset_raw("frames").unwrap();
            println!("got {} bytes", data.len());
            break;
        }
    }
    std::thread::sleep(std::time::Duration::from_millis(100));
}

Implementations§

Source§

impl SwmrFileReader

Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>

Open an HDF5 file for SWMR reading using the env-var-derived locking policy. Takes a shared lock so it coexists with the downgraded shared lock held by SwmrFileWriter after start_swmr, and with other concurrent SWMR readers.

Source

pub fn open_with_locking<P: AsRef<Path>>( path: P, locking: FileLocking, ) -> Result<Self>

Open an HDF5 file for SWMR reading with an explicit locking policy.

Source

pub fn refresh(&mut self) -> Result<()>

Re-read the superblock and dataset metadata from disk.

Call this periodically to pick up new data written by the concurrent SWMR writer.

Source

pub fn dataset_names(&self) -> Vec<String>

Return the names of all datasets.

Source

pub fn dataset_shape(&self, name: &str) -> Result<Vec<u64>>

Return the current shape of a dataset.

Source

pub fn read_dataset_raw(&mut self, name: &str) -> Result<Vec<u8>>

Read the raw bytes of a dataset.

Source

pub fn read_dataset<T: H5Type>(&mut self, name: &str) -> Result<Vec<T>>

Read a dataset as a typed vector.

Source

pub fn read_slice_raw( &mut self, name: &str, starts: &[u64], counts: &[u64], ) -> Result<Vec<u8>>

Read a slice (hyperslab) of a dataset as raw bytes.

starts[d] is the first index along dimension d, counts[d] is how many. For a streaming dataset this reads only the chunks the slice overlaps — the efficient way for a live viewer to fetch the latest frame without re-reading the whole stream.

Source

pub fn read_slice<T: H5Type>( &mut self, name: &str, starts: &[u64], counts: &[u64], ) -> Result<Vec<T>>

Read a slice (hyperslab) of a dataset as a typed vector. See read_slice_raw.

Source

pub fn read_vlen_strings(&mut self, name: &str) -> Result<Vec<String>>

Read a variable-length string dataset.

Source

pub fn dataset_element_size(&self, name: &str) -> Result<usize>

Element size of a dataset’s datatype, in bytes — enough to size a read buffer without knowing the concrete element type at compile time.

Source

pub fn group_paths(&self) -> Vec<String>

All group paths in the file.

Source

pub fn has_group(&self, group_path: &str) -> bool

Whether a group exists. A leading / is tolerated.

Source

pub fn dataset_attr_names(&self, name: &str) -> Result<Vec<String>>

Names of the attributes on a dataset.

Source

pub fn dataset_attr_string( &mut self, dataset: &str, attr: &str, ) -> Result<String>

Read a dataset’s attribute as a string (e.g. units, NX_class).

Source

pub fn group_attr_names(&self, group_path: &str) -> Vec<String>

Names of the attributes on a group, or on the root group when group_path is "/". A leading / is tolerated.

Source

pub fn group_attr_string( &mut self, group_path: &str, attr: &str, ) -> Result<String>

Read a group’s attribute as a string (the NeXus NX_class etc.), or a root attribute when group_path is "/". A leading / is tolerated.

Auto Trait Implementations§

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.