Skip to main content

pim_protocol/
frame_type.rs

1//! Shared discriminator for the outer transport envelope.
2
3use pim_core::PimError;
4
5/// Identifies the type of payload inside a TransportFrame.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7#[repr(u8)]
8pub enum FrameType {
9    /// Authenticated handshake message.
10    Handshake = 0x01,
11    /// Mesh data payload.
12    Data = 0x02,
13    /// Route advertisement payload.
14    RouteUpdate = 0x03,
15    /// Periodic heartbeat payload.
16    Heartbeat = 0x04,
17    /// Control-plane request or response payload.
18    Control = 0x05,
19    /// Packet fragment payload.
20    Fragment = 0x06,
21}
22
23impl FrameType {
24    /// Decode a raw frame-type tag from the wire.
25    pub fn from_u8(value: u8) -> Result<Self, PimError> {
26        match value {
27            0x01 => Ok(Self::Handshake),
28            0x02 => Ok(Self::Data),
29            0x03 => Ok(Self::RouteUpdate),
30            0x04 => Ok(Self::Heartbeat),
31            0x05 => Ok(Self::Control),
32            0x06 => Ok(Self::Fragment),
33            other => Err(PimError::Protocol(format!(
34                "unknown frame type: 0x{other:02x}"
35            ))),
36        }
37    }
38}