pub mod package;
use crate::constants::Constants;
use crate::types::ResolvedType;
use canadensis_bit_length_set::BitLengthSet;
#[derive(Debug)]
pub struct CompiledDsdl {
pub fixed_port_id: Option<u32>,
pub kind: DsdlKind,
}
#[derive(Debug)]
pub enum DsdlKind {
Message(Message),
Service { request: Message, response: Message },
}
#[derive(Debug, Clone)]
pub struct Message {
pub(crate) deprecated: bool,
pub(crate) extent: Extent,
pub(crate) kind: MessageKind,
pub(crate) bit_length: BitLengthSet,
pub(crate) constants: Constants,
}
impl Message {
pub fn deprecated(&self) -> bool {
self.deprecated
}
pub fn extent(&self) -> &Extent {
&self.extent
}
pub fn kind(&self) -> &MessageKind {
&self.kind
}
pub fn bit_length(&self) -> &BitLengthSet {
&self.bit_length
}
pub fn constants(&self) -> &Constants {
&self.constants
}
}
#[derive(Debug, Clone)]
pub enum Extent {
Sealed,
Delimited(u64),
}
#[derive(Debug, Clone)]
pub enum MessageKind {
Struct(Struct),
Union(Union),
}
#[derive(Debug, Clone)]
pub struct Struct {
pub fields: Vec<Field>,
}
#[derive(Debug, Clone)]
pub struct Union {
pub discriminant_bits: u8,
pub variants: Vec<Variant>,
}
#[derive(Debug, Clone)]
pub struct Field {
kind: FieldKind,
always_aligned: bool,
}
impl Field {
pub fn kind(&self) -> &FieldKind {
&self.kind
}
pub fn always_aligned(&self) -> bool {
self.always_aligned
}
}
#[derive(Debug, Clone)]
pub enum FieldKind {
Padding(u8),
Data { ty: ResolvedType, name: String },
}
impl Field {
pub(crate) fn data(ty: ResolvedType, name: String, always_aligned: bool) -> Self {
Field {
kind: FieldKind::Data { ty, name },
always_aligned,
}
}
pub(crate) fn padding(bits: u8, always_aligned: bool) -> Self {
Field {
kind: FieldKind::Padding(bits),
always_aligned,
}
}
pub fn name(&self) -> Option<&str> {
match &self.kind {
FieldKind::Padding(_) => None,
FieldKind::Data { name, .. } => Some(&*name),
}
}
}
#[derive(Debug, Clone)]
pub struct Variant {
pub ty: ResolvedType,
pub name: String,
}
impl Variant {
pub(crate) fn new(ty: ResolvedType, name: String) -> Self {
Variant { ty, name }
}
}