mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 00:47:28 +01:00
66 lines
2.0 KiB
Plaintext
66 lines
2.0 KiB
Plaintext
// Copyright 2024 The Wuffs Authors.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
|
|
// option. This file may not be copied, modified, or distributed
|
|
// except according to those terms.
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
|
|
use "std/crc32"
|
|
use "std/lzma"
|
|
|
|
pub status "#truncated input"
|
|
|
|
pub const DECODER_DST_HISTORY_RETAIN_LENGTH_MAX_INCL_WORST_CASE : base.u64 = 0
|
|
|
|
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 1
|
|
|
|
pub struct decoder? implements base.io_transformer(
|
|
ignore_checksum : base.bool,
|
|
|
|
util : base.utility,
|
|
)
|
|
|
|
pub func decoder.get_quirk(key: base.u32) base.u64 {
|
|
if (args.key == base.QUIRK_IGNORE_CHECKSUM) and this.ignore_checksum {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
|
|
if args.key == base.QUIRK_IGNORE_CHECKSUM {
|
|
this.ignore_checksum = args.value > 0
|
|
return ok
|
|
}
|
|
return base."#unsupported option"
|
|
}
|
|
|
|
pub func decoder.dst_history_retain_length() base.optional_u63 {
|
|
return this.util.make_optional_u63(has_value: true, value: 0)
|
|
}
|
|
|
|
pub func decoder.workbuf_len() base.range_ii_u64 {
|
|
return this.util.make_range_ii_u64(
|
|
min_incl: DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE,
|
|
max_incl: DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE)
|
|
}
|
|
|
|
pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
|
|
var status : base.status
|
|
|
|
while true {
|
|
status =? this.do_transform_io?(dst: args.dst, src: args.src, workbuf: args.workbuf)
|
|
if (status == base."$short read") and args.src.is_closed() {
|
|
return "#truncated input"
|
|
}
|
|
yield? status
|
|
} endwhile
|
|
}
|
|
|
|
pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, workbuf: slice base.u8) {
|
|
args.dst.write_u8?(a: 'x')
|
|
}
|