Skip to main content

Serializer

Trait Serializer 

Source
pub trait Serializer: Send + Sync {
    type Error: Error + Send + Sync + 'static;

    // Required methods
    fn content_type(&self) -> &ContentType;
    fn serialize<T: Message>(&self, body: &T) -> Result<Bytes, Self::Error>;
    fn deserialize<T: Message>(&self, bytes: &[u8]) -> Result<T, Self::Error>;
}
Expand description

Converts a typed Message body to and from bytes. Lives in reliar-core: it touches neither storage nor transport (ADR 0010).

Stateless and cheap; implementations SHALL NOT be placed behind a dyn Serializer on the enqueue path (ADR 0001).

Required Associated Types§

Source

type Error: Error + Send + Sync + 'static

The serializer’s own error type.

Required Methods§

Source

fn content_type(&self) -> &ContentType

The content type this serializer produces. Populates both DeliveryMetadata::content_type and a provider’s content_type column — one value, chosen by the serializer, never by the call site.

Source

fn serialize<T: Message>(&self, body: &T) -> Result<Bytes, Self::Error>

Serializes a message body to bytes.

§Errors

Returns Self::Error if body cannot be represented in this serializer’s format.

Source

fn deserialize<T: Message>(&self, bytes: &[u8]) -> Result<T, Self::Error>

Deserializes bytes back into a message body.

§Errors

Returns Self::Error if bytes is not a valid encoding of T in this serializer’s format.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§