driven/binary/
rule_schema.rs1use bytemuck::{Pod, Zeroable};
6
7pub use super::infinity_format::{RuleFlags, SectionOffsets};
8
9#[repr(C)]
11#[derive(Debug, Clone, Copy, Pod, Zeroable)]
12pub struct BinaryRule {
13 pub rule_id: u16,
15 pub category: u8,
17 pub priority: u8,
19 pub pattern: u32,
21 pub description: u32,
23}
24
25impl BinaryRule {
26 pub fn new(rule_id: u16, category: u8, priority: u8, pattern: u32, description: u32) -> Self {
28 Self {
29 rule_id,
30 category,
31 priority,
32 pattern,
33 description,
34 }
35 }
36
37 pub const fn size() -> usize {
39 std::mem::size_of::<Self>()
40 }
41}
42
43#[repr(C)]
45#[derive(Debug, Clone, Copy, Pod, Zeroable)]
46pub struct BinaryStep {
47 pub step_id: u16,
49 pub action_count: u16,
51 pub name: u32,
53 pub description: u32,
55 pub condition: u32,
57 pub _reserved: u32,
59}
60
61impl BinaryStep {
62 pub fn new(step_id: u16, name: u32, description: u32) -> Self {
64 Self {
65 step_id,
66 action_count: 0,
67 name,
68 description,
69 condition: 0,
70 _reserved: 0,
71 }
72 }
73
74 pub const fn size() -> usize {
76 std::mem::size_of::<Self>()
77 }
78}
79
80#[repr(C)]
82#[derive(Debug, Clone, Copy, Pod, Zeroable)]
83pub struct BinaryPersona {
84 pub name: u32,
86 pub role: u32,
88 pub identity: u32,
90 pub style: u32,
92 pub expertise_level: u8,
94 pub trait_count: u8,
96 pub principle_count: u8,
98 pub behavior_flags: u8,
100}
101
102impl BinaryPersona {
103 pub const fn size() -> usize {
105 std::mem::size_of::<Self>()
106 }
107}
108
109#[repr(C)]
111#[derive(Debug, Clone, Copy, Pod, Zeroable)]
112pub struct BinaryStandardsHeader {
113 pub rule_count: u16,
115 pub category_table_offset: u16,
117 pub priority_index_offset: u32,
119}
120
121impl BinaryStandardsHeader {
122 pub const fn size() -> usize {
124 std::mem::size_of::<Self>()
125 }
126}
127
128#[repr(C)]
130#[derive(Debug, Clone, Copy, Pod, Zeroable)]
131pub struct BinaryContext {
132 pub include_count: u16,
134 pub exclude_count: u16,
136 pub focus_count: u16,
138 pub _reserved: u16,
140}
141
142impl BinaryContext {
143 pub const fn size() -> usize {
145 std::mem::size_of::<Self>()
146 }
147}
148
149#[repr(C)]
151#[derive(Debug, Clone, Copy, Pod, Zeroable)]
152pub struct BinarySignature {
153 pub algorithm: u8,
155 pub _reserved: [u8; 3],
157 pub public_key: [u8; 32],
159 pub signature: [u8; 64],
161}
162
163impl BinarySignature {
164 pub const ED25519: u8 = 1;
166
167 pub const fn size() -> usize {
169 std::mem::size_of::<Self>()
170 }
171
172 pub fn empty() -> Self {
174 Self {
175 algorithm: 0,
176 _reserved: [0; 3],
177 public_key: [0; 32],
178 signature: [0; 64],
179 }
180 }
181}
182
183#[cfg(test)]
184mod tests {
185 use super::*;
186
187 #[test]
188 fn test_binary_rule_size() {
189 assert_eq!(BinaryRule::size(), 12);
190 }
191
192 #[test]
193 fn test_binary_step_size() {
194 assert_eq!(BinaryStep::size(), 20);
195 }
196
197 #[test]
198 fn test_binary_persona_size() {
199 assert_eq!(BinaryPersona::size(), 20);
200 }
201
202 #[test]
203 fn test_binary_signature_size() {
204 assert!(BinarySignature::size() >= 100);
206 }
207}