Function decodeFrameArrayList [src]
Decodes the frame at the start of src into dest. Returns the number of
bytes read from src.
Errors returned:
error.BadMagic if the first 4 bytes of src is not a valid magic
number for a Zstandard or skippable frame
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
that is larger than std.math.maxInt(usize)
error.DictionaryIdFlagUnsupported if the frame uses a dictionary
error.ChecksumFailure if verify_checksum is true and the frame
contains a checksum that does not match the checksum of the decompressed
data
error.ReservedBitSet if any of the reserved bits of the frame header
are set
error.EndOfStream if src does not contain a complete frame
error.BadContentSize if the content size declared by the frame does
not equal the actual size of decompressed data
error.OutOfMemory if allocator cannot allocate enough memory
an error in block.Error if there are errors decoding a block
error.SkippableSizeTooLarge if the frame is skippable and reports a
size greater than src.len
Prototype
pub fn decodeFrameArrayList( allocator: Allocator, dest: *std.ArrayList(u8), src: []const u8, verify_checksum: bool, window_size_max: usize, ) (error{ BadMagic, OutOfMemory, SkippableSizeTooLarge } || FrameContext.Error || FrameError)!usize
Parameters
allocator: Allocator
dest: *std.ArrayList(u8)
src: []const u8
verify_checksum: bool
window_size_max: usize
Source
pub fn decodeFrameArrayList(
allocator: Allocator,
dest: *std.ArrayList(u8),
src: []const u8,
verify_checksum: bool,
window_size_max: usize,
) (error{ BadMagic, OutOfMemory, SkippableSizeTooLarge } || FrameContext.Error || FrameError)!usize {
var fbs = std.io.fixedBufferStream(src);
const reader = fbs.reader();
const magic = try reader.readInt(u32, .little);
switch (try frameType(magic)) {
.zstandard => return decodeZstandardFrameArrayList(
allocator,
dest,
src,
verify_checksum,
window_size_max,
),
.skippable => {
const content_size = try fbs.reader().readInt(u32, .little);
if (content_size > std.math.maxInt(usize) - 8) return error.SkippableSizeTooLarge;
const read_count = @as(usize, content_size) + 8;
if (read_count > src.len) return error.SkippableSizeTooLarge;
return read_count;
},
}
}