pub struct WorkspaceDecoder<'w> { /* private fields */ }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>
impl<'w> WorkspaceDecoder<'w>
Sourcepub fn new(
workspace: &'w mut [u8],
limits: DecodeLimits,
) -> Result<Self, WorkspaceConfigError>
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.
Sourcepub fn reset(&mut self)
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.
Sourcepub fn total_output(&self) -> u64
pub fn total_output(&self) -> u64
Decompressed bytes the stream has produced so far, delivered or not.
Sourcepub fn step(
&mut self,
input: &[u8],
input_is_final: bool,
output: &mut [u8],
work: &mut WorkBudget,
) -> Result<Progress, WorkspaceDecodeError>
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.