Debian Codegraph @

src/decoder_7.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/::ppmd7rust-analyzer cargo ppmd-rust 1.2.1 internal/ppmd7/::{PPMd7rust-analyzer cargo ppmd-rust 1.2.1 internal/ppmd7/PPMd7#, RangeDecoderrust-analyzer cargo ppmd-rust 1.2.1 internal/ppmd7/range_coding/RangeDecoder#},
5 Errorrust-analyzer cargo ppmd-rust 1.2.1 Error#, PPMD7_MAX_MEM_SIZErust-analyzer cargo ppmd-rust 1.2.1 PPMD7_MAX_MEM_SIZE., PPMD7_MAX_ORDERrust-analyzer cargo ppmd-rust 1.2.1 PPMD7_MAX_ORDER., PPMD7_MIN_MEM_SIZErust-analyzer cargo ppmd-rust 1.2.1 PPMD7_MIN_MEM_SIZE., PPMD7_MIN_ORDERrust-analyzer cargo ppmd-rust 1.2.1 PPMD7_MIN_ORDER., SYM_ENDrust-analyzer cargo ppmd-rust 1.2.1 SYM_END.,
6 };
7
8 /// A decoder to decompress data using PPMd7 (PPMdH) with the 7z range coder.
9 pub struct Ppmd7Decoderrust-analyzer cargo ppmd-rust 1.2.1 decoder_7/Ppmd7Decoder#<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#> {
10 ppmdrust-analyzer cargo ppmd-rust 1.2.1 decoder_7/Ppmd7Decoder#ppmd.: PPMd7rust-analyzer cargo ppmd-rust 1.2.1 internal/ppmd7/PPMd7#<RangeDecoderrust-analyzer cargo ppmd-rust 1.2.1 internal/ppmd7/range_coding/RangeDecoder#<R>>,
11 finishedrust-analyzer cargo ppmd-rust 1.2.1 decoder_7/Ppmd7Decoder#finished.: bool,
12 }
13
14 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 Ppmd7Decoderrust-analyzer cargo ppmd-rust 1.2.1 decoder_7/Ppmd7Decoder#<R> {}
15 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 Ppmd7Decoderrust-analyzer cargo ppmd-rust 1.2.1 decoder_7/Ppmd7Decoder#<R> {}
16
17 impl<R: Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#> Ppmd7Decoderrust-analyzer cargo ppmd-rust 1.2.1 decoder_7/Ppmd7Decoder#<R> {
18 /// Creates a new [`Ppmd7Decoder`] which provides a reader over the uncompressed data.
19 ///
20 /// The given `order` must be between [`PPMD7_MIN_ORDER`] and [`PPMD7_MAX_ORDER`]
21 /// The given `mem_size` must be between [`PPMD7_MIN_MEM_SIZE`] and [`PPMD7_MAX_MEM_SIZE`]
22 pub fn newrust-analyzer cargo ppmd-rust 1.2.1 decoder_7/impl#[`Ppmd7Decoder<R>`]new().(reader: R, order: u32, mem_size: u32) -> 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_7/impl#[`Ppmd7Decoder<R>`]> {
23 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(PPMD7_MIN_ORDERrust-analyzer cargo ppmd-rust 1.2.1 PPMD7_MIN_ORDER...=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#PPMD7_MAX_ORDERrust-analyzer cargo ppmd-rust 1.2.1 PPMD7_MAX_ORDER.).containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]contains().(&order)
24 || !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(PPMD7_MIN_MEM_SIZErust-analyzer cargo ppmd-rust 1.2.1 PPMD7_MIN_MEM_SIZE...=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#PPMD7_MAX_MEM_SIZErust-analyzer cargo ppmd-rust 1.2.1 PPMD7_MAX_MEM_SIZE.).containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/impl#[`RangeInclusive<Idx>`]contains().(&mem_size)
25 {
26 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#);
27 }
28
29 let ppmd = PPMd7rust-analyzer cargo ppmd-rust 1.2.1 internal/ppmd7/PPMd7#::new_decoderrust-analyzer cargo ppmd-rust 1.2.1 internal/ppmd7/impl#[`PPMd7<RangeDecoder<R>>`]new_decoder().(reader, order, mem_size)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
30
31 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo ppmd-rust 1.2.1 decoder_7/impl#[`Ppmd7Decoder<R>`] {
32 ppmdrust-analyzer cargo ppmd-rust 1.2.1 decoder_7/Ppmd7Decoder#ppmd.,
33 finishedrust-analyzer cargo ppmd-rust 1.2.1 decoder_7/Ppmd7Decoder#finished.: false,
34 })
35 }
36
37 /// Returns the inner reader.
38 pub fn into_innerrust-analyzer cargo ppmd-rust 1.2.1 decoder_7/impl#[`Ppmd7Decoder<R>`]into_inner().(self) -> R {
39 self.ppmdrust-analyzer cargo ppmd-rust 1.2.1 decoder_7/Ppmd7Decoder#ppmd..into_innerrust-analyzer cargo ppmd-rust 1.2.1 internal/ppmd7/impl#[`PPMd7<RangeDecoder<R>>`]into_inner().()
40 }
41 }
42
43 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 Ppmd7Decoderrust-analyzer cargo ppmd-rust 1.2.1 decoder_7/Ppmd7Decoder#<R> {
44 fn readrust-analyzer cargo ppmd-rust 1.2.1 decoder_7/impl#[`Ppmd7Decoder<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> {
45 if self.finishedrust-analyzer cargo ppmd-rust 1.2.1 decoder_7/Ppmd7Decoder#finished. {
46 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0);
47 }
48
49 if buf.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() {
50 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(0);
51 }
52
53 let mut sym = 0;
54 let mut decoded = 0;
55
56 for byte in buf.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().() {
57 match self.ppmdrust-analyzer cargo ppmd-rust 1.2.1 decoder_7/Ppmd7Decoder#ppmd..decode_symbolrust-analyzer cargo ppmd-rust 1.2.1 internal/ppmd7/decoder/impl#[`PPMd7<RangeDecoder<R>>`]decode_symbol().() {
58 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(symbol) => sym = symbol,
59 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => {
60 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# {
61 self.finishedrust-analyzer cargo ppmd-rust 1.2.1 decoder_7/Ppmd7Decoder#finished. = true;
62 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(decoded);
63 }
64 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err);
65 }
66 }
67
68 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 {
69 break;
70 }
71
72 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().byte = sym as u8;
73 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;
74 }
75
76 let code = self.ppmdrust-analyzer cargo ppmd-rust 1.2.1 decoder_7/Ppmd7Decoder#ppmd..range_decoder_coderust-analyzer cargo ppmd-rust 1.2.1 internal/ppmd7/impl#[`PPMd7<RangeDecoder<R>>`]range_decoder_code().();
77
78 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 {
79 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(decoded);
80 }
81
82 self.finishedrust-analyzer cargo ppmd-rust 1.2.1 decoder_7/Ppmd7Decoder#finished. = true;
83
84 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 {
85 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().(
86 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#,
87 "Error during PPMd decoding",
88 ));
89 }
90
91 // END_MARKER detected
92 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(decoded)
93 }
94 }