inn_network/codec/
forward.rs1pub struct ForwardCodec;
12
13use crate::codec::*;
14use actix_codec::Decoder;
15use actix_codec::Encoder;
16
17impl Encoder<Vec<u8>> for ForwardCodec {
18 type Error = Error;
19 fn encode(&mut self, item: Vec<u8>, dst: &mut BytesMut) -> Result<(), Self::Error> {
20 dst.extend(item);
21 Ok(())
22 }
23}
24impl Decoder for ForwardCodec {
25 type Item = Vec<u8>;
26 type Error = Error;
27 fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
28 if src.is_empty() {
29 Ok(None)
30 } else {
31 Ok(Some(src.split_to(src.len()).to_vec()))
32 }
33 }
34}