Function decodeZstandardHeader [src]

Decode the header of a Zstandard frame. Errors returned: error.ReservedBitSet if any of the reserved bits of the header are set error.EndOfStream if source does not contain a complete header

Prototype

pub fn decodeZstandardHeader( source: anytype, ) (@TypeOf(source).Error || error{ EndOfStream, ReservedBitSet })!ZstandardHeader

Source

pub fn decodeZstandardHeader( source: anytype, ) (@TypeOf(source).Error || error{ EndOfStream, ReservedBitSet })!ZstandardHeader { const descriptor = @as(ZstandardHeader.Descriptor, @bitCast(try source.readByte())); if (descriptor.reserved) return error.ReservedBitSet; var window_descriptor: ?u8 = null; if (!descriptor.single_segment_flag) { window_descriptor = try source.readByte(); } var dictionary_id: ?u32 = null; if (descriptor.dictionary_id_flag > 0) { // if flag is 3 then field_size = 4, else field_size = flag const field_size = (@as(u4, 1) << descriptor.dictionary_id_flag) >> 1; dictionary_id = try source.readVarInt(u32, .little, field_size); } var content_size: ?u64 = null; if (descriptor.single_segment_flag or descriptor.content_size_flag > 0) { const field_size = @as(u4, 1) << descriptor.content_size_flag; content_size = try source.readVarInt(u64, .little, field_size); if (field_size == 2) content_size.? += 256; } const header = ZstandardHeader{ .descriptor = descriptor, .window_descriptor = window_descriptor, .dictionary_id = dictionary_id, .content_size = content_size, }; return header; }