mod nats;
mod trace;
pub use nats::NATSSink;
pub use nats::NATSStream;
pub use trace::{last_sent_at, span_between, wallclock};
pub trait Wire: Sized {
fn encode(&self) -> anyhow::Result<Vec<u8>>;
fn decode(bytes: &[u8]) -> anyhow::Result<Self>;
}
macro_rules! postcard_wire {
($name:ident $(< $($p:ident : $bound:path),+ >)?) => {
impl $(< $($p: $bound + serde::Serialize + serde::de::DeserializeOwned),+ >)?
$crate::bus::Wire for $name $(< $($p),+ >)?
{
fn encode(&self) -> anyhow::Result<Vec<u8>> {
Ok(postcard::to_allocvec(self)?)
}
fn decode(bytes: &[u8]) -> anyhow::Result<Self> {
Ok(postcard::from_bytes(bytes)?)
}
}
};
}
pub(crate) use postcard_wire;