Skip to content

Commit 14eb42d

Browse files
committed
feat(decompression-plz): added main decode logic to decompress function
1 parent 33a2dbe commit 14eb42d

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

decompression-plz/src/lib.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use crate::{
77
content_length::add_body_and_update_cl,
88
decompression::{
99
multi::error::{MultiDecompressError, MultiDecompressErrorReason},
10-
state::runner,
10+
state::decompression_runner,
1111
},
1212
dtraits::DecompressTrait,
13+
state::DecodeState,
1314
};
1415
mod content_length;
1516
mod decode_struct;
@@ -21,16 +22,23 @@ pub fn decompress<T>(
2122
mut message: T,
2223
mut extra_body: Option<BytesMut>,
2324
buf: &mut BytesMut,
24-
) -> Result<(), MultiDecompressError>
25+
)
26+
//-> Result<(), MultiDecompressError>
2527
where
2628
T: DecompressTrait,
2729
{
2830
let mut body = message.get_body().into_bytes().unwrap();
2931
let mut body_headers = message.body_headers_as_mut().take();
3032

31-
//
32-
add_body_and_update_cl(&mut message, body);
33-
Ok(())
33+
let mut state = DecodeState::init(&mut message, extra_body, buf);
34+
loop {
35+
state = state.try_next();
36+
if state.is_ended() {
37+
break;
38+
}
39+
}
40+
41+
// Ok(())
3442
}
3543

3644
// helper function for tests

decompression-plz/src/state.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ where
3535
Self::Start(decode_struct)
3636
}
3737

38-
fn try_next(self) -> Self {
38+
pub fn try_next(self) -> Self {
3939
match self {
4040
DecodeState::Start(mut decode_struct) => {
4141
if decode_struct.transfer_encoding_is_some() {
@@ -91,14 +91,14 @@ where
9191
if let Some(extra) = decode_struct.take_extra_body() {
9292
body.unsplit(extra);
9393
}
94-
add_body_and_update_cl(&mut decode_struct.message, body);
94+
add_body_and_update_cl(decode_struct.message, body);
9595
Self::End
9696
}
9797
DecodeState::End => Self::End,
9898
}
9999
}
100100

101-
fn is_ended(&self) -> bool {
101+
pub fn is_ended(&self) -> bool {
102102
matches!(self, DecodeState::End)
103103
}
104104
}
@@ -110,7 +110,7 @@ fn apply_encoding<T>(
110110
where
111111
T: DecompressTrait,
112112
{
113-
match runner(
113+
match decompression_runner(
114114
&decode_struct.body,
115115
decode_struct.extra_body.as_deref(),
116116
encoding_info,

0 commit comments

Comments
 (0)