use num_enum::TryFromPrimitive;
#[derive(Debug, Clone)]
pub struct Abbreviation {
pub fields: Vec<ScalarOperand>,
pub payload: Option<PayloadOperand>,
pub id: u32,
}
#[derive(Debug, Copy, Clone)]
pub enum ScalarOperand {
Literal(u64),
Fixed(u8),
Vbr(u8),
Char6,
}
#[derive(Debug, Copy, Clone)]
pub enum PayloadOperand {
Blob,
Array(ScalarOperand),
}
#[derive(Debug, Copy, Clone)]
pub enum Operand {
Scalar(ScalarOperand),
Payload(PayloadOperand),
}
impl Operand {
#[must_use]
pub fn is_payload(&self) -> bool {
matches!(self, Self::Payload(_))
}
#[must_use]
pub fn is_literal(&self) -> bool {
matches!(self, Self::Scalar(ScalarOperand::Literal(_)))
}
#[must_use]
pub fn is_array(&self) -> bool {
matches!(self, Self::Payload(PayloadOperand::Array(_)))
}
#[must_use]
pub fn is_blob(&self) -> bool {
matches!(self, Self::Payload(PayloadOperand::Blob))
}
#[must_use]
pub fn encoded_kind(&self) -> u8 {
match self {
Self::Scalar(ScalarOperand::Literal(_)) => 0,
Self::Scalar(ScalarOperand::Fixed(_)) => 1,
Self::Scalar(ScalarOperand::Vbr(_)) => 2,
Self::Payload(PayloadOperand::Array(_)) => 3,
Self::Scalar(ScalarOperand::Char6) => 4,
Self::Payload(PayloadOperand::Blob) => 5,
}
}
}
#[derive(Debug, Clone, Copy, TryFromPrimitive)]
#[repr(u8)]
pub enum BlockInfoCode {
SetBid = 1,
BlockName = 2,
SetRecordName = 3,
}
#[derive(Debug, Clone, Copy, TryFromPrimitive)]
#[repr(u32)]
pub enum BuiltinAbbreviationId {
EndBlock = 0,
EnterSubBlock = 1,
DefineAbbreviation = 2,
UnabbreviatedRecord = 3,
}