Skip to main content

gbp/
lib.rs

1//! **Group Broadcast Protocol — base layer**.
2//!
3//! This crate implements the protocol substrate that every sub-protocol
4//! (`gtp-protocol`, `gap-protocol`, `gsp-protocol`) sits on top of:
5//!
6//! * [`GbpFrame`] — the CBOR-encoded transport frame.
7//! * [`ControlMessage`] — control plane message envelope.
8//! * [`ErrorObject`] — wire-serialisable error object.
9//! * [`CodecError`] — unified codec error type used across the stack.
10//!
11//! The role of GBP in the protocol family is roughly the same as IP's role in
12//! the TCP/IP stack: it provides addressed, integrity-protected delivery of
13//! opaque payloads, leaving message semantics to the layers above.
14//!
15//! See the [`gbp-core`] crate for the shared type vocabulary (StreamType,
16//! flags, FSM states, error codes).
17//!
18//! [`gbp-core`]: https://crates.io/crates/gbp-core
19
20#![deny(missing_docs)]
21
22pub mod control;
23pub mod error_object;
24pub mod frame;
25
26pub use control::ControlMessage;
27pub use error_object::ErrorObject;
28pub use frame::GbpFrame;
29
30/// Unified codec error type used by every codec in the stack.
31///
32/// GTP, GAP and GSP all return this error so that callers can handle decoding
33/// failures uniformly without having to know which sub-protocol was being
34/// parsed.
35#[derive(Debug, thiserror::Error)]
36pub enum CodecError {
37    /// CBOR decoding failure.
38    #[error("CBOR decode: {0}")]
39    Decode(String),
40    /// CBOR encoding failure (practically unreachable when writing to a `Vec`).
41    #[error("CBOR encode: {0}")]
42    Encode(String),
43    /// A length field inside the frame does not match the actual payload
44    /// length (`payload_size`, `content_length`, `args_length`, …).
45    #[error("payload_size/content_length/args_length mismatch")]
46    PayloadSizeMismatch,
47    /// An unknown enum value was observed (for example an out-of-range
48    /// `stream_type` or `signal_type`).
49    #[error("unknown enum value: {0}")]
50    UnknownEnumValue(u32),
51}