1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
use crate::command::flyweight::Flyweight;
use crate::concurrent::atomic_buffer::AtomicBuffer;
use crate::utils::types::Index;
pub const HEADER_DEFN_SIZE: Index = std::mem::size_of::<HeaderDefn>() as Index;
#[repr(C, packed(4))]
#[derive(Copy, Clone)]
pub struct HeaderDefn {
frame_length: i32,
version: i8,
flags: i8,
h_type: i16,
}
pub struct HeaderFlyweight {
pub flyweight: Flyweight<HeaderDefn>,
}
impl HeaderFlyweight {
pub fn new(buffer: AtomicBuffer, offset: Index) -> Self {
Self {
flyweight: Flyweight::new(buffer, offset),
}
}
#[inline]
pub fn frame_length(&self) -> i32 {
unsafe { (*self.flyweight.m_struct).frame_length }
}
#[inline]
pub fn version(&self) -> i8 {
unsafe { (*self.flyweight.m_struct).version }
}
#[inline]
pub fn flags(&self) -> i8 {
unsafe { (*self.flyweight.m_struct).flags }
}
#[inline]
pub fn h_type(&self) -> i16 {
unsafe { (*self.flyweight.m_struct).h_type }
}
#[inline]
pub fn set_frame_length(&mut self, value: i32) {
unsafe {
(*self.flyweight.m_struct).frame_length = value;
}
}
#[inline]
pub fn set_version(&mut self, value: i8) {
unsafe {
(*self.flyweight.m_struct).version = value;
}
}
#[inline]
pub fn set_flags(&mut self, value: i8) {
unsafe {
(*self.flyweight.m_struct).flags = value;
}
}
#[inline]
pub fn set_h_type(&mut self, value: i16) {
unsafe {
(*self.flyweight.m_struct).h_type = value;
}
}
#[inline]
pub const fn header_length() -> Index {
HEADER_DEFN_SIZE
}
pub const HDR_TYPE_PAD: i32 = 0x00;
pub const HDR_TYPE_DATA: i32 = 0x01;
pub const HDR_TYPE_NAK: i32 = 0x02;
pub const HDR_TYPE_SM: i32 = 0x03;
pub const HDR_TYPE_ERR: i32 = 0x04;
pub const HDR_TYPE_SETUP: i32 = 0x05;
pub const HDR_TYPE_EXT: i32 = 0xFFFF;
pub const CURRENT_VERSION: i8 = 0x0;
}