Skip to content

Commit 86b6ffa

Browse files
committed
feat(decompress-plz): changed ContentEncoding argument to EncodingInfo
1 parent ecdbad6 commit 86b6ffa

File tree

4 files changed

+54
-33
lines changed

4 files changed

+54
-33
lines changed

decompression-plz/src/decompression/mod.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,26 @@ use std::io::{Read, Write, copy};
22

33
use brotli::Decompressor;
44
use bytes::{BufMut, BytesMut, buf::Writer};
5-
use header_plz::body_headers::content_encoding::ContentEncoding;
5+
use header_plz::body_headers::{content_encoding::ContentEncoding, encoding_info::EncodingInfo};
66

77
mod decompressors;
88
mod magic_bytes;
99
use decompressors::*;
1010

11-
use crate::decompression::error::DecompressError;
12-
mod error;
11+
use crate::{decompression::error::DecompressError, error::DecompressErrorStruct};
12+
pub mod error;
13+
14+
pub fn decompress_all<R, W>(
15+
compressed: R,
16+
writer: W,
17+
encoding_info: &[EncodingInfo],
18+
) -> Result<BytesMut, DecompressErrorStruct>
19+
where
20+
R: Read,
21+
W: Write,
22+
{
23+
todo!()
24+
}
1325

1426
pub fn decompress<R, W>(
1527
mut input: R,

decompression-plz/src/dstruct.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
use bytes::BytesMut;
2-
use header_plz::body_headers::content_encoding::ContentEncoding;
2+
use header_plz::body_headers::{content_encoding::ContentEncoding, encoding_info::EncodingInfo};
33

44
pub struct DecompressionStruct<'a> {
55
main: BytesMut,
66
pub extra: Option<BytesMut>,
7-
encodings: &'a [ContentEncoding],
7+
encoding_info: &'a [EncodingInfo],
88
buf: &'a mut BytesMut,
99
}
1010

1111
impl<'a> DecompressionStruct<'a> {
1212
pub fn new(
1313
main: BytesMut,
1414
extra: Option<BytesMut>,
15-
encodings: &'a [ContentEncoding],
15+
encoding_info: &'a [EncodingInfo],
1616
buf: &'a mut BytesMut,
1717
) -> Self {
1818
Self {
1919
main,
2020
extra,
21-
encodings,
21+
encoding_info,
2222
buf,
2323
}
2424
}

decompression-plz/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![allow(warnings)]
2-
mod decompression;
2+
pub mod decompression;
33
pub mod dstruct;
4+
mod error;
45
mod state;

decompression-plz/src/state.rs

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1-
use crate::dstruct::DecompressionStruct;
1+
use crate::{dstruct::DecompressionStruct, error::DecompressErrorStruct};
22
use bytes::BytesMut;
3-
use header_plz::body_headers::content_encoding::ContentEncoding;
3+
use header_plz::body_headers::{content_encoding::ContentEncoding, encoding_info::EncodingInfo};
4+
5+
/*
6+
1. Main
7+
true => Main_decompressed + Extra_decompressed
8+
false => Err()
9+
10+
2. Extra
11+
true => Main
12+
false => Main + Extra
13+
14+
3. Main + Extra
15+
true => Main_and_Extra_decompressed
16+
false => Err()
17+
*/
18+
19+
// 1. Try decompressing extra
20+
// 2. If success, try decompressing main
21+
// 2. If failed, try decompressing main + extra
22+
// 3. If failed, try decompressing main
423

524
enum State<'a> {
625
// Main
@@ -18,33 +37,22 @@ impl<'a> State<'a> {
1837
fn start(
1938
main: BytesMut,
2039
extra: Option<BytesMut>,
21-
encodings: &'a [ContentEncoding],
40+
encodings: &'a [EncodingInfo],
2241
buf: &'a mut BytesMut,
2342
) -> Self {
24-
let d = DecompressionStruct::new(main, extra, encodings, buf);
25-
if d.extra.is_some() {
26-
Self::Extra(d)
43+
let dstruct = DecompressionStruct::new(main, extra, encodings, buf);
44+
if dstruct.extra.is_some() {
45+
Self::Extra(dstruct)
2746
} else {
28-
Self::MainOnly(d)
47+
Self::MainOnly(dstruct)
2948
}
3049
}
31-
}
3250

33-
/*
34-
1. Extra
35-
true => Main
36-
false => Main + Extra
37-
38-
2. Main
39-
true => Main_decompressed + Extra_decompressed
40-
false => Err()
41-
42-
3. Main + Extra
43-
true => Main_and_Extra_decompressed
44-
false => Err()
45-
*/
51+
fn try_next(self) -> Result<Self, DecompressErrorStruct> {
52+
todo!()
53+
}
4654

47-
// 1. Try decompressing extra
48-
// 2. If success, try decompressing main
49-
// 2. If failed, try decompressing main + extra
50-
// 3. If failed, try decompressing main
55+
fn ended(self) -> bool {
56+
matches!(self, Self::EndMainOnly(_)) || matches!(self, Self::EndMainOnyDecompressed(_))
57+
}
58+
}

0 commit comments

Comments
 (0)