Skip to main content

gbp_core/
flags.rs

1//! GBP frame delivery flags.
2//!
3//! * `O` (ordered)  — preserve in-stream ordering.
4//! * `R` (reliable) — retransmit until ACK / NACK / timeout.
5//! * `A` (ack-req)  — acknowledgement is mandatory.
6//! * `S` (system)   — control plane frame; receiver MUST process it before
7//!   application delivery.
8//! * `C` (critical) — frame MUST match the receiver's current `transition_id`.
9
10/// Bit set on top of `u16`. Hand-rolled to keep `gbp-core` free of any
11/// dependency tree.
12#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
13pub struct GbpFlags(pub u16);
14
15impl GbpFlags {
16    /// Bit 0: ordered.
17    pub const ORDERED: u16 = 0x0001;
18    /// Bit 1: reliable.
19    pub const RELIABLE: u16 = 0x0002;
20    /// Bit 2: ack required.
21    pub const ACK_REQ: u16 = 0x0004;
22    /// Bit 3: system frame.
23    pub const SYSTEM: u16 = 0x0008;
24    /// Bit 4: critical (must match the current transition_id).
25    pub const CRITICAL: u16 = 0x0010;
26
27    /// Constructs a flag set from raw bits.
28    pub const fn from_bits(bits: u16) -> Self {
29        Self(bits)
30    }
31
32    /// Returns `true` if the given bit is set.
33    pub const fn has(self, bit: u16) -> bool {
34        self.0 & bit != 0
35    }
36
37    /// `O | R | A` profile — chat / signaling messages.
38    pub const fn ordered_reliable_ack() -> u16 {
39        Self::ORDERED | Self::RELIABLE | Self::ACK_REQ
40    }
41
42    /// `O | R | S` profile — control plane (system).
43    pub const fn ordered_reliable_system() -> u16 {
44        Self::ORDERED | Self::RELIABLE | Self::SYSTEM
45    }
46
47    /// `O` profile — best-effort ordered (voice and other real-time media).
48    pub const fn ordered_only() -> u16 {
49        Self::ORDERED
50    }
51}