axum_gate/
codecs.rs

1//! En- and decoding payload interfaces.
2use crate::Error;
3use serde::{Serialize, de::DeserializeOwned};
4
5/// Methods for encoding and decoding payload.
6pub trait CodecService
7where
8    Self: Clone,
9    Self::Payload: Serialize + DeserializeOwned,
10{
11    /// The payload that can be encoded.
12    type Payload;
13
14    /// Encodes the given payload.
15    fn encode(&self, payload: &Self::Payload) -> Result<Vec<u8>, Error>;
16    /// Decodoes the given payload.
17    fn decode(&self, encoded_value: &[u8]) -> Result<Self::Payload, Error>;
18}