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: UnitImplementations§
Source§impl<'transient, 'lifespan> DataArraywhere
'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
impl<'transient, 'lifespan> DataArraywhere
'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
pub fn new() -> DataArray
pub fn from_name(name: &ArrayType) -> DataArray
pub fn from_name_and_type( name: &ArrayType, dtype: BinaryDataArrayType, ) -> DataArray
pub fn from_name_type_size( name: &ArrayType, dtype: BinaryDataArrayType, size: usize, ) -> DataArray
pub fn slice( &self, start: usize, end: usize, ) -> Result<DataArray, ArrayRetrievalError>
pub fn slice_buffer( &self, start: usize, end: usize, ) -> Result<Cow<'_, [u8]>, ArrayRetrievalError>
pub fn wrap( name: &ArrayType, dtype: BinaryDataArrayType, data: Vec<u8>, ) -> DataArray
Sourcepub fn update_buffer<T>(
&mut self,
data_buffer: &[T],
) -> Result<usize, ArrayRetrievalError>where
T: Pod,
pub fn update_buffer<T>(
&mut self,
data_buffer: &[T],
) -> Result<usize, ArrayRetrievalError>where
T: Pod,
Directly set the data buffer from a slice of a Pod type.
This will return an error if std::mem::size_of::<T>() is not equal to
the size of DataArray::dtype.
Sourcepub fn push<T>(&mut self, value: T) -> Result<(), ArrayRetrievalError>where
T: Pod,
pub fn push<T>(&mut self, value: T) -> Result<(), ArrayRetrievalError>where
T: Pod,
Add the value of a Pod implementing type T to the array, converting it
to native byte representation.
This will return an error if std::mem::size_of::<T>() is not equal to
the size of DataArray::dtype.
Sourcepub fn extend<T>(&mut self, values: &[T]) -> Result<(), ArrayRetrievalError>where
T: Pod,
pub fn extend<T>(&mut self, values: &[T]) -> Result<(), ArrayRetrievalError>where
T: Pod,
Add the values from a slice of a Pod implementing type T to the array, converting the slice
a slice of T in its native byte representation.
This will return an error if std::mem::size_of::<T>() is not equal to
the size of DataArray::dtype.
Sourcepub fn extend_raw(&mut self, values: &[u8]) -> Result<(), ArrayRetrievalError>
pub fn extend_raw(&mut self, values: &[u8]) -> Result<(), ArrayRetrievalError>
Add the values from a buffer of bytes to the array directly.
This will return an error if values.len() is not a multiple of
the size of DataArray::dtype.
Sourcepub fn extend_iter<T>(
&mut self,
iter: impl IntoIterator<Item = T>,
) -> Result<(), ArrayRetrievalError>where
T: Pod,
pub fn extend_iter<T>(
&mut self,
iter: impl IntoIterator<Item = T>,
) -> Result<(), ArrayRetrievalError>where
T: Pod,
Add the values from an iterator over Pod type T.
This is more efficient than repeated calls to DataArray::push or collecting
to a Vec and then using DataArray::extend, but equivalent to either.
This will return an error if std::mem::size_of::<T>() is not equal to
the size of DataArray::dtype.
Sourcepub fn encode_bytestring(&self, compression: BinaryCompressionType) -> Vec<u8> ⓘ
pub fn encode_bytestring(&self, compression: BinaryCompressionType) -> Vec<u8> ⓘ
Encode the data buffer to a byte array using the requested BinaryCompressionType to
compress it and then base64 encode it.
Sourcepub fn decode_and_store(
&mut self,
) -> Result<BinaryCompressionType, ArrayRetrievalError>
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.
Sourcepub fn decode(
&'lifespan self,
) -> Result<Cow<'lifespan, [u8]>, ArrayRetrievalError>
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.
pub fn decode_mut( &'transient mut self, ) -> Result<&'transient mut Vec<u8>, ArrayRetrievalError>
pub fn clear(&mut self)
Sourcepub fn store_compressed(
&mut self,
compression: BinaryCompressionType,
) -> Result<(), ArrayRetrievalError>
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.
Sourcepub fn store_as(
&mut self,
dtype: BinaryDataArrayType,
) -> Result<usize, ArrayRetrievalError>
pub fn store_as( &mut self, dtype: BinaryDataArrayType, ) -> Result<usize, ArrayRetrievalError>
Recode the stored data as the requested binary data type.
Sourcepub const fn is_ion_mobility(&self) -> bool
pub const fn is_ion_mobility(&self) -> bool
Sourcepub fn data_processing_reference(&self) -> Option<&str>
pub fn data_processing_reference(&self) -> Option<&str>
Get the identifier referencing a DataProcessing
Sourcepub fn set_data_processing_reference(
&mut self,
data_processing_reference: Option<Box<str>>,
)
pub fn set_data_processing_reference( &mut self, data_processing_reference: Option<Box<str>>, )
Set the identifier referencing a DataProcessing
Trait Implementations§
Source§impl<'transient, 'lifespan> ByteArrayView<'transient, 'lifespan> for DataArraywhere
'lifespan: 'transient,
impl<'transient, 'lifespan> ByteArrayView<'transient, 'lifespan> for DataArraywhere
'lifespan: 'transient,
fn view(&'lifespan self) -> Result<Cow<'lifespan, [u8]>, ArrayRetrievalError>
Source§fn dtype(&self) -> BinaryDataArrayType
fn dtype(&self) -> BinaryDataArrayType
Source§fn data_len(&'lifespan self) -> Result<usize, ArrayRetrievalError>
fn data_len(&'lifespan self) -> Result<usize, ArrayRetrievalError>
BinaryDataArrayType given by ByteArrayView::dtypeSource§fn data_processing_reference(&self) -> Option<&str>
fn data_processing_reference(&self) -> Option<&str>
DataProcessingfn coerce_from<T>(
buffer: Cow<'transient, [u8]>,
) -> Result<Cow<'transient, [T]>, ArrayRetrievalError>where
T: Pod,
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>
fn convert<S, D>( &'lifespan self, ) -> Result<Cow<'transient, [D]>, ArrayRetrievalError>
D to to type Sfn to_f32( &'lifespan self, ) -> Result<Cow<'transient, [f32]>, ArrayRetrievalError>
fn to_f64( &'lifespan self, ) -> Result<Cow<'transient, [f64]>, ArrayRetrievalError>
fn to_i32( &'lifespan self, ) -> Result<Cow<'transient, [i32]>, ArrayRetrievalError>
fn to_i64( &'lifespan self, ) -> Result<Cow<'transient, [i64]>, ArrayRetrievalError>
fn iter_type<T>(
&'lifespan self,
) -> Result<DataSliceIter<'lifespan, T>, ArrayRetrievalError>where
T: Pod,
fn iter_u8( &'lifespan self, ) -> Result<DataSliceIter<'lifespan, u8>, ArrayRetrievalError>
fn iter_f32( &'lifespan self, ) -> Result<DataSliceIter<'lifespan, f32>, ArrayRetrievalError>
fn iter_f64( &'lifespan self, ) -> Result<DataSliceIter<'lifespan, f64>, ArrayRetrievalError>
fn iter_i32( &'lifespan self, ) -> Result<DataSliceIter<'lifespan, i32>, ArrayRetrievalError>
fn iter_i64( &'lifespan self, ) -> Result<DataSliceIter<'lifespan, i64>, ArrayRetrievalError>
Source§impl<'transient, 'lifespan> ByteArrayViewMut<'transient, 'lifespan> for DataArraywhere
'lifespan: 'transient,
impl<'transient, 'lifespan> ByteArrayViewMut<'transient, 'lifespan> for DataArraywhere
'lifespan: 'transient,
Source§fn view_mut(
&'transient mut self,
) -> Result<&'transient mut Vec<u8>, ArrayRetrievalError>
fn view_mut( &'transient mut self, ) -> Result<&'transient mut Vec<u8>, ArrayRetrievalError>
Source§fn set_data_processing_reference(
&mut self,
data_processing_reference: Option<Box<str>>,
)
fn set_data_processing_reference( &mut self, data_processing_reference: Option<Box<str>>, )
DataProcessingfn coerce_from_mut<T>(
buffer: &mut [u8],
) -> Result<&'transient mut [T], ArrayRetrievalError>where
T: Clone,
fn coerce_mut<T>(
&'lifespan mut self,
) -> Result<&'transient mut [T], ArrayRetrievalError>where
T: Clone,
Source§impl ParamDescribed for DataArray
impl ParamDescribed for DataArray
Source§fn params_mut(&mut self) -> &mut Vec<Param>
fn params_mut(&mut self) -> &mut Vec<Param>
Param listSource§fn extend_params(&mut self, it: impl IntoIterator<Item = Param>)
fn extend_params(&mut self, it: impl IntoIterator<Item = Param>)
Param to the entitySource§fn get_param_by_name(&self, name: &str) -> Option<&Param>
fn get_param_by_name(&self, name: &str) -> Option<&Param>
Param whose name matches name