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
use std::fmt::{Display, Debug};
use libc::c_void;
use serde_json;
pub enum LevelKind {
Signed,
Float,
}
pub enum RawType {
Level(LevelKind),
Counter,
State,
}
pub trait Value: Display + Debug + Describe + Assign {
}
pub trait Assign {
fn assign(&self, ptr: *mut c_void);
fn copy_assign(&self, ptr: *mut c_void);
fn reset(&self);
}
pub trait Describe {
fn raw_type(&self) -> RawType;
fn raw_size(&self) -> usize;
fn as_json(&self) -> serde_json::Value;
}
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,
}
}
}