1use crate::Encoding;
4
5#[derive(Debug, Clone, Copy)]
9#[repr(C)]
10pub struct MsgHeader {
11 pub version: u16,
13 pub header_len: u16,
15 pub encoding: u16,
17 pub flags: u16,
19 pub correlation_id: u64,
21 pub deadline_ns: u64,
23}
24
25pub const MSG_HEADER_VERSION: u16 = 1;
27
28pub const MSG_HEADER_SIZE: usize = core::mem::size_of::<MsgHeader>();
30
31const _: () = assert!(MSG_HEADER_SIZE == 24);
32
33impl MsgHeader {
34 pub const fn new() -> Self {
36 Self {
37 version: MSG_HEADER_VERSION,
38 header_len: MSG_HEADER_SIZE as u16,
39 encoding: Encoding::Postcard as u16,
40 flags: 0,
41 correlation_id: 0,
42 deadline_ns: 0,
43 }
44 }
45
46 pub fn encoding(&self) -> Option<Encoding> {
48 Encoding::from_u16(self.encoding)
49 }
50
51 pub fn set_encoding(&mut self, encoding: Encoding) {
53 self.encoding = encoding as u16;
54 }
55}
56
57impl Default for MsgHeader {
58 fn default() -> Self {
59 Self::new()
60 }
61}