Skip to main content

weida_protocol/
lib.rs

1//! weida wire protocol v0: framing, CBOR headers, negotiation and QUIC
2//! application error codes.
3//!
4//! The crate performs no I/O. It parses and encodes byte slices, which makes it
5//! directly fuzzable and keeps hostile-input handling in one place. Every
6//! decoder treats its input as hostile: lengths are checked before allocation,
7//! duplicate map keys are rejected and nesting depth is bounded.
8//!
9//! `docs/PROTOCOL.md` is the normative specification; this crate is its
10//! implementation, and the golden vectors in ยง8 are asserted byte-for-byte by
11//! the unit tests.
12
13pub mod codes;
14pub mod datagram;
15pub mod frame;
16pub mod header;
17pub mod negotiate;
18pub mod varint;
19
20pub use datagram::{LOCAL_MAX_DATAGRAM, flow_prefix, split_flow_datagram};
21pub use frame::{
22    FrameKind, MAGIC, MAX_PREAMBLE_LEN, Preamble, PreambleError, encode_frame, encode_preamble,
23    parse_preamble, preamble_bytes,
24};
25pub use header::{
26    CreditHeader, CursorHeader, CursorLevel, DataHeader, ErrorHeader, FlowHeader, HeaderError,
27    Hello, PathRecord, ReportHead, ReportMode, SubscriptionHeader, decode_cursor_record,
28    encode_cursor_record, filter, limits as header_limits,
29};
30pub use negotiate::{
31    Agreed, CAPABILITY_DATAGRAM, CAPABILITY_PATH_REPORT, NegotiateError, negotiate,
32};
33pub use varint::{VarintError, decode_varint, encode_varint, varint_len};
34
35/// Wire protocol version implemented by this crate (experimental).
36pub const VERSION: u64 = 0;
37
38/// TLS ALPN token identifying the weida native QUIC protocol.
39pub const ALPN: &[u8] = b"weida/0";
40
41#[cfg(test)]
42mod tests {
43    #[test]
44    fn alpn_matches_the_wire_version() {
45        assert_eq!(super::ALPN, b"weida/0");
46        assert_eq!(super::VERSION, 0);
47    }
48}