Struct q_compress::Decompressor
source · [−]pub struct Decompressor<T> where
T: NumberLike, { /* private fields */ }
Expand description
Converts compressed bytes into Flags
, ChunkMetadata
,
and vectors of numbers.
You can use the decompressor very easily:
use q_compress::Decompressor;
let my_bytes = vec![113, 99, 111, 33, 3, 0, 46]; // the simplest possible .qco file; empty
let decompressor = Decompressor::<i32>::default();
let nums = decompressor.simple_decompress(my_bytes).expect("decompression"); // returns Vec<i32>
You can also get full control over the decompression process:
use q_compress::{BitReader, Decompressor};
let my_bytes = vec![113, 99, 111, 33, 3, 0, 46]; // the simplest possible .qco file; empty
let mut reader = BitReader::from(my_bytes);
let decompressor = Decompressor::<i32>::default();
let flags = decompressor.header(&mut reader).expect("header failure");
while let Some(chunk_meta) = decompressor.chunk_metadata(&mut reader, &flags).expect("chunk meta failure") {
let nums = decompressor.chunk_body(&mut reader, &flags, &chunk_meta).expect("chunk body failure");
}
// We don't need to explicitly read the footer because `.chunk_metadata()`
// returns `None` when it reaches the footer byte.
Implementations
sourceimpl<T> Decompressor<T> where
T: NumberLike,
impl<T> Decompressor<T> where
T: NumberLike,
sourcepub fn from_config(config: DecompressorConfig) -> Self
pub fn from_config(config: DecompressorConfig) -> Self
Creates a new decompressor, given a DecompressorConfig
.
This config has nothing to do with Flags
, which will be parsed out
of a .qco file’s header.
sourcepub fn header(&self, reader: &mut BitReader) -> QCompressResult<Flags>
pub fn header(&self, reader: &mut BitReader) -> QCompressResult<Flags>
Reads the header, returning its Flags
.
Will return an error if the reader is not byte-aligned,
if the reader runs out of data, if the data type byte does not agree,
if the flags are from a newer, incompatible version of q_compress,
or if any corruptions are found.
sourcepub fn chunk_metadata(
&self,
reader: &mut BitReader,
flags: &Flags
) -> QCompressResult<Option<ChunkMetadata<T>>>
pub fn chunk_metadata(
&self,
reader: &mut BitReader,
flags: &Flags
) -> QCompressResult<Option<ChunkMetadata<T>>>
Reads a ChunkMetadata
, returning it.
Will return None
if it instead finds a termination footer
(indicating end of the .qco file).
Will return an error if the reader is not byte-aligned,
the reader runs out of data, or any corruptions are found.
Typically one would pass in the Flags
obtained from an earlier
.header()
call.
sourcepub fn chunk_body(
&self,
reader: &mut BitReader,
flags: &Flags,
metadata: &ChunkMetadata<T>
) -> QCompressResult<Vec<T>>
pub fn chunk_body(
&self,
reader: &mut BitReader,
flags: &Flags,
metadata: &ChunkMetadata<T>
) -> QCompressResult<Vec<T>>
Reads a chunk body, returning it as a vector of numbers. Will return an error if the reader is not byte-aligned, the reader runs out of data, or any corruptions are found.
Typically one would pass in the Flags
obtained from an earlier
.header()
call and the ChunkMetadata
obtained
from an earlier .chunk_metadata()
call.
sourcepub fn chunk(
&self,
reader: &mut BitReader,
flags: &Flags
) -> QCompressResult<Option<DecompressedChunk<T>>>
pub fn chunk(
&self,
reader: &mut BitReader,
flags: &Flags
) -> QCompressResult<Option<DecompressedChunk<T>>>
Reads a ChunkMetadata
and the chunk body into a vector of numbers,
returning both.
Will return None
if it instead finds a termination footer
(indicating end of the .qco file).
Will return an error if the reader is not byte-aligned,
the reader runs out of data, or any corruptions are found.
The same effect can be achieved via
.chunk_metadata()
and
.chunk_body()
.
sourcepub fn simple_decompress(&self, bytes: Vec<u8>) -> QCompressResult<Vec<T>>
pub fn simple_decompress(&self, bytes: Vec<u8>) -> QCompressResult<Vec<T>>
Takes in compressed bytes and returns a vector of numbers. Will return an error if there are any compatibility, corruption, or insufficient data issues.
Trait Implementations
sourceimpl<T: Clone> Clone for Decompressor<T> where
T: NumberLike,
impl<T: Clone> Clone for Decompressor<T> where
T: NumberLike,
sourcefn clone(&self) -> Decompressor<T>
fn clone(&self) -> Decompressor<T>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<T: Debug> Debug for Decompressor<T> where
T: NumberLike,
impl<T: Debug> Debug for Decompressor<T> where
T: NumberLike,
sourceimpl<T: Default> Default for Decompressor<T> where
T: NumberLike,
impl<T: Default> Default for Decompressor<T> where
T: NumberLike,
sourcefn default() -> Decompressor<T>
fn default() -> Decompressor<T>
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for Decompressor<T> where
T: RefUnwindSafe,
impl<T> Send for Decompressor<T> where
T: Send,
impl<T> Sync for Decompressor<T> where
T: Sync,
impl<T> Unpin for Decompressor<T> where
T: Unpin,
impl<T> UnwindSafe for Decompressor<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more