Silk

silk/support/zstd_block

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.

Internal bounded zstd compressed-block decoding with retained entropy tables.

Details

Callers supply literal, output, and circular history storage. A failed decode invalidates the state.

Import as BlockState with import silk.support.zstd_block { BlockState }.

Public declarations: 3.

BlockReason

pub enum BlockReason

The invalid component of a compressed zstd block.

None

None = 0

No compressed-block failure applies.

Literals

Literals = 1

A literal header, tree, or stream is invalid.

Sequences

Sequences = 2

A sequence header, table, or bitstream is invalid.

Offset

Offset = 3

A match points outside the available window.

Output

Output = 4

The decoded block exceeds the supplied output storage.

BlockError

pub struct BlockError

A compressed-block failure and its local compressed byte position.

Field reason

pub reason: BlockReason

The invalid component.

Field offset

pub offset: usize

The local compressed byte position.

BlockState

pub struct BlockState

Retained entropy tables and repeat offsets for one zstd frame.

Associated function BlockState.make

pub effect<'static> fn make() -> BlockState ! OutOfMemoryError ? &mut Allocator

Allocates fresh entropy tables and sets the initial repeat offsets for one frame.

Details

The state owns five exact allocations and releases them when dropped. Decode and reset do not allocate.

Method BlockState.reset

pub fn reset<'life0>(self: &'life0 mut BlockState) -> ()

Restores fresh entropy tables and repeat offsets before a new frame.

Associated function BlockState.workspaceBytes

pub fn workspaceBytes() -> usize

Returns a conservative byte bound for tables and transient algorithm scratch on supported targets.

Details

This bound excludes caller-owned compressed, literal, output, and history storage.

Method BlockState.decode

pub fn decode<'life0, 'life1, 'life2, 'life3, 'life4>(self: &'life0 mut BlockState, input: &'life1 [u8], literals: &'life2 mut [u8], output: &'life3 mut [u8], history: &'life4 [u8], historyPosition: usize, historyLength: usize, windowSize: usize) -> silk/result.Result<usize, silk/support/zstd_block.BlockError>

Decodes one complete compressed block into caller-owned storage without allocation.

Details

Returns the initialized output length. historyPosition is the next circular write position. historyLength counts valid bytes from earlier blocks. windowSize bounds match distances.

Gotchas

Failure can change tables and scratch bytes. Discard the frame state after failure.

On this page