Debian Codegraph @

src/decoder_8.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#;
2
3 use craterust-analyzer cargo ppmd-rust 1.2.1 crate/::{
4 internalrust-analyzer cargo ppmd-rust 1.2.1 internal/::ppmd8rust-analyzer cargo ppmd-rust 1.2.1 internal/ppmd8/::{PPMd8rust-analyzer cargo ppmd-rust 1.2.1 internal/ppmd8/PPMd8#, RangeDecoderrust-analyzer cargo ppmd-rust 1.2.1 internal/ppmd8/range_coding/RangeDecoder#},
5 Errorrust-analyzer cargo ppmd-rust 1.2.1 Error#, RestoreMethodrust-analyzer cargo ppmd-rust 1.2.1 RestoreMethod#, PPMD8_MAX_MEM_SIZErust-analyzer cargo ppmd-rust 1.2.1 PPMD8_MAX_MEM_SIZE., PPMD8_MAX_ORDERrust-analyzer cargo ppmd-rust 1.2.1 PPMD8_MAX_ORDER., PPMD8_MIN_MEM_SIZErust-analyzer cargo ppmd-rust 1.2.1 PPMD8_MIN_MEM_SIZE., PPMD8_MIN_ORDERrust-analyzer cargo ppmd-rust 1.2.1 PPMD8_MIN_ORDER.,
6 SYM_ENDrust-analyzer cargo ppmd-rust 1.2.1 SYM_END.,
7 };
8
9 /// A decoder to decompress data using PPMd8 (PPMdI rev.1).
10 pub struct Ppmd8Decoderrust-analyzer cargo ppmd-rust 1.2.1 decoder_8/Ppmd8Decoder#<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#> {
11 ppmdrust-analyzer cargo ppmd-rust 1.2.1 decoder_8/Ppmd8Decoder#ppmd.: PPMd8rust-analyzer cargo ppmd-rust 1.2.1 internal/ppmd8/PPMd8#<RangeDecoderrust-analyzer cargo ppmd-rust 1.2.1 internal/ppmd8/range_coding/RangeDecoder#<R>>,
12 finishedrust-analyzer cargo ppmd-rust 1.2.1 decoder_8/Ppmd8Decoder#finished.: bool,
13 }
14
15 unsafe impl<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#> Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# for Ppmd8Decoderrust-analyzer cargo ppmd-rust 1.2.1 decoder_8/Ppmd8Decoder#<R> {}
16 unsafe impl<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#> Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# for Ppmd8Decoderrust-analyzer cargo ppmd-rust 1.2.1 decoder_8/Ppmd8Decoder#<R> {}
17
18 impl<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#> Ppmd8Decoderrust-analyzer cargo ppmd-rust 1.2.1 decoder_8/Ppmd8Decoder#<R> {
19 /// Creates a new [`Ppmd8Decoder`] which provides a reader over the uncompressed data.
20 ///
21 /// The given `order` must be between [`PPMD8_MIN_ORDER`] and [`PPMD8_MAX_ORDER`] (inclusive).
22 /// The given `mem_size` must be between [`PPMD8_MIN_MEM_SIZE`] and [`PPMD8_MAX_MEM_SIZE`] (inclusive).
23 pub fn newrust-analyzer cargo ppmd-rust 1.2.1 decoder_8/impl#[`Ppmd8Decoder<R>`]new().(
24 reader: R,
25 order: u32,
26 mem_size: u32,
27 restore_method: RestoreMethodrust-analyzer cargo ppmd-rust 1.2.1 RestoreMethod#,
28 ) -> craterust-analyzer cargo ppmd-rust 1.2.1 crate/::Resultrust-analyzer cargo ppmd-rust 1.2.1 Result#<Selfrust-analyzer cargo ppmd-rust 1.2.1 decoder_8/impl#[`Ppmd8Decoder<R>`]> {
29 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(PPMD8_MIN_ORDERrust-analyzer cargo ppmd-rust 1.2.1 PPMD8_MIN_ORDER...=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#PPMD8_MAX_ORDERrust-analyzer cargo ppmd-rust 1.2.1 PPMD8_MAX_ORDER.).containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]contains().(&order)
30 || !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(PPMD8_MIN_MEM_SIZErust-analyzer cargo ppmd-rust 1.2.1 PPMD8_MIN_MEM_SIZE...=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#PPMD8_MAX_MEM_SIZErust-analyzer cargo ppmd-rust 1.2.1 PPMD8_MAX_MEM_SIZE.).containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]contains().(&mem_size)
31 {
32 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo ppmd-rust 1.2.1 Error#::InvalidParameterrust-analyzer cargo ppmd-rust 1.2.1 Error#InvalidParameter#);
33 }
34
35 let ppmd = PPMd8rust-analyzer cargo ppmd-rust 1.2.1 internal/ppmd8/PPMd8#::new_decoderrust-analyzer cargo ppmd-rust 1.2.1 internal/ppmd8/impl#[`PPMd8<RangeDecoder<R>>`]new_decoder().(reader, order, mem_size, restore_method)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
36
37 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo ppmd-rust 1.2.1 decoder_8/impl#[`Ppmd8Decoder<R>`] {
38 ppmdrust-analyzer cargo ppmd-rust 1.2.1 decoder_8/Ppmd8Decoder#ppmd.,
39 finishedrust-analyzer cargo ppmd-rust 1.2.1 decoder_8/Ppmd8Decoder#finished.: false,
40 })
41 }
42
43 /// Returns the inner reader.
44 pub fn into_innerrust-analyzer cargo ppmd-rust 1.2.1 decoder_8/impl#[`Ppmd8Decoder<R>`]into_inner().(self) -> R {
45 self.ppmdrust-analyzer cargo ppmd-rust 1.2.1 decoder_8/Ppmd8Decoder#ppmd..into_innerrust-analyzer cargo ppmd-rust 1.2.1 internal/ppmd8/impl#[`PPMd8<RangeDecoder<R>>`]into_inner().()
46 }
47 }
48
49 impl<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#> Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read# for Ppmd8Decoderrust-analyzer cargo ppmd-rust 1.2.1 decoder_8/Ppmd8Decoder#<R> {
50 fn readrust-analyzer cargo ppmd-rust 1.2.1 decoder_8/impl#[`Ppmd8Decoder<R>`][Read]read().(&mut self, buf: &mut [u8]) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> {
51 if self.finishedrust-analyzer cargo ppmd-rust 1.2.1 decoder_8/Ppmd8Decoder#finished. {
52 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0);
53 }
54
55 if buf.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() {
56 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0);
57 }
58
59 let mut sym = 0;
60 let mut decoded = 0;
61
62 for byte in buf.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().() {
63 match self.ppmdrust-analyzer cargo ppmd-rust 1.2.1 decoder_8/Ppmd8Decoder#ppmd..decode_symbolrust-analyzer cargo ppmd-rust 1.2.1 internal/ppmd8/decoder/impl#[`PPMd8<RangeDecoder<R>>`]decode_symbol().() {
64 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(symbol) => sym = symbol,
65 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => {
66 if err.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().() rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().==rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq(). rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::UnexpectedEofrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#UnexpectedEof# {
67 self.finishedrust-analyzer cargo ppmd-rust 1.2.1 decoder_8/Ppmd8Decoder#finished. = true;
68 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(decoded);
69 }
70 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err);
71 }
72 }
73
74 if sym rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().0 {
75 break;
76 }
77
78 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().byte = sym as u8;
79 decoded rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
80 }
81
82 let code = self.ppmdrust-analyzer cargo ppmd-rust 1.2.1 decoder_8/Ppmd8Decoder#ppmd..range_decoder_coderust-analyzer cargo ppmd-rust 1.2.1 internal/ppmd8/impl#[`PPMd8<RangeDecoder<R>>`]range_decoder_code().();
83
84 if sym rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge().0 {
85 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(decoded);
86 }
87
88 self.finishedrust-analyzer cargo ppmd-rust 1.2.1 decoder_8/Ppmd8Decoder#finished. = true;
89
90 if sym rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().SYM_ENDrust-analyzer cargo ppmd-rust 1.2.1 SYM_END. || code rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().0 {
91 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(
92 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidDatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidData#,
93 "Error during PPMd decoding",
94 ));
95 }
96
97 // END_MARKER detected
98 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(decoded)
99 }
100 }