1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! # Codec Layer
//!
//! This module provides pluggable payload encoding and decoding capabilities,
//! converting application-layer data between `serde_json::Value` and wire-format
//! bytes. The protocol specification (section 7) defines the supported encoding
//! formats.
//!
//! ## Architecture Overview
//!
//! ```text
//! Codec (trait)
//! ├── CborCodec -- CBOR binary encoding (default, compact and fast to parse)
//! └── JsonCodec -- JSON text encoding (human-readable, widest compatibility)
//! ```
//!
//! ## Codec Negotiation
//!
//! During the Hello handshake phase, the client submits an ordered list of
//! preferred codecs. The server then calls [`negotiate`] to match the first
//! codec that both sides support. If no common codec is found, negotiation
//! fails with
//! [`FrameReject::CodecUnsupported`](crate::error::FrameReject::CodecUnsupported).
//!
//! ## Usage Example
//!
//! ```rust,no_run
//! use rifts::codec::{Codec, CborCodec, JsonCodec, negotiate};
//! use std::sync::Arc;
//!
//! // Register the codecs the server supports, in preference order.
//! let server_codecs: Vec<Arc<dyn Codec>> = vec![
//! Arc::new(CborCodec),
//! Arc::new(JsonCodec),
//! ];
//! ```
//!
//! ## Extending with Custom Codecs
//!
//! To add a new codec, implement the [`Codec`] trait for a zero-sized type
//! (or a struct carrying configuration) and register it alongside the
//! built-in codecs. The trait is dyn-compatible, so codecs can be stored
//! as `Arc<dyn Codec>` in collections.
pub use CborCodec;
pub use ;
pub use JsonCodec;