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
use std::fmt::Display;

use libc::c_void;
use serde_json;

pub enum LevelKind {
    Signed,
    Float,
}

pub enum RawType {
    Level(LevelKind),
    Counter,
    State,
}

pub trait Value: Display + Assign {
    fn raw_type(&self) -> RawType;
    fn raw_size(&self) -> usize;
    fn as_json(&self) -> serde_json::Value;
}

pub trait Assign {
    fn assign(&self, ptr: *mut c_void);
    fn reset(&self);
}

impl RawType {
    pub fn as_json_str(&self) -> &'static str {
        use self::RawType::*;

        match *self {
            Level(_) => "level",
            Counter => "counter",
            State => "state",
        }
    }
    pub fn main_type(&self) -> &'static str {
        use self::RawType::*;

        match *self {
            Level(_) => "level",
            Counter => "counter",
            State => "state",
        }
    }
    pub fn type_suffix(&self) -> Option<&'static str> {
        use self::RawType::*;
        use self::LevelKind::*;

        match *self {
            Level(Signed) => Some("signed"),
            Level(Float) => Some("float"),
            Counter => None,
            State => None,
        }
    }
}