MCPcopy Create free account
hub / github.com/Recordscript/recordscript / decode

Method decode

libs/hbb_common/src/bytes_codec.rs:80–107  ·  view source on GitHub ↗
(&mut self, src: &mut BytesMut)

Source from the content-addressed store, hash-verified

78 type Error = io::Error;
79
80 fn decode(&mut self, src: &mut BytesMut) -> Result<Option<BytesMut>, io::Error> {
81 if self.raw {
82 if !src.is_empty() {
83 let len = src.len();
84 return Ok(Some(src.split_to(len)));
85 } else {
86 return Ok(None);
87 }
88 }
89 let n = match self.state {
90 DecodeState::Head => match self.decode_head(src)? {
91 Some(n) => {
92 self.state = DecodeState::Data(n);
93 n
94 }
95 None => return Ok(None),
96 },
97 DecodeState::Data(n) => n,
98 };
99
100 match self.decode_data(n, src)? {
101 Some(data) => {
102 self.state = DecodeState::Head;
103 Ok(Some(data))
104 }
105 None => Ok(None),
106 }
107 }
108}
109
110impl Encoder<Bytes> for BytesCodec {

Callers 6

test_codec1Function · 0.45
test_codec2Function · 0.45
test_codec3Function · 0.45
test_codec4Function · 0.45
test_codec5Function · 0.45
test_codec6Function · 0.45

Calls 3

is_emptyMethod · 0.80
decode_headMethod · 0.80
decode_dataMethod · 0.80

Tested by 6

test_codec1Function · 0.36
test_codec2Function · 0.36
test_codec3Function · 0.36
test_codec4Function · 0.36
test_codec5Function · 0.36
test_codec6Function · 0.36