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 frame;
15pub mod header;
16pub mod negotiate;
17pub mod varint;
18
19pub use frame::{
20    FrameKind, MAGIC, MAX_PREAMBLE_LEN, Preamble, PreambleError, encode_frame, encode_preamble,
21    parse_preamble, preamble_bytes,
22};
23pub use header::{
24    CreditHeader, CursorHeader, CursorLevel, DataHeader, ErrorHeader, HeaderError, Hello,
25    ReportMode, SubscriptionHeader, decode_cursor_record, encode_cursor_record, filter,
26    limits as header_limits,
27};
28pub use negotiate::{Agreed, NegotiateError, negotiate};
29pub use varint::{VarintError, decode_varint, encode_varint, varint_len};
30
31/// Wire protocol version implemented by this crate (experimental).
32pub const VERSION: u64 = 0;
33
34/// TLS ALPN token identifying the weida native QUIC protocol.
35pub const ALPN: &[u8] = b"weida/0";
36
37#[cfg(test)]
38mod tests {
39    #[test]
40    fn alpn_matches_the_wire_version() {
41        assert_eq!(super::ALPN, b"weida/0");
42        assert_eq!(super::VERSION, 0);
43    }
44}