mod decoder;
mod encoder;
mod schema;
mod versioning;
pub use decoder::DrvDecoder;
pub use encoder::DrvEncoder;
pub use schema::{
ContextSection, DrvHeader, PersonaSection, RuleCategory, RuleEntry, StandardsSection,
WorkflowSection, WorkflowStep,
};
pub use versioning::{FormatVersion, VersionMigrator};
pub const DRV_MAGIC: [u8; 4] = *b"DRV\0";
pub const DRV_VERSION: u16 = 1;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u8)]
pub enum SectionType {
StringTable = 0x01,
Persona = 0x02,
Standards = 0x03,
Context = 0x04,
Workflow = 0x05,
}
impl TryFrom<u8> for SectionType {
type Error = crate::DrivenError;
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0x01 => Ok(SectionType::StringTable),
0x02 => Ok(SectionType::Persona),
0x03 => Ok(SectionType::Standards),
0x04 => Ok(SectionType::Context),
0x05 => Ok(SectionType::Workflow),
_ => Err(crate::DrivenError::InvalidBinary(format!(
"Unknown section type: 0x{:02x}",
value
))),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_magic_bytes() {
assert_eq!(&DRV_MAGIC, b"DRV\0");
}
#[test]
fn test_section_type_roundtrip() {
let types = [
SectionType::StringTable,
SectionType::Persona,
SectionType::Standards,
SectionType::Context,
SectionType::Workflow,
];
for t in types {
let byte = t as u8;
let back = SectionType::try_from(byte).unwrap();
assert_eq!(t, back);
}
}
}