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, ReportMode, SubscriptionHeader, decode_cursor_record, encode_cursor_record, filter,
28    limits as header_limits,
29};
30pub use negotiate::{Agreed, CAPABILITY_DATAGRAM, NegotiateError, negotiate};
31pub use varint::{VarintError, decode_varint, encode_varint, varint_len};
32
33/// Wire protocol version implemented by this crate (experimental).
34pub const VERSION: u64 = 0;
35
36/// TLS ALPN token identifying the weida native QUIC protocol.
37pub const ALPN: &[u8] = b"weida/0";
38
39#[cfg(test)]
40mod tests {
41    #[test]
42    fn alpn_matches_the_wire_version() {
43        assert_eq!(super::ALPN, b"weida/0");
44        assert_eq!(super::VERSION, 0);
45    }
46}