Rename u32, io_reader, etc to base.u32, etc

This commit is contained in:
Nigel Tao committed 2018-04-12 21:49:17 +10:00
1 parent fee97df698
commit f95239f6e0
24 files changed
+394 -392

No files matched your search

+14 -14
View File
@@ -26,15 +26,15 @@ pub error "TODO: unsupported zlib preset dictionary"
pub struct decoder?(
flate deflate.decoder,
checksum adler32,
ignore_checksum bool,
ignore_checksum base.bool,
)
pub func decoder.set_ignore_checksum!(ic bool)() {
pub func decoder.set_ignore_checksum!(ic base.bool)() {
this.ignore_checksum = in.ic
}
pub func decoder.decode?(dst io_writer, src io_reader)() {
var x u16 = in.src.read_u16be?()
pub func decoder.decode?(dst base.io_writer, src base.io_reader)() {
var x base.u16 = in.src.read_u16be?()
if ((x >> 8) & 0x0F) != 0x08 {
return error "invalid zlib compression method"
}
@@ -49,10 +49,10 @@ pub func decoder.decode?(dst io_writer, src io_reader)() {
}
// Decode and checksum the DEFLATE-encoded payload.
var checksum_got u32
var checksum_got base.u32
while true {
in.dst.mark()
var z status = try this.flate.decode?(dst:in.dst, src:in.src)
var z base.status = try this.flate.decode?(dst:in.dst, src:in.src)
if not this.ignore_checksum {
checksum_got = this.checksum.update(x:in.dst.since_mark())
}
@@ -61,7 +61,7 @@ pub func decoder.decode?(dst io_writer, src io_reader)() {
}
yield z
}
var checksum_want u32 = in.src.read_u32be?()
var checksum_want base.u32 = in.src.read_u32be?()
if (not this.ignore_checksum) and (checksum_got != checksum_want) {
return error "checksum mismatch"
}
@@ -69,26 +69,26 @@ pub func decoder.decode?(dst io_writer, src io_reader)() {
// TODO: drop the '?' but still generate wuffs_zlib__adler32__initialize?
pri struct adler32?(
state u32 = 1,
state base.u32 = 1,
)
// TODO: add a ! as this function is impure.
pri func adler32.update(x slice u8)(checksum u32) {
pri func adler32.update(x slice base.u8)(checksum base.u32) {
// The Adler-32 checksum's magic 65521 and 5552 numbers are discussed in
// RFC 1950.
var s1 u32 = this.state.low_bits(n:16)
var s2 u32 = this.state.high_bits(n:16)
var s1 base.u32 = this.state.low_bits(n:16)
var s2 base.u32 = this.state.high_bits(n:16)
while in.x.length() > 0 {
var remaining slice u8
var remaining slice base.u8
if in.x.length() > 5552 {
remaining = in.x[5552:]
in.x = in.x[:5552]
}
iterate[8](p ptr u8:in.x) {
s1 ~+= deref p as u32
iterate[8](p ptr base.u8:in.x) {
s1 ~+= deref p as base.u32
s2 ~+= s1
}