rapace_core/
flags.rs

1//! Frame flags and encoding types.
2
3use bitflags::bitflags;
4
5bitflags! {
6    /// Flags carried in each frame descriptor.
7    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8    pub struct FrameFlags: u32 {
9        /// Regular data frame.
10        const DATA          = 0b0000_0001;
11        /// Control frame (channel 0).
12        const CONTROL       = 0b0000_0010;
13        /// End of stream (half-close).
14        const EOS           = 0b0000_0100;
15        /// Cancel this channel.
16        const CANCEL        = 0b0000_1000;
17        /// Error response.
18        const ERROR         = 0b0001_0000;
19        /// Priority scheduling hint.
20        const HIGH_PRIORITY = 0b0010_0000;
21        /// Contains credit grant.
22        const CREDITS       = 0b0100_0000;
23        /// Headers/trailers only, no body.
24        const METADATA_ONLY = 0b1000_0000;
25    }
26}
27
28/// Body encoding format.
29#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
30#[repr(u16)]
31pub enum Encoding {
32    /// Default: postcard via facet (not serde).
33    Postcard = 1,
34    /// JSON for debugging and external tooling.
35    Json = 2,
36    /// Application-defined, no schema.
37    Raw = 3,
38}
39
40impl Encoding {
41    /// Try to convert from a raw u16 value.
42    pub fn from_u16(value: u16) -> Option<Self> {
43        match value {
44            1 => Some(Self::Postcard),
45            2 => Some(Self::Json),
46            3 => Some(Self::Raw),
47            _ => None,
48        }
49    }
50}