use crate::Encoding;
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct MsgHeader {
pub version: u16,
pub header_len: u16,
pub encoding: u16,
pub flags: u16,
pub correlation_id: u64,
pub deadline_ns: u64,
}
pub const MSG_HEADER_VERSION: u16 = 1;
pub const MSG_HEADER_SIZE: usize = core::mem::size_of::<MsgHeader>();
const _: () = assert!(MSG_HEADER_SIZE == 24);
impl MsgHeader {
pub const fn new() -> Self {
Self {
version: MSG_HEADER_VERSION,
header_len: MSG_HEADER_SIZE as u16,
encoding: Encoding::Postcard as u16,
flags: 0,
correlation_id: 0,
deadline_ns: 0,
}
}
pub fn encoding(&self) -> Option<Encoding> {
Encoding::from_u16(self.encoding)
}
pub fn set_encoding(&mut self, encoding: Encoding) {
self.encoding = encoding as u16;
}
}
impl Default for MsgHeader {
fn default() -> Self {
Self::new()
}
}