1#[derive(Debug, Clone)]
5pub struct Protocol {
6 pub name: String,
7 pub constants: Vec<Constant>,
8 pub types: Vec<TypeDef>,
9 pub procedures: Vec<Procedure>,
10}
11
12impl Protocol {
13 pub fn new(name: impl Into<String>) -> Self {
14 Self {
15 name: name.into(),
16 constants: Vec::new(),
17 types: Vec::new(),
18 procedures: Vec::new(),
19 }
20 }
21}
22
23#[derive(Debug, Clone)]
25pub struct Constant {
26 pub name: String,
27 pub value: ConstValue,
28}
29
30#[derive(Debug, Clone)]
32pub enum ConstValue {
33 Int(i64),
34 Ident(String),
35}
36
37#[derive(Debug, Clone)]
39pub enum TypeDef {
40 Struct(StructDef),
41 Enum(EnumDef),
42 Union(UnionDef),
43 Typedef(TypedefDef),
44}
45
46#[derive(Debug, Clone)]
48pub struct StructDef {
49 pub name: String,
50 pub fields: Vec<Field>,
51}
52
53#[derive(Debug, Clone)]
55pub struct Field {
56 pub name: String,
57 pub ty: Type,
58}
59
60#[derive(Debug, Clone)]
62pub struct EnumDef {
63 pub name: String,
64 pub variants: Vec<EnumVariant>,
65}
66
67#[derive(Debug, Clone)]
69pub struct EnumVariant {
70 pub name: String,
71 pub value: Option<ConstValue>,
72}
73
74#[derive(Debug, Clone)]
76pub struct UnionDef {
77 pub name: String,
78 pub discriminant: Field,
79 pub cases: Vec<UnionCase>,
80 pub default: Option<Box<Type>>,
81}
82
83#[derive(Debug, Clone)]
85pub struct UnionCase {
86 pub values: Vec<ConstValue>,
87 pub field: Option<Field>,
88}
89
90#[derive(Debug, Clone)]
92pub struct TypedefDef {
93 pub name: String,
94 pub target: Type,
95}
96
97#[derive(Debug, Clone)]
99pub enum Type {
100 Void,
102 Int,
104 UInt,
106 Hyper,
108 UHyper,
110 Float,
112 Double,
114 Bool,
116 String { max_len: Option<u32> },
118 Opaque { len: LengthSpec },
120 Array {
122 elem: Box<Type>,
123 len: LengthSpec,
124 },
125 Optional(Box<Type>),
127 Named(String),
129}
130
131#[derive(Debug, Clone)]
133pub enum LengthSpec {
134 Fixed(u32),
136 Variable { max: Option<u32> },
138}
139
140#[derive(Debug, Clone)]
142pub struct Procedure {
143 pub name: String,
144 pub number: u32,
145 pub args: Option<String>,
146 pub ret: Option<String>,
147 pub priority: Priority,
148}
149
150#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
152pub enum Priority {
153 #[default]
154 Low,
155 High,
156}