    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

    // use std::collections::HashMap;
    use serde::{Deserialize,Serialize};

    fn default_empty() -> String {
      "/".to_string()
    }
    fn default_tracedata_items() -> Vec<TraceContent> {
      Vec::new()
    }

    #[derive(Default,Deserialize,Serialize,Debug,Clone)]
    pub struct TraceContent {
        #[serde(default = "default_empty")]
        pub when: String,
        #[serde(default = "default_empty")]
        pub sid: String,
        #[serde(default = "default_empty")]
        pub origin: String,
        #[serde(default = "default_empty")]
        pub trigger: String,
        #[serde(default = "default_empty")]
        pub id: String,
        #[serde(default = "default_empty")]
        pub info: String,
        #[serde(default = "default_empty")]
        pub context: String,
        #[serde(default = "default_empty")]
        pub role: String,
    }
    impl TraceContent {
        #[allow(dead_code)]
        pub fn to_json(&self) -> String {
            serde_json::to_string(self).unwrap_or_else(|e|{
                println!("Error to convert TraceContent to json: {}",e);
                String::from("")
            })
        }
    }

    #[derive(Default,Deserialize,Serialize,Debug,Clone)]
    pub struct TraceData {
        #[serde(default = "default_empty")]
        pub server: String,
        #[serde(default = "default_empty")]
        pub timestamp: String,
        #[serde(default = "default_tracedata_items")]
        pub contents: Vec<TraceContent>,
    }
    impl TraceData {
        #[allow(dead_code)]
        pub fn contents_to_json(&self) -> Vec<String> {
            self.contents.clone().into_iter().map(|item| item.to_json()).collect()
        }
    }