structstd.compress.zstandard.decompress.FrameContext[src]

Fields

hasher_opt: ?std.hash.XxHash64
window_size: usize
has_checksum: bool
block_size_max: usize
content_size: ?usize

Functions

Functioninit[src]

pub fn init( frame_header: ZstandardHeader, window_size_max: usize, verify_checksum: bool, ) Error!FrameContext

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 or std.math.intMax(usize)
  • error.ContentSizeTooLarge if the frame header indicates a content size larger than std.math.maxInt(usize)

Parameters

frame_header: ZstandardHeader
window_size_max: usize
verify_checksum: bool

Source Code

Source code
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
        std.math.cast(usize, window_size_raw) orelse return error.WindowTooLarge;

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

Source Code

Source code
pub const FrameContext = struct {
    hasher_opt: ?std.hash.XxHash64,
    window_size: usize,
    has_checksum: bool,
    block_size_max: usize,
    content_size: ?usize,

    const Error = error{
        DictionaryIdFlagUnsupported,
        WindowSizeUnknown,
        WindowTooLarge,
        ContentSizeTooLarge,
    };
    /// 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` or `std.math.intMax(usize)`
    ///   - `error.ContentSizeTooLarge` if the frame header indicates a content
    ///     size larger than `std.math.maxInt(usize)`
    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
            std.math.cast(usize, window_size_raw) orelse return error.WindowTooLarge;

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