mirror of
https://github.com/Noratrieb/haesli.git
synced 2026-01-14 11:45:02 +01:00
codegen
This commit is contained in:
parent
e5fa49a05a
commit
d5fd9abdf7
10 changed files with 640 additions and 7 deletions
80
amqp_codegen/src/main.rs
Normal file
80
amqp_codegen/src/main.rs
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
use std::fs;
|
||||
use strong_xml::{XmlError, XmlRead};
|
||||
|
||||
#[derive(Debug, XmlRead)]
|
||||
#[xml(tag = "amqp")]
|
||||
struct Amqp {
|
||||
#[xml(child = "domain")]
|
||||
domains: Vec<Domain>,
|
||||
#[xml(child = "class")]
|
||||
classes: Vec<Class>,
|
||||
}
|
||||
|
||||
#[derive(Debug, XmlRead)]
|
||||
#[xml(tag = "domain")]
|
||||
struct Domain {
|
||||
#[xml(attr = "name")]
|
||||
name: String,
|
||||
#[xml(attr = "type")]
|
||||
kind: String,
|
||||
#[xml(child = "assert")]
|
||||
asserts: Vec<Assert>,
|
||||
}
|
||||
|
||||
#[derive(Debug, XmlRead)]
|
||||
#[xml(tag = "assert")]
|
||||
struct Assert {
|
||||
#[xml(attr = "check")]
|
||||
check: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, XmlRead)]
|
||||
#[xml(tag = "class")]
|
||||
struct Class {
|
||||
#[xml(attr = "name")]
|
||||
name: String,
|
||||
#[xml(attr = "handler")]
|
||||
handler: String,
|
||||
#[xml(attr = "index")]
|
||||
index: u16,
|
||||
#[xml(child = "method")]
|
||||
methods: Vec<Method>,
|
||||
}
|
||||
|
||||
#[derive(Debug, XmlRead)]
|
||||
#[xml(tag = "method")]
|
||||
struct Method {
|
||||
#[xml(attr = "name")]
|
||||
name: String,
|
||||
#[xml(child = "field")]
|
||||
fields: Vec<Field>,
|
||||
#[xml(attr = "index")]
|
||||
index: u16,
|
||||
}
|
||||
|
||||
#[derive(Debug, XmlRead)]
|
||||
#[xml(tag = "field")]
|
||||
struct Field {
|
||||
#[xml(attr = "name")]
|
||||
name: String,
|
||||
#[xml(attr = "domain")]
|
||||
domain: Option<String>,
|
||||
#[xml(child = "assert")]
|
||||
asserts: Vec<Assert>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let content = fs::read_to_string("./amqp-0-9-1.xml").unwrap();
|
||||
|
||||
let amqp: Result<Amqp, XmlError> = Amqp::from_str(&content);
|
||||
|
||||
match amqp {
|
||||
Ok(amqp) => {
|
||||
println!("{amqp:#?}");
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("{err}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue