use crate::ids::{AureliaError, MessageType};
use bytes::Bytes;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct EncodedMessage {
pub msg_type: MessageType,
pub payload: Bytes,
}
impl EncodedMessage {
pub fn new(msg_type: MessageType, payload: Bytes) -> Self {
Self { msg_type, payload }
}
}
pub trait MessageCodec: Send + Sync + 'static {
type AppMessage;
fn encode_app(&self, msg: &Self::AppMessage) -> Result<EncodedMessage, AureliaError>;
fn decode_app(
&self,
msg_type: MessageType,
payload: &[u8],
) -> Result<Self::AppMessage, AureliaError>;
}