//! Cap'n Proto schemas, generated types, and serialisation helpers for quicnprotochat. //! //! # Design constraints //! //! This crate is intentionally restricted: //! - **No crypto** — key material never enters this crate. //! - **No I/O** — callers own transport; this crate only converts bytes ↔ types. //! - **No async** — pure synchronous data-layer code. //! //! # Generated code //! //! `build.rs` invokes `capnpc` at compile time and writes generated Rust source //! into `$OUT_DIR`. The `include!` macros below splice that code in as a module. // ── Generated types ─────────────────────────────────────────────────────────── /// Cap'n Proto generated types for `schemas/auth.capnp`. /// /// Do not edit this module by hand — it is entirely machine-generated. pub mod auth_capnp { include!(concat!(env!("OUT_DIR"), "/auth_capnp.rs")); } /// Cap'n Proto generated types for `schemas/delivery.capnp`. /// /// Do not edit this module by hand — it is entirely machine-generated. pub mod delivery_capnp { include!(concat!(env!("OUT_DIR"), "/delivery_capnp.rs")); } /// Cap'n Proto generated types for `schemas/node.capnp`. /// /// Do not edit this module by hand — it is entirely machine-generated. pub mod node_capnp { include!(concat!(env!("OUT_DIR"), "/node_capnp.rs")); } // ── Low-level byte ↔ message conversions ────────────────────────────────────── /// Serialise a Cap'n Proto message builder to unpacked wire bytes. /// /// The output includes the segment table header. For transport, the /// `quicnprotochat-core` frame codec prepends a 4-byte little-endian length field. pub fn to_bytes( msg: &capnp::message::Builder, ) -> Result, capnp::Error> { let mut buf = Vec::new(); capnp::serialize::write_message(&mut buf, msg)?; Ok(buf) } /// Deserialise unpacked wire bytes into a message with owned segments. /// /// Uses `ReaderOptions::new()` (default limits: 64 MiB, 512 nesting levels). /// Callers that receive data from untrusted peers should consider tightening /// the traversal limit via `ReaderOptions::traversal_limit_in_words`. pub fn from_bytes( bytes: &[u8], ) -> Result, capnp::Error> { let mut cursor = std::io::Cursor::new(bytes); capnp::serialize::read_message(&mut cursor, capnp::message::ReaderOptions::new()) }