switchback_traits/traits/codec.rs
1//! Switchback serialization seam (async primary + sync secondary).
2
3use crate::{ReferenceManual, Result};
4
5/// Async codec for I/O-backed serialize/deserialize of [`ReferenceManual`] artifacts.
6///
7/// Primary API per [ADR 0002](https://github.com/canardleteer/switchback-rs/blob/main/docs/adr/0002-async-first-traits-with-synchronous-secondary-apis-in-switchback-traits.md).
8/// Implementations live in codec crates (e.g. protobuf switchback wire format).
9pub trait SwitchbackCodec: Send + Sync {
10 /// Serializes a reference manual to switchback wire bytes.
11 async fn serialize(&self, manual: &ReferenceManual) -> Result<Vec<u8>>;
12
13 /// Deserializes switchback wire bytes into a reference manual.
14 async fn deserialize(&self, bytes: &[u8]) -> Result<ReferenceManual>;
15}
16
17/// Synchronous compatibility API for callers that cannot wrap [`SwitchbackCodec`].
18///
19/// Secondary API per ADR 0002. Prefer [`SwitchbackCodec`] for service-side pipelines.
20pub trait SyncSwitchbackCodec: Send + Sync {
21 /// Serializes a reference manual to switchback wire bytes.
22 fn serialize(&self, manual: &ReferenceManual) -> Result<Vec<u8>>;
23
24 /// Deserializes switchback wire bytes into a reference manual.
25 fn deserialize(&self, bytes: &[u8]) -> Result<ReferenceManual>;
26}