Function init [src]

Validates frame_header and returns the associated Frame.

Prototype

pub fn init( frame_header: Frame.Zstandard.Header, window_size_max: usize, verify_checksum: bool, ) InitError!Frame

Parameters

frame_header: Frame.Zstandard.Headerwindow_size_max: usizeverify_checksum: bool

Possible Errors

ContentOversize

Frame header indicates a content size exceeding max usize value.

DictionaryIdFlagUnsupported

Frame uses a dictionary.

WindowOversize

Window size exceeds window_size_max or max usize value.

WindowSizeUnknown

Frame does not have a valid window size.

Source

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, }; }