| ... | ... | @@ -14,8 +14,6 @@ fn readVarInt(comptime T: type, bytes: []const u8) T { |
| 14 | 14 | return std.mem.readVarInt(T, bytes, .Little); |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | | const log = std.log.scoped(.Decompress); |
| 18 | | |
| 19 | 17 | fn isSkippableMagic(magic: u32) bool { |
| 20 | 18 | return frame.Skippable.magic_number_min <= magic and magic <= frame.Skippable.magic_number_max; |
| 21 | 19 | } |
| ... | ... | @@ -136,11 +134,6 @@ pub const DecodeState = struct { |
| 136 | 134 | self.literal.state = try bit_reader.readBitsNoEof(u9, self.literal.accuracy_log); |
| 137 | 135 | self.offset.state = try bit_reader.readBitsNoEof(u8, self.offset.accuracy_log); |
| 138 | 136 | self.match.state = try bit_reader.readBitsNoEof(u9, self.match.accuracy_log); |
| 139 | | log.debug("initial decoder state: literal = {d}, offset = {d} match = {d}", .{ |
| 140 | | self.literal.state, |
| 141 | | self.offset.state, |
| 142 | | self.match.state, |
| 143 | | }); |
| 144 | 137 | } |
| 145 | 138 | |
| 146 | 139 | fn updateRepeatOffset(self: *DecodeState, offset: u32) void { |
| ... | ... | @@ -208,10 +201,6 @@ pub const DecodeState = struct { |
| 208 | 201 | ); |
| 209 | 202 | @field(self, field_name).table = .{ .fse = @field(self, field_name ++ "_fse_buffer")[0..table_size] }; |
| 210 | 203 | @field(self, field_name).accuracy_log = std.math.log2_int_ceil(usize, table_size); |
| 211 | | log.debug("decoded fse " ++ field_name ++ " table '{}'", .{ |
| 212 | | std.fmt.fmtSliceHexUpper(src[0..counting_reader.bytes_read]), |
| 213 | | }); |
| 214 | | dumpFseTable(field_name, @field(self, field_name).table.fse); |
| 215 | 204 | return counting_reader.bytes_read; |
| 216 | 205 | }, |
| 217 | 206 | .repeat => return if (self.fse_tables_undefined) error.RepeatModeFirst else 0, |
| ... | ... | @@ -227,7 +216,6 @@ pub const DecodeState = struct { |
| 227 | 216 | fn nextSequence(self: *DecodeState, bit_reader: anytype) !Sequence { |
| 228 | 217 | const raw_code = self.getCode(.offset); |
| 229 | 218 | const offset_code = std.math.cast(u5, raw_code) orelse { |
| 230 | | log.err("got offset code of {d}", .{raw_code}); |
| 231 | 219 | return error.OffsetCodeTooLarge; |
| 232 | 220 | }; |
| 233 | 221 | const offset_value = (@as(u32, 1) << offset_code) + try bit_reader.readBitsNoEof(u32, offset_code); |
| ... | ... | @@ -256,7 +244,6 @@ pub const DecodeState = struct { |
| 256 | 244 | break :offset self.useRepeatOffset(offset_value - 1); |
| 257 | 245 | }; |
| 258 | 246 | |
| 259 | | log.debug("sequence = ({d}, {d}, {d})", .{ literal_length, offset, match_length }); |
| 260 | 247 | return .{ |
| 261 | 248 | .literal_length = literal_length, |
| 262 | 249 | .match_length = match_length, |
| ... | ... | @@ -310,9 +297,6 @@ pub const DecodeState = struct { |
| 310 | 297 | if (sequence_length > sequence_size_limit) return error.MalformedSequence; |
| 311 | 298 | |
| 312 | 299 | try self.executeSequenceSlice(dest, write_pos, literals, sequence); |
| 313 | | log.debug("sequence decompressed into '{x}'", .{ |
| 314 | | std.fmt.fmtSliceHexUpper(dest[write_pos .. write_pos + sequence.literal_length + sequence.match_length]), |
| 315 | | }); |
| 316 | 300 | if (!last_sequence) { |
| 317 | 301 | try self.updateState(.literal, bit_reader); |
| 318 | 302 | try self.updateState(.match, bit_reader); |
| ... | ... | @@ -334,13 +318,6 @@ pub const DecodeState = struct { |
| 334 | 318 | if (sequence_length > sequence_size_limit) return error.MalformedSequence; |
| 335 | 319 | |
| 336 | 320 | try self.executeSequenceRingBuffer(dest, literals, sequence); |
| 337 | | if (std.options.log_level == .debug) { |
| 338 | | const written_slice = dest.sliceLast(sequence_length); |
| 339 | | log.debug("sequence decompressed into '{x}{x}'", .{ |
| 340 | | std.fmt.fmtSliceHexUpper(written_slice.first), |
| 341 | | std.fmt.fmtSliceHexUpper(written_slice.second), |
| 342 | | }); |
| 343 | | } |
| 344 | 321 | if (!last_sequence) { |
| 345 | 322 | try self.updateState(.literal, bit_reader); |
| 346 | 323 | try self.updateState(.match, bit_reader); |
| ... | ... | @@ -355,7 +332,6 @@ pub const DecodeState = struct { |
| 355 | 332 | } |
| 356 | 333 | |
| 357 | 334 | fn initLiteralStream(self: *DecodeState, bytes: []const u8) !void { |
| 358 | | log.debug("initing literal stream: {}", .{std.fmt.fmtSliceHexUpper(bytes)}); |
| 359 | 335 | try self.literal_stream_reader.init(bytes); |
| 360 | 336 | } |
| 361 | 337 | |
| ... | ... | @@ -372,7 +348,6 @@ pub const DecodeState = struct { |
| 372 | 348 | while (i < len) : (i += 1) { |
| 373 | 349 | dest[i] = literals.streams.one[0]; |
| 374 | 350 | } |
| 375 | | log.debug("rle: {}", .{std.fmt.fmtSliceHexUpper(dest[0..len])}); |
| 376 | 351 | self.literal_written_count += len; |
| 377 | 352 | }, |
| 378 | 353 | .compressed, .treeless => { |
| ... | ... | @@ -538,7 +513,6 @@ pub fn decodeZStandardFrame(dest: []u8, src: []const u8, verify_checksum: bool) |
| 538 | 513 | const hash = hash_state.final(); |
| 539 | 514 | const hash_low_bytes = hash & 0xFFFFFFFF; |
| 540 | 515 | if (checksum != hash_low_bytes) { |
| 541 | | std.log.err("expected checksum {x}, got {x} (full hash {x})", .{ checksum, hash_low_bytes, hash }); |
| 542 | 516 | return error.ChecksumFailure; |
| 543 | 517 | } |
| 544 | 518 | } |
| ... | ... | @@ -556,13 +530,11 @@ pub fn decodeZStandardFrameAlloc(allocator: std.mem.Allocator, src: []const u8, |
| 556 | 530 | if (frame_header.descriptor.dictionary_id_flag != 0) return error.DictionaryIdFlagUnsupported; |
| 557 | 531 | |
| 558 | 532 | const window_size = frameWindowSize(frame_header) orelse return error.WindowSizeUnknown; |
| 559 | | log.debug("window size = {d}", .{window_size}); |
| 560 | 533 | |
| 561 | 534 | const should_compute_checksum = frame_header.descriptor.content_checksum_flag and verify_checksum; |
| 562 | 535 | var hash = if (should_compute_checksum) std.hash.XxHash64.init(0) else null; |
| 563 | 536 | |
| 564 | 537 | const block_size_maximum = @min(1 << 17, window_size); |
| 565 | | log.debug("block size maximum = {d}", .{block_size_maximum}); |
| 566 | 538 | |
| 567 | 539 | var window_data = try allocator.alloc(u8, window_size); |
| 568 | 540 | defer allocator.free(window_data); |
| ... | ... | @@ -680,7 +652,6 @@ pub fn decodeFrameBlocks(dest: []u8, src: []const u8, consumed_count: *usize, ha |
| 680 | 652 | |
| 681 | 653 | fn decodeRawBlock(dest: []u8, src: []const u8, block_size: u21, consumed_count: *usize) !usize { |
| 682 | 654 | if (src.len < block_size) return error.MalformedBlockSize; |
| 683 | | log.debug("writing raw block - size {d}", .{block_size}); |
| 684 | 655 | const data = src[0..block_size]; |
| 685 | 656 | std.mem.copy(u8, dest, data); |
| 686 | 657 | consumed_count.* += block_size; |
| ... | ... | @@ -689,7 +660,6 @@ fn decodeRawBlock(dest: []u8, src: []const u8, block_size: u21, consumed_count: |
| 689 | 660 | |
| 690 | 661 | fn decodeRawBlockRingBuffer(dest: *RingBuffer, src: []const u8, block_size: u21, consumed_count: *usize) !usize { |
| 691 | 662 | if (src.len < block_size) return error.MalformedBlockSize; |
| 692 | | log.debug("writing raw block - size {d}", .{block_size}); |
| 693 | 663 | const data = src[0..block_size]; |
| 694 | 664 | dest.writeSliceAssumeCapacity(data); |
| 695 | 665 | consumed_count.* += block_size; |
| ... | ... | @@ -698,7 +668,6 @@ fn decodeRawBlockRingBuffer(dest: *RingBuffer, src: []const u8, block_size: u21, |
| 698 | 668 | |
| 699 | 669 | fn decodeRleBlock(dest: []u8, src: []const u8, block_size: u21, consumed_count: *usize) !usize { |
| 700 | 670 | if (src.len < 1) return error.MalformedRleBlock; |
| 701 | | log.debug("writing rle block - '{x}'x{d}", .{ src[0], block_size }); |
| 702 | 671 | var write_pos: usize = 0; |
| 703 | 672 | while (write_pos < block_size) : (write_pos += 1) { |
| 704 | 673 | dest[write_pos] = src[0]; |
| ... | ... | @@ -709,7 +678,6 @@ fn decodeRleBlock(dest: []u8, src: []const u8, block_size: u21, consumed_count: |
| 709 | 678 | |
| 710 | 679 | fn decodeRleBlockRingBuffer(dest: *RingBuffer, src: []const u8, block_size: u21, consumed_count: *usize) !usize { |
| 711 | 680 | if (src.len < 1) return error.MalformedRleBlock; |
| 712 | | log.debug("writing rle block - '{x}'x{d}", .{ src[0], block_size }); |
| 713 | 681 | var write_pos: usize = 0; |
| 714 | 682 | while (write_pos < block_size) : (write_pos += 1) { |
| 715 | 683 | dest.writeAssumeCapacity(src[0]); |
| ... | ... | @@ -751,7 +719,6 @@ pub fn decodeBlock( |
| 751 | 719 | var sequence_size_limit = block_size_max; |
| 752 | 720 | var i: usize = 0; |
| 753 | 721 | while (i < sequences_header.sequence_count) : (i += 1) { |
| 754 | | log.debug("decoding sequence {d}", .{i}); |
| 755 | 722 | const write_pos = written_count + bytes_written; |
| 756 | 723 | const decompressed_size = try decode_state.decodeSequenceSlice( |
| 757 | 724 | dest, |
| ... | ... | @@ -769,13 +736,8 @@ pub fn decodeBlock( |
| 769 | 736 | } |
| 770 | 737 | |
| 771 | 738 | if (decode_state.literal_written_count < literals.header.regenerated_size) { |
| 772 | | log.debug("decoding remaining literals", .{}); |
| 773 | 739 | const len = literals.header.regenerated_size - decode_state.literal_written_count; |
| 774 | 740 | try decode_state.decodeLiteralsSlice(dest[written_count + bytes_written ..], literals, len); |
| 775 | | log.debug("remaining decoded literals at {d}: {}", .{ |
| 776 | | written_count, |
| 777 | | std.fmt.fmtSliceHexUpper(dest[written_count .. written_count + len]), |
| 778 | | }); |
| 779 | 741 | bytes_written += len; |
| 780 | 742 | } |
| 781 | 743 | |
| ... | ... | @@ -820,7 +782,6 @@ pub fn decodeBlockRingBuffer( |
| 820 | 782 | var sequence_size_limit = block_size_max; |
| 821 | 783 | var i: usize = 0; |
| 822 | 784 | while (i < sequences_header.sequence_count) : (i += 1) { |
| 823 | | log.debug("decoding sequence {d}", .{i}); |
| 824 | 785 | const decompressed_size = try decode_state.decodeSequenceRingBuffer( |
| 825 | 786 | dest, |
| 826 | 787 | literals, |
| ... | ... | @@ -836,15 +797,8 @@ pub fn decodeBlockRingBuffer( |
| 836 | 797 | } |
| 837 | 798 | |
| 838 | 799 | if (decode_state.literal_written_count < literals.header.regenerated_size) { |
| 839 | | log.debug("decoding remaining literals", .{}); |
| 840 | 800 | const len = literals.header.regenerated_size - decode_state.literal_written_count; |
| 841 | 801 | try decode_state.decodeLiteralsRingBuffer(dest, literals, len); |
| 842 | | const written_slice = dest.sliceLast(len); |
| 843 | | log.debug("remaining decoded literals at {d}: {}{}", .{ |
| 844 | | bytes_written, |
| 845 | | std.fmt.fmtSliceHexUpper(written_slice.first), |
| 846 | | std.fmt.fmtSliceHexUpper(written_slice.second), |
| 847 | | }); |
| 848 | 802 | bytes_written += len; |
| 849 | 803 | } |
| 850 | 804 | |
| ... | ... | @@ -922,22 +876,6 @@ pub fn decodeZStandardHeader(src: []const u8, consumed_count: ?*usize) !frame.ZS |
| 922 | 876 | .dictionary_id = dictionary_id, |
| 923 | 877 | .content_size = content_size, |
| 924 | 878 | }; |
| 925 | | log.debug( |
| 926 | | "decoded ZStandard frame header {x}: " ++ |
| 927 | | "desc = (d={d},c={},r={},u={},s={},cs={d}), win_desc = {?x}, dict_id = {?x}, content_size = {?d}", |
| 928 | | .{ |
| 929 | | std.fmt.fmtSliceHexUpper(src[0..bytes_read_count]), |
| 930 | | header.descriptor.dictionary_id_flag, |
| 931 | | header.descriptor.content_checksum_flag, |
| 932 | | header.descriptor.reserved, |
| 933 | | header.descriptor.unused, |
| 934 | | header.descriptor.single_segment_flag, |
| 935 | | header.descriptor.content_size_flag, |
| 936 | | header.window_descriptor, |
| 937 | | header.dictionary_id, |
| 938 | | header.content_size, |
| 939 | | }, |
| 940 | | ); |
| 941 | 879 | return header; |
| 942 | 880 | } |
| 943 | 881 | |
| ... | ... | @@ -945,12 +883,6 @@ pub fn decodeBlockHeader(src: *const [3]u8) frame.ZStandard.Block.Header { |
| 945 | 883 | const last_block = src[0] & 1 == 1; |
| 946 | 884 | const block_type = @intToEnum(frame.ZStandard.Block.Type, (src[0] & 0b110) >> 1); |
| 947 | 885 | const block_size = ((src[0] & 0b11111000) >> 3) + (@as(u21, src[1]) << 5) + (@as(u21, src[2]) << 13); |
| 948 | | log.debug("decoded block header {}: last = {}, type = {s}, size = {d}", .{ |
| 949 | | std.fmt.fmtSliceHexUpper(src), |
| 950 | | last_block, |
| 951 | | @tagName(block_type), |
| 952 | | block_size, |
| 953 | | }); |
| 954 | 886 | return .{ |
| 955 | 887 | .last_block = last_block, |
| 956 | 888 | .block_type = block_type, |
| ... | ... | @@ -990,8 +922,6 @@ pub fn decodeLiteralsSection(src: []const u8, consumed_count: *usize) !LiteralsS |
| 990 | 922 | null; |
| 991 | 923 | const huffman_tree_size = bytes_read - huffman_tree_start; |
| 992 | 924 | const total_streams_size = @as(usize, header.compressed_size.?) - huffman_tree_size; |
| 993 | | log.debug("huffman tree size = {}, total streams size = {}", .{ huffman_tree_size, total_streams_size }); |
| 994 | | if (huffman_tree) |tree| dumpHuffmanTree(tree); |
| 995 | 925 | |
| 996 | 926 | if (src.len < bytes_read + total_streams_size) return error.MalformedLiteralsSection; |
| 997 | 927 | const stream_data = src[bytes_read .. bytes_read + total_streams_size]; |
| ... | ... | @@ -1007,7 +937,6 @@ pub fn decodeLiteralsSection(src: []const u8, consumed_count: *usize) !LiteralsS |
| 1007 | 937 | |
| 1008 | 938 | if (stream_data.len < 6) return error.MalformedLiteralsSection; |
| 1009 | 939 | |
| 1010 | | log.debug("jump table: {}", .{std.fmt.fmtSliceHexUpper(stream_data[0..6])}); |
| 1011 | 940 | const stream_1_length = @as(usize, readInt(u16, stream_data[0..2])); |
| 1012 | 941 | const stream_2_length = @as(usize, readInt(u16, stream_data[2..4])); |
| 1013 | 942 | const stream_3_length = @as(usize, readInt(u16, stream_data[4..6])); |
| ... | ... | @@ -1059,8 +988,6 @@ fn decodeHuffmanTree(src: []const u8, consumed_count: *usize) !LiteralsSection.H |
| 1059 | 988 | var huff_bits: ReverseBitReader = undefined; |
| 1060 | 989 | try huff_bits.init(huff_data); |
| 1061 | 990 | |
| 1062 | | dumpFseTable("huffman", entries[0..table_size]); |
| 1063 | | |
| 1064 | 991 | var i: usize = 0; |
| 1065 | 992 | var even_state: u32 = try huff_bits.readBitsNoEof(u32, accuracy_log); |
| 1066 | 993 | var odd_state: u32 = try huff_bits.readBitsNoEof(u32, accuracy_log); |
| ... | ... | @@ -1073,7 +1000,6 @@ fn decodeHuffmanTree(src: []const u8, consumed_count: *usize) !LiteralsSection.H |
| 1073 | 1000 | i += 1; |
| 1074 | 1001 | if (read_bits < even_data.bits) { |
| 1075 | 1002 | weights[i] = std.math.cast(u4, entries[odd_state].symbol) orelse return error.MalformedHuffmanTree; |
| 1076 | | log.debug("overflow condition: setting weights[{d}] = {d}", .{ i, weights[i] }); |
| 1077 | 1003 | i += 1; |
| 1078 | 1004 | break; |
| 1079 | 1005 | } |
| ... | ... | @@ -1087,7 +1013,6 @@ fn decodeHuffmanTree(src: []const u8, consumed_count: *usize) !LiteralsSection.H |
| 1087 | 1013 | if (read_bits < odd_data.bits) { |
| 1088 | 1014 | if (i == 256) return error.MalformedHuffmanTree; |
| 1089 | 1015 | weights[i] = std.math.cast(u4, entries[even_state].symbol) orelse return error.MalformedHuffmanTree; |
| 1090 | | log.debug("overflow condition: setting weights[{d}] = {d}", .{ i, weights[i] }); |
| 1091 | 1016 | i += 1; |
| 1092 | 1017 | break; |
| 1093 | 1018 | } |
| ... | ... | @@ -1099,19 +1024,12 @@ fn decodeHuffmanTree(src: []const u8, consumed_count: *usize) !LiteralsSection.H |
| 1099 | 1024 | } else { |
| 1100 | 1025 | const encoded_symbol_count = header - 127; |
| 1101 | 1026 | symbol_count = encoded_symbol_count + 1; |
| 1102 | | log.debug("huffman tree symbol count = {d}", .{symbol_count}); |
| 1103 | 1027 | const weights_byte_count = (encoded_symbol_count + 1) / 2; |
| 1104 | | log.debug("decoding direct huffman tree: {}|{}", .{ |
| 1105 | | std.fmt.fmtSliceHexUpper(src[0..1]), |
| 1106 | | std.fmt.fmtSliceHexUpper(src[1 .. weights_byte_count + 1]), |
| 1107 | | }); |
| 1108 | 1028 | if (src.len < weights_byte_count) return error.MalformedHuffmanTree; |
| 1109 | 1029 | var i: usize = 0; |
| 1110 | 1030 | while (i < weights_byte_count) : (i += 1) { |
| 1111 | 1031 | weights[2 * i] = @intCast(u4, src[i + 1] >> 4); |
| 1112 | 1032 | weights[2 * i + 1] = @intCast(u4, src[i + 1] & 0xF); |
| 1113 | | log.debug("weights[{d}] = {d}", .{ 2 * i, weights[2 * i] }); |
| 1114 | | log.debug("weights[{d}] = {d}", .{ 2 * i + 1, weights[2 * i + 1] }); |
| 1115 | 1033 | } |
| 1116 | 1034 | bytes_read += weights_byte_count; |
| 1117 | 1035 | } |
| ... | ... | @@ -1121,13 +1039,11 @@ fn decodeHuffmanTree(src: []const u8, consumed_count: *usize) !LiteralsSection.H |
| 1121 | 1039 | weight_power_sum += @as(u16, 1) << (value - 1); |
| 1122 | 1040 | } |
| 1123 | 1041 | } |
| 1124 | | log.debug("weight power sum = {d}", .{weight_power_sum}); |
| 1125 | 1042 | |
| 1126 | 1043 | // advance to next power of two (even if weight_power_sum is a power of 2) |
| 1127 | 1044 | max_number_of_bits = std.math.log2_int(u16, weight_power_sum) + 1; |
| 1128 | 1045 | const next_power_of_two = @as(u16, 1) << max_number_of_bits; |
| 1129 | 1046 | weights[symbol_count - 1] = std.math.log2_int(u16, next_power_of_two - weight_power_sum) + 1; |
| 1130 | | log.debug("weights[{d}] = {d}", .{ symbol_count - 1, weights[symbol_count - 1] }); |
| 1131 | 1047 | |
| 1132 | 1048 | var weight_sorted_prefixed_symbols: [256]LiteralsSection.HuffmanTree.PrefixedSymbol = undefined; |
| 1133 | 1049 | for (weight_sorted_prefixed_symbols[0..symbol_count]) |_, i| { |
| ... | ... | @@ -1177,7 +1093,6 @@ fn decodeHuffmanTree(src: []const u8, consumed_count: *usize) !LiteralsSection.H |
| 1177 | 1093 | .symbol_count_minus_one = @intCast(u8, prefixed_symbol_count - 1), |
| 1178 | 1094 | .nodes = weight_sorted_prefixed_symbols, |
| 1179 | 1095 | }; |
| 1180 | | log.debug("decoded huffman tree {}:", .{std.fmt.fmtSliceHexUpper(src[0..bytes_read])}); |
| 1181 | 1096 | return tree; |
| 1182 | 1097 | } |
| 1183 | 1098 | |
| ... | ... | @@ -1194,7 +1109,6 @@ fn lessThanByWeight( |
| 1194 | 1109 | |
| 1195 | 1110 | pub fn decodeLiteralsHeader(src: []const u8, consumed_count: *usize) !LiteralsSection.Header { |
| 1196 | 1111 | if (src.len == 0) return error.MalformedLiteralsSection; |
| 1197 | | const start = consumed_count.*; |
| 1198 | 1112 | const byte0 = src[0]; |
| 1199 | 1113 | const block_type = @intToEnum(LiteralsSection.BlockType, byte0 & 0b11); |
| 1200 | 1114 | const size_format = @intCast(u2, (byte0 & 0b1100) >> 2); |
| ... | ... | @@ -1250,16 +1164,6 @@ pub fn decodeLiteralsHeader(src: []const u8, consumed_count: *usize) !LiteralsSe |
| 1250 | 1164 | } |
| 1251 | 1165 | }, |
| 1252 | 1166 | } |
| 1253 | | log.debug( |
| 1254 | | "decoded literals section header '{}': type = {s}, size_format = {}, regen_size = {d}, compressed size = {?d}", |
| 1255 | | .{ |
| 1256 | | std.fmt.fmtSliceHexUpper(src[0 .. consumed_count.* - start]), |
| 1257 | | @tagName(block_type), |
| 1258 | | size_format, |
| 1259 | | regenerated_size, |
| 1260 | | compressed_size, |
| 1261 | | }, |
| 1262 | | ); |
| 1263 | 1167 | return LiteralsSection.Header{ |
| 1264 | 1168 | .block_type = block_type, |
| 1265 | 1169 | .size_format = size_format, |
| ... | ... | @@ -1276,7 +1180,6 @@ pub fn decodeSequencesHeader(src: []const u8, consumed_count: *usize) !Sequences |
| 1276 | 1180 | const byte0 = src[0]; |
| 1277 | 1181 | if (byte0 == 0) { |
| 1278 | 1182 | bytes_read += 1; |
| 1279 | | log.debug("decoded sequences header '{}': sequence count = 0", .{std.fmt.fmtSliceHexUpper(src[0..bytes_read])}); |
| 1280 | 1183 | consumed_count.* += bytes_read; |
| 1281 | 1184 | return SequencesSection.Header{ |
| 1282 | 1185 | .sequence_count = 0, |
| ... | ... | @@ -1305,13 +1208,6 @@ pub fn decodeSequencesHeader(src: []const u8, consumed_count: *usize) !Sequences |
| 1305 | 1208 | const matches_mode = @intToEnum(SequencesSection.Header.Mode, (compression_modes & 0b00001100) >> 2); |
| 1306 | 1209 | const offsets_mode = @intToEnum(SequencesSection.Header.Mode, (compression_modes & 0b00110000) >> 4); |
| 1307 | 1210 | const literal_mode = @intToEnum(SequencesSection.Header.Mode, (compression_modes & 0b11000000) >> 6); |
| 1308 | | log.debug("decoded sequences header '{}': (sc={d},o={s},m={s},l={s})", .{ |
| 1309 | | std.fmt.fmtSliceHexUpper(src[0..bytes_read]), |
| 1310 | | sequence_count, |
| 1311 | | @tagName(offsets_mode), |
| 1312 | | @tagName(matches_mode), |
| 1313 | | @tagName(literal_mode), |
| 1314 | | }); |
| 1315 | 1211 | if (compression_modes & 0b11 != 0) return error.ReservedBitSet; |
| 1316 | 1212 | |
| 1317 | 1213 | return SequencesSection.Header{ |
| ... | ... | @@ -1383,10 +1279,7 @@ fn decodeFseTable( |
| 1383 | 1279 | max_accuracy_log: u4, |
| 1384 | 1280 | entries: []Table.Fse, |
| 1385 | 1281 | ) !usize { |
| 1386 | | log.debug("decoding fse table {d} {d}", .{ max_accuracy_log, expected_symbol_count }); |
| 1387 | | |
| 1388 | 1282 | const accuracy_log_biased = try bit_reader.readBitsNoEof(u4, 4); |
| 1389 | | log.debug("accuracy_log_biased = {d}", .{accuracy_log_biased}); |
| 1390 | 1283 | if (accuracy_log_biased > max_accuracy_log -| 5) return error.MalformedAccuracyLog; |
| 1391 | 1284 | const accuracy_log = accuracy_log_biased + 5; |
| 1392 | 1285 | |
| ... | ... | @@ -1394,7 +1287,6 @@ fn decodeFseTable( |
| 1394 | 1287 | var value_count: usize = 0; |
| 1395 | 1288 | |
| 1396 | 1289 | const total_probability = @as(u16, 1) << accuracy_log; |
| 1397 | | log.debug("total probability = {d}", .{total_probability}); |
| 1398 | 1290 | var accumulated_probability: u16 = 0; |
| 1399 | 1291 | |
| 1400 | 1292 | while (accumulated_probability < total_probability) { |
| ... | ... | @@ -1549,17 +1441,3 @@ test buildFseTable { |
| 1549 | 1441 | try buildFseTable(&offset_codes_default_values, entries[0..32]); |
| 1550 | 1442 | try std.testing.expectEqualSlices(Table.Fse, types.compressed_block.predefined_offset_fse_table.fse, entries[0..32]); |
| 1551 | 1443 | } |
| 1552 | | |
| 1553 | | fn dumpFseTable(prefix: []const u8, table: []const Table.Fse) void { |
| 1554 | | log.debug("{s} fse table:", .{prefix}); |
| 1555 | | for (table) |entry, i| { |
| 1556 | | log.debug("state = {d} symbol = {d} bl = {d}, bits = {d}", .{ i, entry.symbol, entry.baseline, entry.bits }); |
| 1557 | | } |
| 1558 | | } |
| 1559 | | |
| 1560 | | fn dumpHuffmanTree(tree: LiteralsSection.HuffmanTree) void { |
| 1561 | | log.debug("Huffman tree: max bit count = {}, symbol count = {}", .{ tree.max_bit_count, tree.symbol_count_minus_one + 1 }); |
| 1562 | | for (tree.nodes[0 .. tree.symbol_count_minus_one + 1]) |node| { |
| 1563 | | log.debug("symbol = {[symbol]d}, prefix = {[prefix]d}, weight = {[weight]d}", node); |
| 1564 | | } |
| 1565 | | } |