pub trait Codec: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn encode(&self, msg: &Message) -> Result<Vec<u8>, EventBusError>;
fn decode(&self, bytes: &[u8]) -> Result<Message, EventBusError>;
}Expand description
Pluggable wire-format encoder for Message.
Object-safe: backends store an Arc<dyn Codec> and dispatch through it.
Implementations own the full envelope so swapping codecs is a binary
decision (e.g. JSON for cross-language compat vs. binary for throughput).
Required Methods§
fn name(&self) -> &str
fn encode(&self, msg: &Message) -> Result<Vec<u8>, EventBusError>
fn decode(&self, bytes: &[u8]) -> Result<Message, EventBusError>
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".