Struct DataArray

Source
pub struct DataArray {
    pub data: Vec<u8>,
    pub dtype: BinaryDataArrayType,
    pub compression: BinaryCompressionType,
    pub name: ArrayType,
    pub params: Option<Box<Vec<Param>>>,
    pub unit: Unit,
    /* private fields */
}
Expand description

Represents a data array that holds a byte buffer that may be compressed, base64 encoded, or raw little endian bytes, and provides views of those bytes as a small range of supported types.

This type is modeled after the <binaryDataArray> element in mzML.

§Note

This type tries to walk a fine line between convenience and performance and as such is easy to misuse. All operations that view the byte buffer as arbitrary data need that data to be decoded and decompressed in order to borrow it. If the byte buffer is not already stored decoded, the operation will copy and decode the buffer in its entirety before performing any other operation, so repeated method calls may incur excessive overhead. If this is happening, please use DataArray::decode_and_store to store the decoded representation explicitly.

Normally, SpectrumSource-implementing file readers will eagerly decode all arrays as soon as they are ready. If they are operating in lazy mode, the buffers will need to be decoded explicitly, again using DataArray::decode_and_store or operations should make as much use of the copied arrays as possible instead.

Fields§

§data: Vec<u8>§dtype: BinaryDataArrayType§compression: BinaryCompressionType§name: ArrayType§params: Option<Box<Vec<Param>>>§unit: Unit

Implementations§

Source§

impl<'transient, 'lifespan> DataArray
where 'lifespan: 'transient,

A type to represent a base64-encoded, possibly compressed data array of a fixed size, usually numeric, type. It can be decoded, and it can

Source

pub fn new() -> DataArray

Source

pub fn from_name(name: &ArrayType) -> DataArray

Source

pub fn from_name_and_type( name: &ArrayType, dtype: BinaryDataArrayType, ) -> DataArray

Source

pub fn from_name_type_size( name: &ArrayType, dtype: BinaryDataArrayType, size: usize, ) -> DataArray

Source

pub fn slice( &self, start: usize, end: usize, ) -> Result<DataArray, ArrayRetrievalError>

Source

pub fn slice_buffer( &self, start: usize, end: usize, ) -> Result<Cow<'_, [u8]>, ArrayRetrievalError>

Source

pub fn wrap( name: &ArrayType, dtype: BinaryDataArrayType, data: Vec<u8>, ) -> DataArray

Source

pub fn update_buffer<T>( &mut self, data_buffer: &[T], ) -> Result<usize, ArrayRetrievalError>
where T: Pod,

Source

pub fn push<T>(&mut self, value: T) -> Result<(), ArrayRetrievalError>
where T: Pod,

Source

pub fn extend<T>(&mut self, values: &[T]) -> Result<(), ArrayRetrievalError>
where T: Pod,

Source

pub fn encode_bytestring(&self, compression: BinaryCompressionType) -> Vec<u8>

Source

pub fn compress_zlib(bytestring: &[u8]) -> Vec<u8>

Source

pub fn decompress_zlib(bytestring: &[u8]) -> Vec<u8>

Source

pub fn decode_and_store( &mut self, ) -> Result<BinaryCompressionType, ArrayRetrievalError>

Decode the compressed data, if needed, and store that buffer in self.data. After decoding self.compression will always be BinaryCompressionType::Decoded.

The return value is the content of self.compression after decoding.

This may fail if the decoding fails for any reason.

Source

pub fn decode( &'lifespan self, ) -> Result<Cow<'lifespan, [u8]>, ArrayRetrievalError>

Decompress and base64-decode encoded bytes, and return the data.

If the data were already decoded, the existing bytes are returned. Otherwise one or more buffers may be allocated to hold the decompressed and decoded bytes.

Source

pub fn decode_mut( &'transient mut self, ) -> Result<&'transient mut Vec<u8>, ArrayRetrievalError>

Source

pub fn clear(&mut self)

Source

pub fn store_compressed( &mut self, compression: BinaryCompressionType, ) -> Result<(), ArrayRetrievalError>

The reverse of DataArray::decode_and_store, this method compresses self.data to the desired compression method and stores that buffer as self.data.

Source

pub fn store_as( &mut self, dtype: BinaryDataArrayType, ) -> Result<usize, ArrayRetrievalError>

Recode the stored data as the requested binary data type.

Source

pub const fn is_ion_mobility(&self) -> bool

Test if the the array describes an ion mobility quantity.

§See also

ArrayType::is_ion_mobility

Source

pub fn raw_len(&self) -> usize

The size of the raw byte buffer

Trait Implementations§

Source§

impl<'transient, 'lifespan> ByteArrayView<'transient, 'lifespan> for DataArray
where 'lifespan: 'transient,

Source§

fn view(&'lifespan self) -> Result<Cow<'lifespan, [u8]>, ArrayRetrievalError>

Source§

fn dtype(&self) -> BinaryDataArrayType

The real data type encoded in bytes
Source§

fn data_len(&'lifespan self) -> Result<usize, ArrayRetrievalError>

The size of encoded array in terms of # of elements of the BinaryDataArrayType given by ByteArrayView::dtype
Source§

fn unit(&self) -> Unit

The unit of measurement each data point is in
Source§

fn name(&self) -> &ArrayType

The kind of array this is
Source§

fn coerce_from<T>( buffer: Cow<'transient, [u8]>, ) -> Result<Cow<'transient, [T]>, ArrayRetrievalError>
where T: Pod,

Source§

fn coerce<T>( &'lifespan self, ) -> Result<Cow<'transient, [T]>, ArrayRetrievalError>
where T: Pod,

Source§

fn convert<S, D>( &'lifespan self, ) -> Result<Cow<'transient, [D]>, ArrayRetrievalError>
where S: Num + Clone + AsPrimitive<D> + Pod, D: Num + Clone + Copy + 'static,

Decode the array, then copy it to a new array, converting each element from type D to to type S
Source§

fn to_f32( &'lifespan self, ) -> Result<Cow<'transient, [f32]>, ArrayRetrievalError>

Source§

fn to_f64( &'lifespan self, ) -> Result<Cow<'transient, [f64]>, ArrayRetrievalError>

Source§

fn to_i32( &'lifespan self, ) -> Result<Cow<'transient, [i32]>, ArrayRetrievalError>

Source§

fn to_i64( &'lifespan self, ) -> Result<Cow<'transient, [i64]>, ArrayRetrievalError>

Source§

fn iter_type<T>( &'lifespan self, ) -> Result<DataSliceIter<'lifespan, T>, ArrayRetrievalError>
where T: Pod,

Source§

fn iter_u8( &'lifespan self, ) -> Result<DataSliceIter<'lifespan, u8>, ArrayRetrievalError>

Source§

fn iter_f32( &'lifespan self, ) -> Result<DataSliceIter<'lifespan, f32>, ArrayRetrievalError>

Source§

fn iter_f64( &'lifespan self, ) -> Result<DataSliceIter<'lifespan, f64>, ArrayRetrievalError>

Source§

fn iter_i32( &'lifespan self, ) -> Result<DataSliceIter<'lifespan, i32>, ArrayRetrievalError>

Source§

fn iter_i64( &'lifespan self, ) -> Result<DataSliceIter<'lifespan, i64>, ArrayRetrievalError>

Source§

impl<'transient, 'lifespan> ByteArrayViewMut<'transient, 'lifespan> for DataArray
where 'lifespan: 'transient,

Source§

fn view_mut( &'transient mut self, ) -> Result<&'transient mut Vec<u8>, ArrayRetrievalError>

Get a mutable view of the bytes backing this data array. Read more
Source§

fn unit_mut(&mut self) -> &mut Unit

Specify the unit of the data array
Source§

fn coerce_from_mut<T>( buffer: &mut [u8], ) -> Result<&'transient mut [T], ArrayRetrievalError>
where T: Clone,

Source§

fn coerce_mut<T>( &'lifespan mut self, ) -> Result<&'transient mut [T], ArrayRetrievalError>
where T: Clone,

Source§

impl Clone for DataArray

Source§

fn clone(&self) -> DataArray

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DataArray

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for DataArray

Source§

fn default() -> DataArray

Returns the “default value” for a type. Read more
Source§

impl ParamDescribed for DataArray

Source§

fn params(&self) -> &[Param]

Obtain an immutable slice over the encapsulated Param list
Source§

fn params_mut(&mut self) -> &mut Vec<Param>

Obtain an mutable slice over the encapsulated Param list
Source§

fn add_param(&mut self, param: Param)

Add a new Param to the entity
Source§

fn extend_params(&mut self, it: impl IntoIterator<Item = Param>)

Add all parameters from an iterator of Param to the entity
Source§

fn remove_param(&mut self, index: usize) -> Param

Remove the ith Param from the entity.
Source§

fn get_param_by_name(&self, name: &str) -> Option<&Param>

Find the first Param whose name matches name
Source§

fn get_param_by_curie(&self, curie: &CURIE) -> Option<&Param>

Find the first Param whose CURIE matches curie
Source§

fn get_param_by_accession(&self, accession: &str) -> Option<&Param>

Find the first Param whose Param::accession matches accession Read more
Source§

fn iter_params(&self) -> Iter<'_, Param>

Iterate over the encapsulated parameter list
Source§

fn iter_params_mut(&mut self) -> IterMut<'_, Param>

Iterate mutably over the encapsulated parameter list

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.