Rename std/flate's decoder to flate_decoder.

This commit is contained in:
Nigel Tao committed 2017-10-21 13:05:19 +11:00
1 parent 1c75edb32e
commit 2639f8f46a
8 files changed
+132 -119

No files matched your search

+20 -19
View File
@@ -33,9 +33,9 @@ pub error "no Huffman codes"
// The next two tables were created by script/print-flate-magic-numbers.go.
//
// The u32 values' meanings are the same as the decoder.huffs u32 values. In
// particular, bit 30 indicates a base number + extra bits, bits 23-8 are the
// base number and bits 7-4 are the number of those extra bits.
// The u32 values' meanings are the same as the flate_decoder.huffs u32 values.
// In particular, bit 30 indicates a base number + extra bits, bits 23-8 are
// the base number and bits 7-4 are the number of those extra bits.
//
// Some trailing elements are 0x08000000. Bit 27 indicates an invalid value.
@@ -53,7 +53,7 @@ pri const dcode_magic_numbers[32] u32 = $(
0x401001B0, 0x401801B0, 0x402001C0, 0x403001C0, 0x404001D0, 0x406001D0, 0x08000000, 0x08000000,
)
pub struct decoder?(
pub struct flate_decoder?(
// These fields yield src's bits in Least Significant Bits order.
bits u32,
n_bits u32,
@@ -65,16 +65,17 @@ pub struct decoder?(
// - huffs[0] is used for clcode and lcode.
// - huffs[1] is used for dcode.
//
// The initial table key is the low n_huffs_bits of the decoder.bits field.
// Keys longer than 9 bits require a two step lookup, the first step
// The initial table key is the low n_huffs_bits of the flate_decoder.bits
// field. Keys longer than 9 bits require a two step lookup, the first step
// examines the low 9 bits, the second step examines the remaining bits.
// Two steps are required at most, as keys are at most 15 bits long.
//
// Using decoder.bits's low n_huffs_bits as a table key is valid even if
// decoder.n_bits is less than n_huffs_bits, because the immediate next
// step after indexing the table by the key is to compare decoder.n_bits to
// the table value's number of decoder.bits to consume. If it compares
// less, then more source bytes are read and the table lookup re-tried.
// Using flate_decoder.bits's low n_huffs_bits as a table key is valid even
// if flate_decoder.n_bits is less than n_huffs_bits, because the immediate
// next step after indexing the table by the key is to compare
// flate_decoder.n_bits to the table value's number of flate_decoder.bits
// to consume. If it compares less, then more source bytes are read and the
// table lookup re-tried.
//
// The table value is:
// - bit 31 indicates the symbol is a literal.
@@ -85,7 +86,7 @@ pub struct decoder?(
// - bits 26-24 are zero.
// - bits 23- 8 is the redirect offset, literal (in bits 15-8) or base number.
// - bits 7- 4 is the redirected table's bits or number of extra bits.
// - bits 3- 0 are the number of decoder.bits to consume.
// - bits 3- 0 are the number of flate_decoder.bits to consume.
//
// Exactly one of the eight bits 31-24 should be set.
//
@@ -114,7 +115,7 @@ pub struct decoder?(
code_lengths[320] u8[..15],
)
pub func decoder.decode?(dst writer1, src reader1)() {
pub func flate_decoder.decode?(dst writer1, src reader1)() {
while true {
var z status = try this.decode_blocks?(dst:in.dst, src:in.src)
if not z.is_suspension() {
@@ -168,7 +169,7 @@ pub func decoder.decode?(dst writer1, src reader1)() {
}
}
pri func decoder.decode_blocks?(dst writer1, src reader1)() {
pri func flate_decoder.decode_blocks?(dst writer1, src reader1)() {
var final u32
while final == 0 {
while this.n_bits < 3,
@@ -198,7 +199,7 @@ pri func decoder.decode_blocks?(dst writer1, src reader1)() {
// decode_uncompressed decodes an uncompresed block as per the RFC section
// 3.2.4.
pri func decoder.decode_uncompressed?(dst writer1, src reader1)() {
pri func flate_decoder.decode_uncompressed?(dst writer1, src reader1)() {
if this.n_bits >= 8 {
return error "internal error: inconsistent n_bits"
}
@@ -225,7 +226,7 @@ pri func decoder.decode_uncompressed?(dst writer1, src reader1)() {
}
}
pri func decoder.decode_huffman?(dst writer1, src reader1)() {
pri func flate_decoder.decode_huffman?(dst writer1, src reader1)() {
var bits u32 = this.bits
var n_bits u32 = this.n_bits
@@ -444,7 +445,7 @@ pri func decoder.decode_huffman?(dst writer1, src reader1)() {
}
// init_fixed_huffman initializes this.huffs as per the RFC section 3.2.6.
pri func decoder.init_fixed_huffman?()() {
pri func flate_decoder.init_fixed_huffman?()() {
var i u32
while i < 144 {
this.code_lengths[i] = 8
@@ -471,7 +472,7 @@ pri func decoder.init_fixed_huffman?()() {
}
// init_dynamic_huffman initializes this.huffs as per the RFC section 3.2.7.
pri func decoder.init_dynamic_huffman?(src reader1)() {
pri func flate_decoder.init_dynamic_huffman?(src reader1)() {
var bits u32 = this.bits
var n_bits u32 = this.n_bits
while n_bits < 14,
@@ -621,7 +622,7 @@ pri func decoder.init_dynamic_huffman?(src reader1)() {
// TODO: skip generating PUFFS_COROUTINE_SUSPENSION_POINTs for *callers* of
// this function, as it can only return errors, not suspensions.
pri func decoder.init_huff?(which u32[..1], n_codes0 u32[..320], n_codes1 u32[..320], base_symbol u32)() {
pri func flate_decoder.init_huff?(which u32[..1], n_codes0 u32[..320], n_codes1 u32[..320], base_symbol u32)() {
// For the clcode example in this package's README.md:
// - n_codes0 = 0
// - n_codes1 = 19
+2 -2
View File
@@ -19,7 +19,7 @@ pub error "invalid zlib parity check"
pub error "TODO: unsupported zlib preset dictionary"
pub struct zlib_decoder?(
dec decoder,
flate flate_decoder,
adler adler32,
)
@@ -39,7 +39,7 @@ pub func zlib_decoder.decode?(dst writer1, src reader1)() {
}
var checksum u32
while true {
var z status = try this.dec.decode?(dst:in.dst, src:in.src)
var z status = try this.flate.decode?(dst:in.dst, src:in.src)
checksum = this.adler.update(x:in.dst.slice())
if z.is_ok() {
break