Skip to main content

thunder/wire/
mod.rs

1//! HiveLLM binary RPC wire layer — **wire v1, frozen**.
2//!
3//! One frame is `u32 LE length` + MessagePack body; the body is a
4//! [`Request`] or [`Response`] in rmp-serde's externally-tagged encoding
5//! over the 8-variant [`Value`] model. The normative byte definition lives
6//! in `docs/spec/` (transplanted family spec); this crate is bound to it by
7//! `docs/specs/SPEC-001-wire-format.md` (`WIRE-xxx` requirements).
8//!
9//! Canonicalization over the donor implementations (SPEC-001 §2):
10//! - `Bytes` is emitted as MessagePack **bin** (WIRE-010) — ~33% smaller
11//!   than the int-array form every pre-Thunder Rust server emits — while
12//!   the legacy int-array form is accepted on decode forever (WIRE-011).
13//! - `Request`/`Response` are emitted as array-encoded structs (WIRE-012);
14//!   map-shaped requests decode fine (WIRE-013, rmp-serde leniency).
15//!
16//! This crate is pure: no sockets, no product knowledge (WIRE-030). Async
17//! frame helpers are available behind the `tokio` feature.
18
19pub mod config;
20mod frame;
21mod value;
22
23pub use config::Config;
24pub use frame::{decode_frame, decode_frame_with_limit, encode_frame, DecodeError};
25pub use value::{Request, Response, Value};
26
27#[cfg(feature = "tokio")]
28pub use frame::{
29    read_frame, read_request, read_request_with_limit, read_response, read_response_with_limit,
30    write_frame, write_request, write_response,
31};
32
33/// Reserved frame id for server-initiated push frames (WIRE-005).
34///
35/// Clients must never use it as a request id; servers refuse requests
36/// carrying it; client demultiplexers route it to the push hook.
37pub const PUSH_ID: u32 = u32::MAX;
38
39/// Default frame-body cap: 64 MiB, validated against the length prefix
40/// *before* any allocation (WIRE-020). Operators tune it per profile.
41pub const DEFAULT_MAX_FRAME_BYTES: usize = 64 * 1024 * 1024;