Function prepare [src]
Prepare the decoder to decode a compressed block. Loads the literals
stream and Huffman tree from literals and reads the FSE tables from
source.
Errors returned:
error.BitStreamHasNoStartBit if the (reversed) literal bitstream's
first byte does not have any bits set
error.TreelessLiteralsFirst literals is a treeless literals
section and the decode state does not have a Huffman tree from a
previous block
error.RepeatModeFirst on the first call if one of the sequence FSE
tables is set to repeat mode
error.MalformedAccuracyLog if an FSE table has an invalid accuracy
error.MalformedFseTable if there are errors decoding an FSE table
error.EndOfStream if source ends before all FSE tables are read
Prototype
pub fn prepare( self: *DecodeState, source: anytype, literals: LiteralsSection, sequences_header: SequencesSection.Header, ) !void
Parameters
self: *DecodeState
literals: LiteralsSection
sequences_header: SequencesSection.Header
Source
pub fn prepare(
self: *DecodeState,
source: anytype,
literals: LiteralsSection,
sequences_header: SequencesSection.Header,
) !void {
self.literal_written_count = 0;
self.literal_header = literals.header;
self.literal_streams = literals.streams;
if (literals.huffman_tree) |tree| {
self.huffman_tree = tree;
} else if (literals.header.block_type == .treeless and self.huffman_tree == null) {
return error.TreelessLiteralsFirst;
}
switch (literals.header.block_type) {
.raw, .rle => {},
.compressed, .treeless => {
self.literal_stream_index = 0;
switch (literals.streams) {
.one => |slice| try self.initLiteralStream(slice),
.four => |streams| try self.initLiteralStream(streams[0]),
}
},
}
if (sequences_header.sequence_count > 0) {
try self.updateFseTable(source, .literal, sequences_header.literal_lengths);
try self.updateFseTable(source, .offset, sequences_header.offsets);
try self.updateFseTable(source, .match, sequences_header.match_lengths);
self.fse_tables_undefined = false;
}
}