aboutsummaryrefslogtreecommitdiff
path: root/net/src/codec/mod.rs
blob: 565cb07fd99f60691237f896d6f45396682879d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
mod bytes_codec;
mod length_codec;
mod websocket;

pub use bytes_codec::BytesCodec;
pub use length_codec::LengthCodec;
pub use websocket::{WebSocketCodec, WebSocketDecoder, WebSocketEncoder};

use crate::Result;

pub trait Codec:
    Decoder<DeItem = Self::Item> + Encoder<EnItem = Self::Item> + Send + Sync + 'static + Unpin
{
    type Item: Send + Sync;
}

pub trait Encoder {
    type EnItem;
    fn encode(&self, src: &Self::EnItem, dst: &mut [u8]) -> Result<usize>;
}

pub trait Decoder {
    type DeItem;
    fn decode(&self, src: &mut [u8]) -> Result<Option<(usize, Self::DeItem)>>;
}