Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › compress › zstd › Decompress › Frame › Zstandard › Decode › decodeLiterals Private Function decodeLiterals Doc Source Private Function std.compress.zstd.Decompress.Frame.Zstandard.Decode.decodeLiterals
fn decodeLiterals (d : *Decode , w : *Writer , len : usize ) !void Params File compress/zstd/Decompress.zig: 843
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892 fn decodeLiterals (d : *Decode , w : *Writer , len : usize ) !void {
switch (d .literal_header .block_type ) {
.raw => {
try w .writeAll (d .literal_streams .one [d .literal_written_count ..][0 ..len ]);
},
.rle => {
try w .splatByteAll (d .literal_streams .one [0 ], len );
},
.compressed , .treeless => {
const buf = try w .writableSlice (len );
const huffman_tree = d .huffman_tree .?;
const max_bit_count = huffman_tree .max_bit_count ;
const starting_bit_count = LiteralsSection .HuffmanTree .weightToBitCount (
huffman_tree .nodes [huffman_tree .symbol_count_minus_one ].weight ,
max_bit_count ,
);
var bits_read : u4 = 0 ;
var huffman_tree_index : usize = huffman_tree .symbol_count_minus_one ;
var bit_count_to_read : u4 = starting_bit_count ;
for (buf ) |*out | {
var prefix : u16 = 0 ;
while (true ) {
const new_bits = try d .readLiteralsBits (bit_count_to_read );
prefix <<= bit_count_to_read ;
prefix |= new_bits ;
bits_read += bit_count_to_read ;
const result = try huffman_tree .query (huffman_tree_index , prefix );
switch (result ) {
.symbol => |sym | {
out .* = sym ;
bit_count_to_read = starting_bit_count ;
bits_read = 0 ;
huffman_tree_index = huffman_tree .symbol_count_minus_one ;
break ;
},
.index => |index | {
huffman_tree_index = index ;
const bit_count = LiteralsSection .HuffmanTree .weightToBitCount (
huffman_tree .nodes [index ].weight ,
max_bit_count ,
);
bit_count_to_read = bit_count - bits_read ;
},
}
}
}
},
}
}
Decode
lenbytes of literals intow.