Function decodeLiteralsSection [src]

Decode a LiteralsSection from src, incrementing consumed_count by the number of bytes the section uses. See decodeLiterasSectionSlice().

Prototype

pub fn decodeLiteralsSection( source: anytype, buffer: []u8, ) !LiteralsSection

Parameters

buffer: []u8

Source

pub fn decodeLiteralsSection( source: anytype, buffer: []u8, ) !LiteralsSection { const header = try decodeLiteralsHeader(source); switch (header.block_type) { .raw => { try source.readNoEof(buffer[0..header.regenerated_size]); return LiteralsSection{ .header = header, .huffman_tree = null, .streams = .{ .one = buffer }, }; }, .rle => { buffer[0] = try source.readByte(); return LiteralsSection{ .header = header, .huffman_tree = null, .streams = .{ .one = buffer[0..1] }, }; }, .compressed, .treeless => { var counting_reader = std.io.countingReader(source); const huffman_tree = if (header.block_type == .compressed) try huffman.decodeHuffmanTree(counting_reader.reader(), buffer) else null; const huffman_tree_size = @as(usize, @intCast(counting_reader.bytes_read)); const total_streams_size = std.math.sub(usize, header.compressed_size.?, huffman_tree_size) catch return error.MalformedLiteralsSection; if (total_streams_size > buffer.len) return error.LiteralsBufferTooSmall; try source.readNoEof(buffer[0..total_streams_size]); const stream_data = buffer[0..total_streams_size]; const streams = try decodeStreams(header.size_format, stream_data); return LiteralsSection{ .header = header, .huffman_tree = huffman_tree, .streams = streams, }; }, } }