Function init [src]
Validates frame_header and returns the associated FrameContext.
Errors returned:
error.DictionaryIdFlagUnsupported if the frame uses a dictionary
error.WindowSizeUnknown if the frame does not have a valid window
size
error.WindowTooLarge if the window size is larger than
window_size_max
error.ContentSizeTooLarge if the frame header indicates a content
size larger than std.math.maxInt(usize)
Prototype
pub fn init( frame_header: ZstandardHeader, window_size_max: usize, verify_checksum: bool, ) Error!FrameContext
Parameters
frame_header: ZstandardHeader
window_size_max: usize
verify_checksum: bool
Possible Errors
Source
pub fn init(
frame_header: ZstandardHeader,
window_size_max: usize,
verify_checksum: bool,
) Error!FrameContext {
if (frame_header.descriptor.dictionary_id_flag != 0)
return error.DictionaryIdFlagUnsupported;
const window_size_raw = frameWindowSize(frame_header) orelse return error.WindowSizeUnknown;
const window_size = if (window_size_raw > window_size_max)
return error.WindowTooLarge
else
@as(usize, @intCast(window_size_raw));
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.ContentSizeTooLarge
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(types.block_size_max, window_size),
.content_size = content_size,
};
}