Struct Chunk

Source
pub struct Chunk<'a> { /* private fields */ }
Expand description

A chunk of compressed data.

A chunk is a thin wrapper around CowVec<u8>, with some additional metadata, and the creation of a Chunk through the Self::from_compressed is very cheap.

Implementations§

Source§

impl<'a> Chunk<'a>

Source

pub fn from_compressed(bytes: CowVec<'a, u8>) -> Result<Self, Error>

Create a new Chunk from a compressed bytes buffer.

Source

pub fn as_bytes(&self) -> &[u8]

Get a reference to the underlying bytes buffer.

Source

pub fn into_bytes(self) -> CowVec<'a, u8>

Convert the chunk into a bytes buffer.

Source

pub fn get_dparams(&self) -> DParams

Get the current decompression parameters.

Source

pub fn set_dparams(&self, params: DParams) -> Result<(), Error>

Set the decompression parameters.

Source

pub fn decompress(&self) -> Result<Vec<u8>, Error>

Decompress the whole chunk into a new allocated bytes vector.

For decompressing the data into an already allocated buffer, create a Decoder (with other params or Self::get_dparams) and use Decoder::decompress_into.

Source

pub fn nbytes(&self) -> usize

Get the number of bytes in the uncompressed data.

Source

pub fn typesize(&self) -> usize

Get the size of each item in the chunk.

Source

pub fn items_num(&self) -> usize

Get the number of items in the chunk.

Source

pub fn item(&self, idx: usize) -> Result<Vec<u8>, Error>

Get an item at the specified index.

Each item is typesize (as provided during encoding) bytes long, and the index is zero-based.

Note that the returned vector may not be aligned to the original data type’s alignment, and the caller should ensure that the alignment is correct before transmuting it to original type. If the alignment does not match the original data type, the bytes should be copied to a new aligned allocation before transmuting, otherwise undefined behavior may occur. Alternatively, the caller can use Self::item_into and provide an already aligned destination buffer.

Source

pub fn item_into( &self, idx: usize, dst: &mut [MaybeUninit<u8>], ) -> Result<usize, Error>

Get an item at the specified index and copy it into the provided destination buffer.

Each item is typesize (as provided during encoding) bytes long, and the index is zero-based.

Note that if the destination buffer is not aligned to the original data type’s alignment, the caller should not transmute the decompressed data to original type, as this may lead to undefined behavior.

Source

pub fn items(&self, idx: Range<usize>) -> Result<Vec<u8>, Error>

Get a range of items specified by the index range.

Each item is typesize (as provided during encoding) bytes long, and the index is zero-based.

Note that the returned vector may not be aligned to the original data type’s alignment, and the caller should ensure that the alignment is correct before transmuting it to original type. If the alignment does not match the original data type, the bytes should be copied to a new aligned allocation before transmuting, otherwise undefined behavior may occur. Alternatively, the caller can use Self::items_into and provide an already aligned destination buffer.

Source

pub fn items_into( &self, idx: Range<usize>, dst: &mut [MaybeUninit<u8>], ) -> Result<usize, Error>

Get a range of items specified by the index range and copy them into the provided destination buffer.

Each item is typesize (as provided during encoding) bytes long, and the index is zero-based.

Note that if the destination buffer is not aligned to the original data type’s alignment, the caller should not transmute the decompressed data to original type, as this may lead to undefined behavior.

Source

pub fn shallow_clone(&self) -> Chunk<'_>

Create a shallow clone of the chunk without re-allocating the internal buffer.

Trait Implementations§

Source§

impl Clone for Chunk<'_>

Source§

fn clone(&self) -> Self

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

Auto Trait Implementations§

§

impl<'a> !Freeze for Chunk<'a>

§

impl<'a> !RefUnwindSafe for Chunk<'a>

§

impl<'a> !Send for Chunk<'a>

§

impl<'a> !Sync for Chunk<'a>

§

impl<'a> Unpin for Chunk<'a>

§

impl<'a> UnwindSafe for Chunk<'a>

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.