#[derive(Debug, Clone)]
pub struct Protocol {
pub name: String,
pub constants: Vec<Constant>,
pub types: Vec<TypeDef>,
pub procedures: Vec<Procedure>,
}
impl Protocol {
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
constants: Vec::new(),
types: Vec::new(),
procedures: Vec::new(),
}
}
}
#[derive(Debug, Clone)]
pub struct Constant {
pub name: String,
pub value: ConstValue,
}
#[derive(Debug, Clone)]
pub enum ConstValue {
Int(i64),
Ident(String),
}
#[derive(Debug, Clone)]
pub enum TypeDef {
Struct(StructDef),
Enum(EnumDef),
Union(UnionDef),
Typedef(TypedefDef),
}
#[derive(Debug, Clone)]
pub struct StructDef {
pub name: String,
pub fields: Vec<Field>,
}
#[derive(Debug, Clone)]
pub struct Field {
pub name: String,
pub ty: Type,
}
#[derive(Debug, Clone)]
pub struct EnumDef {
pub name: String,
pub variants: Vec<EnumVariant>,
}
#[derive(Debug, Clone)]
pub struct EnumVariant {
pub name: String,
pub value: Option<ConstValue>,
}
#[derive(Debug, Clone)]
pub struct UnionDef {
pub name: String,
pub discriminant: Field,
pub cases: Vec<UnionCase>,
pub default: Option<Box<Type>>,
}
#[derive(Debug, Clone)]
pub struct UnionCase {
pub values: Vec<ConstValue>,
pub field: Option<Field>,
}
#[derive(Debug, Clone)]
pub struct TypedefDef {
pub name: String,
pub target: Type,
}
#[derive(Debug, Clone)]
pub enum Type {
Void,
Int,
UInt,
Hyper,
UHyper,
Float,
Double,
Bool,
String { max_len: Option<u32> },
Opaque { len: LengthSpec },
Array {
elem: Box<Type>,
len: LengthSpec,
},
Optional(Box<Type>),
Named(String),
}
#[derive(Debug, Clone)]
pub enum LengthSpec {
Fixed(u32),
Variable { max: Option<u32> },
}
#[derive(Debug, Clone)]
pub struct Procedure {
pub name: String,
pub number: u32,
pub args: Option<String>,
pub ret: Option<String>,
pub priority: Priority,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Priority {
#[default]
Low,
High,
}