| 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 | |
| 110 | impl Encoder<Bytes> for BytesCodec { |