photon-protocol 0.2.0

Internal codec and compression traits for Photon
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use bytes::BytesMut;

pub trait Codec<T>: Send + Sync + Clone + 'static {
    fn encode(&self, value: &T, output: &mut BytesMut) -> Result<(), CodecError>;
    fn decode(&self, input: &[u8]) -> Result<T, CodecError>;
}

#[non_exhaustive]
#[derive(Debug, thiserror::Error)]
pub enum CodecError {
    #[error("failed to encode batch: {reason}")]
    EncodeFailed { reason: String },

    #[error("failed to decode batch: {reason}")]
    DecodeFailed { reason: String },
}