Skip to main content

nexus_web/ws/
frame.rs

1/// Wire-level opcode (internal).
2#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3pub(crate) enum RawOpcode {
4    Continuation,
5    Text,
6    Binary,
7    Close,
8    Ping,
9    Pong,
10}
11
12impl RawOpcode {
13    pub(crate) fn from_u8(v: u8) -> Option<Self> {
14        match v {
15            0x0 => Some(Self::Continuation),
16            0x1 => Some(Self::Text),
17            0x2 => Some(Self::Binary),
18            0x8 => Some(Self::Close),
19            0x9 => Some(Self::Ping),
20            0xA => Some(Self::Pong),
21            _ => None,
22        }
23    }
24
25    pub(crate) fn is_control(self) -> bool {
26        matches!(self, Self::Close | Self::Ping | Self::Pong)
27    }
28}
29
30/// Determines masking behavior per RFC 6455.
31#[derive(Debug, Clone, Copy, PartialEq, Eq)]
32pub enum Role {
33    /// WebSocket client: must mask outbound, expects unmasked inbound.
34    Client,
35    /// WebSocket server: must not mask outbound, expects masked inbound.
36    Server,
37}