reliar_core/mapper.rs
1//! Transport mapping abstraction (SRS §16, ADR 0004). Implemented in Phase 2.
2
3use crate::SerializedEnvelope;
4
5/// Converts a [`SerializedEnvelope`] to and from one transport's native message type `M`.
6///
7/// No implementation ships from `reliar-core` — a mapper's transport headers are a
8/// **projection** of [`Metadata`](crate::Metadata), not a second source of truth (ADR 0004).
9/// The reserved `reliar-*` header names a mapper writes are a public contract (§14).
10pub trait EnvelopeMapper<M> {
11 /// The mapper's own error type.
12 type Error: std::error::Error + Send + Sync + 'static;
13
14 /// Encodes a canonical envelope into the transport's native message type.
15 ///
16 /// # Errors
17 ///
18 /// Returns `Self::Error` if the transport's native message type cannot represent the
19 /// envelope (e.g. a field it cannot carry).
20 fn encode(&self, envelope: &SerializedEnvelope) -> Result<M, Self::Error>;
21
22 /// Decodes a transport message back into a canonical envelope.
23 ///
24 /// # Errors
25 ///
26 /// Returns `Self::Error` if the transport message cannot be decoded into a canonical
27 /// envelope (a missing required framework header, or a malformed one).
28 fn decode(&self, message: M) -> Result<SerializedEnvelope, Self::Error>;
29}