photon_protocol/ports/
codec.rs1use bytes::BytesMut;
2
3pub trait Codec<T>: Send + Sync + Clone + 'static {
4 fn encode(&self, value: &T, output: &mut BytesMut) -> Result<(), CodecError>;
5 fn decode(&self, input: &[u8]) -> Result<T, CodecError>;
6}
7
8#[non_exhaustive]
9#[derive(Debug, thiserror::Error)]
10pub enum CodecError {
11 #[error("failed to encode batch: {reason}")]
12 EncodeFailed { reason: String },
13
14 #[error("failed to decode batch: {reason}")]
15 DecodeFailed { reason: String },
16}