DoxigAlpha

init

Validates frame_header and returns the associated Frame.

Function parameters

Parameters

#
frame_header:Frame.Zstandard.Header
window_size_max:usize
verify_checksum:bool

Type definitions in this namespace

Types

#

When connecting `reader` to a `Writer`, `buffer` should be empty, and

Functions

#
init
When connecting `reader` to a `Writer`, `buffer` should be empty, and

Error sets in this namespace

Error Sets

#

Source

Implementation

#
pub fn init(
    frame_header: Frame.Zstandard.Header,
    window_size_max: usize,
    verify_checksum: bool,
) InitError!Frame {
    if (frame_header.descriptor.dictionary_id_flag != 0)
        return error.DictionaryIdFlagUnsupported;

    const window_size_raw = frame_header.windowSize() orelse return error.WindowSizeUnknown;
    const window_size = if (window_size_raw > window_size_max)
        return error.WindowOversize
    else
        std.math.cast(usize, window_size_raw) orelse return error.WindowOversize;

    const should_compute_checksum =
        frame_header.descriptor.content_checksum_flag and verify_checksum;

    const content_size = if (frame_header.content_size) |size|
        std.math.cast(usize, size) orelse return error.ContentOversize
    else
        null;

    return .{
        .hasher_opt = if (should_compute_checksum) std.hash.XxHash64.init(0) else null,
        .window_size = window_size,
        .has_checksum = frame_header.descriptor.content_checksum_flag,
        .block_size_max = @min(zstd.block_size_max, window_size),
        .content_size = content_size,
    };
}