Trait MessageSerializer

Source
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§

Source

type SerializeError: Debug + Send + Sync + 'static

Error type for serialization failures

Source

type DeserializeError: Debug + Send + Sync + 'static

Error type for deserialization failures

Required Methods§

Source

fn serialize(&self, data: &T) -> Result<Vec<u8>, Self::SerializeError>

Convert data to bytes for MQTT transmission

Source

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.

Implementors§