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 /// Don't send a reply frame for this request.
26 ///
27 /// This is intended for fire-and-forget notifications where the caller
28 /// does not want to register a pending waiter or receive an error response.
29 const NO_REPLY = 0b0001_0000_0000;
30 }
31}
32
33/// Body encoding format.
34#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
35#[repr(u16)]
36pub enum Encoding {
37 /// Default: postcard via facet (not serde).
38 Postcard = 1,
39 /// JSON for debugging and external tooling.
40 Json = 2,
41 /// Application-defined, no schema.
42 Raw = 3,
43}
44
45impl Encoding {
46 /// Try to convert from a raw u16 value.
47 pub fn from_u16(value: u16) -> Option<Self> {
48 match value {
49 1 => Some(Self::Postcard),
50 2 => Some(Self::Json),
51 3 => Some(Self::Raw),
52 _ => None,
53 }
54 }
55}