use std::ops::{RangeInclusive, Range};
use serde::{Serialize, Deserialize};
use shm_rs::lexer::lexer;
use shm_rs::scheme_composer::composer::from_struct;
use shm_rs::serializator::serializator;
use shm_rs::static_scheme::generator::RustCode;
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<String>
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum LdLogStructFormat
{
Text{ msg_type: MsgType, regex: String, td: TimeDecodeFormat },
Json{ td: TimeDecodeFormat, tag_field: Vec<JsonTagField> }
}
pub fn main()
{
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();
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();
let ret = serializator::Serialization::serialize(resser.clone(), dynres.clone()).unwrap();
let serialized = serde_json::to_string(&ret).unwrap();
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());
}
}