use serde::{Serialize, Deserialize}; use shm_rs::scheme_composer::composer::from_struct; use shm_rs::serializator::serializator; use shm_rs::static_scheme::init; use shm_rs::dynamic_scheme::environment; #[derive(Clone, Debug, Serialize, Deserialize)] pub enum MsgType { Syslognet, Other, Syslogfile } pub const APPNAME: &'static str = "appname"; pub const PORT: &'static str = "port"; pub const MSG: &'static str = "msg"; pub const HOST: &'static str = "host"; pub const USER: &'static str = "user"; pub const TIMESTAMP: &'static str = "timestamp"; #[derive(Clone, Debug, Serialize, Deserialize)] pub enum TimeDecodeFormat { DateTimeFormat{ dt: String }, TimeRegFormat{ t: String, r: String }, TimeFormat{ t: String } } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct JsonTagField { pub tag: String, pub field_path: Vec } #[derive(Clone, Debug, Serialize, Deserialize)] pub enum LdLogStructFormat { Text{ msg_type: MsgType, regex: String, td: TimeDecodeFormat }, Json{ td: TimeDecodeFormat, tag_field: Vec } } pub fn main() { // static let mut curdir = std::env::current_dir().unwrap(); curdir.push("examples/struct_to_scheme/advanced2"); println!("{}", curdir.display()); let schm = init::SchemeInit::new_with_path(curdir).unwrap(); let res = schm.run_from_file("logformats.shm", None).unwrap(); let resser = res.get("logformats").unwrap().clone(); // dynamic let mut curdir = std::env::current_dir().unwrap(); curdir.push("examples/struct_to_scheme/advanced2/nginx.shm"); let (_, dynres) = environment::DynEnvironment::from_file(curdir, resser.clone()).unwrap(); // serialize dyn let ret = serializator::Serialization::serialize(resser.clone(), dynres.clone()).unwrap(); let serialized = serde_json::to_string(&ret).unwrap(); /* let mut rc = RustCode::new(&["Clone", "Debug", "Serialize", "Deserialize"], &["Clone", "Debug", "Serialize", "Deserialize"]); println!("Structures: "); match resser.generate_rust_structs(&mut rc) { Ok(_) => { println!("{}", rc); }, Err(e) => { println!("{}", e); } } */ let n: LdLogStructFormat = serde_json::from_str(&serialized).unwrap(); let resser = from_struct(n, resser); if resser.is_err() == true { panic!("{}", resser.err().unwrap()); } else { println!("{}", resser.unwrap()); } }