1#[cfg(feature = "json-codec")]
4mod json_codec;
5mod prost_codec;
6
7use std::io::Result;
8
9use bytes::BytesMut;
10
11pub trait Encoder: Send + 'static {
13 type Item: Send + 'static;
15
16 fn encode(&mut self, message: Self::Item, buf: &mut BytesMut) -> Result<()>;
18}
19
20pub trait Decoder: Send + 'static {
22 type Item: Send + 'static;
24
25 fn decode(&mut self, buf: &[u8]) -> Result<Self::Item>;
27}
28
29pub trait Codec: Default {
31 const CONTENT_TYPES: &'static [&'static str];
33
34 type Encode: Send + 'static;
36
37 type Decode: Send + 'static;
39
40 type Encoder: Encoder<Item = Self::Encode>;
42
43 type Decoder: Decoder<Item = Self::Decode>;
45
46 #[inline]
48 fn check_content_type(&self, ct: &str) -> bool {
49 Self::CONTENT_TYPES.contains(&ct)
50 }
51
52 fn encoder(&mut self) -> Self::Encoder;
54
55 fn decoder(&mut self) -> Self::Decoder;
57}
58
59#[cfg(feature = "json-codec")]
60pub use json_codec::{
61 JsonCodec, JsonDecoder, JsonEncoder, JsonI64ToStringCodec, JsonI64ToStringDecoder,
62 JsonI64ToStringEncoder,
63};
64pub use prost_codec::{ProstCodec, ProstDecoder, ProstEncoder};