Skip to main content

WorkspaceDecoder

Struct WorkspaceDecoder 

Source
pub struct WorkspaceDecoder<'w> { /* private fields */ }
Available on crate feature caller-workspace only.
Expand description

Allocation-free streaming zstd decoder over a caller-owned workspace.

See the module documentation for the contract and an example.

Implementations§

Source§

impl<'w> WorkspaceDecoder<'w>

Source

pub fn new( workspace: &'w mut [u8], limits: DecodeLimits, ) -> Result<Self, WorkspaceConfigError>

Build a decoder in workspace, which must hold at least workspace_bytes(limits.max_window_size) bytes. Nothing is allocated, now or later; the workspace stays borrowed for the decoder’s life.

§Errors

WorkspaceConfigError when the window limit is out of range or the workspace is too small for it.

Source

pub fn reset(&mut self)

Start a new stream: forget the current one, including a failure, and expect a frame’s magic number next. The workspace is reused as it is.

Source

pub fn total_output(&self) -> u64

Decompressed bytes the stream has produced so far, delivered or not.

Source

pub fn step( &mut self, input: &[u8], input_is_final: bool, output: &mut [u8], work: &mut WorkBudget, ) -> Result<Progress, WorkspaceDecodeError>

Decode from input into output until one of them runs out or the stream ends.

input_is_final says no input follows this slice. Without it, running out of input asks for more (StepState::NeedInput); with it, input that ends between frames finishes the stream (StepState::Done) and input that ends inside one is WorkspaceDecodeError::Truncated. Unconsumed input must be passed again, first, on the next call.

Concatenated frames decode one after another, and skippable frames are consumed without output.

§Errors

See WorkspaceDecodeError. Any error ends the stream; the output already written by this call is then not counted in a Progress.

Trait Implementations§

Auto Trait Implementations§

§

impl<'w> !Sync for WorkspaceDecoder<'w>

§

impl<'w> !UnwindSafe for WorkspaceDecoder<'w>

§

impl<'w> Freeze for WorkspaceDecoder<'w>

§

impl<'w> RefUnwindSafe for WorkspaceDecoder<'w>

§

impl<'w> Unpin for WorkspaceDecoder<'w>

§

impl<'w> UnsafeUnpin for WorkspaceDecoder<'w>

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.