#![warn(missing_docs)]
use bytes::Bytes;
use serde::Deserialize;
use serde::Serialize;
use crate::error::Error;
use crate::error::Result;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Envelope {
pub namespace: String,
pub payload: Bytes,
}
impl Envelope {
pub fn new(namespace: impl Into<String>, payload: Bytes) -> Self {
Self {
namespace: namespace.into(),
payload,
}
}
pub fn encode(&self) -> Result<Vec<u8>> {
bincode::serialize(self).map_err(|_| Error::EncodeError)
}
pub fn decode(bytes: &[u8]) -> Result<Self> {
bincode::deserialize(bytes).map_err(|_| Error::DecodeError)
}
}