photon-protocol 0.0.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
17
18
use bytes::BytesMut;

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

#[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 },

    #[error(transparent)]
    Unknown(#[from] anyhow::Error),
}