silk/zstd
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc.
Bounded, resumable Zstandard decoding into caller-owned byte slices.
When to use
Use Zstd for RFC 8878 files or HTTP zstd content. The decoder accepts all non-dictionary block modes.
Use Zstd.make to allocate state, then step until the result reports Finished.
Details
Input and output are borrowed only for one call. State owns its history and scratch storage. Limits apply across all concatenated regular and skippable frames. A frame boundary is not end of input. The first final call fixes the input end. Later calls must supply its unconsumed suffix with final input set.
Gotchas
Output is provisional until Finished: a later checksum or truncated trailer can invalidate earlier output.
A failure is terminal. Drop the decoder to release its storage and construct another decoder for another stream.
Import as Zstd with import silk.zstd { Zstd }.
Public declarations: 6.
ZstdLimits
pub struct ZstdLimitsResource limits for one complete concatenated input stream.
Field inputBytes
pub inputBytes: u64Maximum consumed bytes, including headers, trailers, and skipped bytes.
Field outputBytes
pub outputBytes: u64Maximum decoded bytes across all regular frames.
Field frames
pub frames: u64Maximum regular and skippable frame count combined.
Field skippableBytes
pub skippableBytes: u64Maximum skipped payload bytes across all skippable frames.
Field windowBytes
pub windowBytes: usizeMaximum advertised window and exact allocated history capacity.
Field workspaceBytes
pub workspaceBytes: usizeMaximum non-window workspace, including staging, state, and bounded entropy scratch.
Associated function ZstdLimits.make
pub fn make() -> ZstdLimitsReturns limits of 64 MiB input, 256 MiB output, 1024 frames, 8 MiB skipped bytes and window, and 1 MiB workspace.
ZstdStatus
pub enum ZstdStatusThe resource needed to continue, or successful end of the complete input.
NeedInput
NeedInput = 0The supplied input is exhausted; supply more input or declare its end.
NeedOutput
NeedOutput = 1Pending decoded bytes need output space; supply a nonempty output slice.
Finished
Finished = 2Final input ended after complete frame and trailer validation.
ZstdProgress
pub struct ZstdProgressExact progress made by one successful step.
Field consumed
pub consumed: usizeInput bytes consumed by this call; resubmit only the remaining suffix.
Field written
pub written: usizeOutput bytes written by this call; only this prefix of the destination was changed.
Field status
pub status: ZstdStatusThe required next resource or terminal completion.
ZstdReason
pub enum ZstdReasonA precise category of decoder failure.
None
None = 0No failure; used only by live internal state.
InvalidConfiguration
InvalidConfiguration = 1Configuration cannot represent the required storage.
InvalidState
InvalidState = 2A call changes an established final input boundary or adds input after completion.
InvalidMagic
InvalidMagic = 3Input does not start with a regular or skippable frame magic number.
ReservedFrame
ReservedFrame = 4The reserved frame-header bit is set.
ReservedBlock
ReservedBlock = 5A block uses the reserved block type.
BlockSize
BlockSize = 6A block exceeds the frame block maximum or has an invalid size.
MalformedBlock
MalformedBlock = 7Entropy data or a match sequence is invalid; inspect the block reason.
UnsupportedDictionary
UnsupportedDictionary = 8A frame requests a nonzero dictionary ID.
Truncated
Truncated = 9Final input ends before a complete stream is available.
Checksum
Checksum = 10The frame checksum differs from seed-zero XXH64 of its decoded bytes.
ContentSize
ContentSize = 11Decoded frame length differs from its declared content size.
InputLimit
InputLimit = 12Cumulative input exceeds its configured limit.
OutputLimit
OutputLimit = 13Cumulative decoded output exceeds its configured limit.
FrameLimit
FrameLimit = 14The combined regular and skippable frame count exceeds its limit.
SkippableLimit
SkippableLimit = 15Cumulative skipped payload bytes exceed their limit.
WindowLimit
WindowLimit = 16The advertised frame window exceeds the configured history capacity.
WorkspaceLimit
WorkspaceLimit = 17The configured workspace budget cannot hold bounded decoder storage.
ZstdError
pub struct ZstdErrorA terminal decoding failure with exact progress and location.
Details
consumed and written describe this call, including progress before failure.
Previously written bytes remain provisional. Repeated calls return the same reason and offset with zero progress.
Field reason
pub reason: ZstdReasonThe category that stopped decoding.
Field blockReason
pub blockReason: BlockReasonThe compressed-block category, or None for framing and resource failures.
Field offset
pub offset: u64The cumulative consumed input position where failure was detected.
Field consumed
pub consumed: usizeInput bytes consumed during this call before failure.
Field written
pub written: usizeOutput bytes written during this call before failure.
Zstd
pub struct ZstdAn owned, allocation-free-after-construction decoder for one concatenated stream.
Details
The state releases all allocations when dropped. It retains neither input nor output borrows between calls. Each regular frame resets its history, entropy tables, and checksum, but cumulative limits do not reset.
Associated function Zstd.make
pub effect<'static> fn make(limits: ZstdLimits) -> Zstd ! ZstdError | OutOfMemoryError ? &mut AllocatorAllocates exact bounded storage and creates a decoder for one complete input stream.
Details
Allocation uses the supplied Allocator. No allocation occurs during step.
Storage includes windowBytes, three 128 KiB staging buffers, and bounded state and entropy scratch.
A zero window or unrepresentable total size fails before allocation. Insufficient workspace reports WorkspaceLimit.
Method Zstd.step
pub fn step<'life0, 'life1, 'life2>(self: &'life0 mut Zstd, input: &'life1 [u8], output: &'life2 mut [u8], finalInput: bool) -> silk/result.Result<silk/zstd.ZstdProgress, silk/zstd.ZstdError>Consumes input and writes output until a resource is needed, input finishes, or a typed error occurs.
Details
Resubmit only input[consumed..] and use only output[..written] from each result.
A final call fixes the absolute input end. Later calls must supply the complete unconsumed suffix with finalInput true.
NeedOutput with an empty destination makes no output progress; provide a nonempty destination before retrying.
NeedInput exhausts the input. Finished validates all concatenated frames and permits only empty final retries.
Gotchas
Output can precede a checksum or truncation failure. Do not treat it as validated until Finished.
Failure poisons this state. Subsequent calls report the same failure location and make no progress.