pub trait MessageSerializer<T>:
Default
+ Clone
+ Send
+ Sync
+ 'static {
type SerializeError: Debug + Send + Sync + 'static;
type DeserializeError: Debug + Send + Sync + 'static;
// Required methods
fn serialize(&self, data: &T) -> Result<Vec<u8>, Self::SerializeError>;
fn deserialize(&self, bytes: &[u8]) -> Result<T, Self::DeserializeError>;
}
Expand description
Trait for serializing and deserializing MQTT message payloads.
Implement this trait to use custom serialization formats.
Required Associated Types§
Sourcetype SerializeError: Debug + Send + Sync + 'static
type SerializeError: Debug + Send + Sync + 'static
Error type for serialization failures
Sourcetype DeserializeError: Debug + Send + Sync + 'static
type DeserializeError: Debug + Send + Sync + 'static
Error type for deserialization failures
Required Methods§
Sourcefn serialize(&self, data: &T) -> Result<Vec<u8>, Self::SerializeError>
fn serialize(&self, data: &T) -> Result<Vec<u8>, Self::SerializeError>
Convert data to bytes for MQTT transmission
Sourcefn deserialize(&self, bytes: &[u8]) -> Result<T, Self::DeserializeError>
fn deserialize(&self, bytes: &[u8]) -> Result<T, Self::DeserializeError>
Convert bytes from MQTT into typed data
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.