rapace_core/
descriptor.rs1use crate::FrameFlags;
4
5pub const INLINE_PAYLOAD_SIZE: usize = 16;
7
8pub const INLINE_PAYLOAD_SLOT: u32 = u32::MAX;
10
11pub const NO_DEADLINE: u64 = u64::MAX;
13
14#[derive(Clone, Copy)]
19#[repr(C, align(64))]
20pub struct MsgDescHot {
21 pub msg_id: u64,
24 pub channel_id: u32,
26 pub method_id: u32,
28
29 pub payload_slot: u32,
32 pub payload_generation: u32,
34 pub payload_offset: u32,
36 pub payload_len: u32,
38
39 pub flags: FrameFlags,
42 pub credit_grant: u32,
44 pub deadline_ns: u64,
46
47 pub inline_payload: [u8; INLINE_PAYLOAD_SIZE],
51}
52
53const _: () = assert!(core::mem::size_of::<MsgDescHot>() == 64);
54
55impl MsgDescHot {
56 pub const fn new() -> Self {
58 Self {
59 msg_id: 0,
60 channel_id: 0,
61 method_id: 0,
62 payload_slot: INLINE_PAYLOAD_SLOT,
63 payload_generation: 0,
64 payload_offset: 0,
65 payload_len: 0,
66 flags: FrameFlags::empty(),
67 credit_grant: 0,
68 deadline_ns: NO_DEADLINE,
69 inline_payload: [0; INLINE_PAYLOAD_SIZE],
70 }
71 }
72
73 #[inline]
75 pub const fn has_deadline(&self) -> bool {
76 self.deadline_ns != NO_DEADLINE
77 }
78
79 #[inline]
83 pub fn is_expired(&self, now_ns: u64) -> bool {
84 self.deadline_ns != NO_DEADLINE && now_ns > self.deadline_ns
85 }
86
87 #[inline]
89 pub const fn is_inline(&self) -> bool {
90 self.payload_slot == INLINE_PAYLOAD_SLOT
91 }
92
93 #[inline]
95 pub const fn is_control(&self) -> bool {
96 self.channel_id == 0
97 }
98
99 #[inline]
101 pub fn inline_payload(&self) -> &[u8] {
102 &self.inline_payload[..self.payload_len as usize]
103 }
104}
105
106impl Default for MsgDescHot {
107 fn default() -> Self {
108 Self::new()
109 }
110}
111
112impl core::fmt::Debug for MsgDescHot {
113 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
114 f.debug_struct("MsgDescHot")
115 .field("msg_id", &self.msg_id)
116 .field("channel_id", &self.channel_id)
117 .field("method_id", &self.method_id)
118 .field("payload_slot", &self.payload_slot)
119 .field("payload_generation", &self.payload_generation)
120 .field("payload_offset", &self.payload_offset)
121 .field("payload_len", &self.payload_len)
122 .field("flags", &self.flags)
123 .field("credit_grant", &self.credit_grant)
124 .field("deadline_ns", &self.deadline_ns)
125 .field("is_inline", &self.is_inline())
126 .finish()
127 }
128}
129
130#[derive(Debug, Clone, Copy, Default)]
135#[repr(C, align(64))]
136pub struct MsgDescCold {
137 pub msg_id: u64,
139 pub trace_id: u64,
141 pub span_id: u64,
143 pub parent_span_id: u64,
145 pub timestamp_ns: u64,
147 pub debug_level: u32,
149 pub _reserved: u32,
150}
151
152const _: () = assert!(core::mem::size_of::<MsgDescCold>() == 64);