Decode flate code length code lengths.

This commit is contained in:
Nigel Tao committed 2017-07-16 12:51:44 +10:00
1 parent b78807d60a
commit 20f37a6dab
8 files changed
+95 -15

No files matched your search

+23 -2
View File
@@ -19,10 +19,11 @@ pub struct decoder?(
bits u32,
n_bits u32,
code_length_code_lengths[19] u8[..7],
// These temporary fields are used to debug work-in-progress code.
wip0 u32,
wip1 u32,
wip2 u32,
)
pub func decoder.decode?(dst writer1, src reader1)() {
@@ -91,10 +92,30 @@ pub func decoder.decode_dynamic?(dst writer1, src reader1)() {
bits >>= 4
n_bits -= 14
// Read the code length code lengths. (This is not a typo).
var i u32 = 0
while i < hclen {
while n_bits < 3,
inv i < hclen,
post n_bits >= 3,
{
bits |= (in.src.read_u8?() as u32) << n_bits
n_bits += 8
}
assert i < 19 via "a < b: a < c; c <= b"(c:hclen)
this.code_length_code_lengths[code_order[i]] = (bits & 0x07) as u8
bits >>= 3
n_bits -= 3
i += 1
}
while i < 19 {
this.code_length_code_lengths[code_order[i]] = 0
i += 1
}
// TODO: implement.
this.wip0 = hlit
this.wip1 = hdist
this.wip2 = hclen
this.bits = bits
this.n_bits = n_bits