1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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()
{

// 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());
    }
}