use crate::core::Message;
#[derive(Clone)]
pub struct WithTopic<T> {
pub topic: Topic,
pub value: T,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Topic {
Text(String),
Id(u64),
}
impl<'a> From<&'a str> for Topic {
fn from(text: &'a str) -> Self {
Topic::Text(String::from(text))
}
}
impl From<&Topic> for String {
fn from(topic: &Topic) -> Self {
match topic {
Topic::Text(text) => text.clone(),
Topic::Id(id) => id.to_string(),
}
}
}
pub type SerializedMessage = Message<Vec<u8>>;
pub trait BinaryFormat<T> {
fn schema(&self) -> Schema;
fn serialize(&mut self, data: &T) -> eyre::Result<Vec<u8>>;
fn deserialize(&mut self, buffer: &[u8]) -> eyre::Result<T>;
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Schema {
pub name: String,
pub encoding: String,
}