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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use std::io::{Read, Write};
use std::fmt;
use encoding::*;
use basic_types::*;
use date_time::*;
use status_codes::StatusCode::BadMonitoringModeInvalid;
pub type Index = UInt32;
pub type IntegerId = UInt32;
pub const MESSAGE_SECURITY_MODE_NONE: &'static str = "None";
pub const MESSAGE_SECURITY_MODE_SIGN: &'static str = "Sign";
pub const MESSAGE_SECURITY_MODE_SIGN_AND_ENCRYPT: &'static str = "SignAndEncrypt";
#[derive(Debug, Clone, PartialEq, Copy)]
pub enum MessageSecurityMode {
Invalid = 0,
None = 1,
Sign = 2,
SignAndEncrypt = 3,
}
impl BinaryEncoder<MessageSecurityMode> for MessageSecurityMode {
fn byte_len(&self) -> usize {
4
}
fn encode<S: Write>(&self, stream: &mut S) -> EncodingResult<usize> {
write_i32(stream, *self as Int32)
}
fn decode<S: Read>(stream: &mut S) -> EncodingResult<Self> {
let value = read_i32(stream)?;
Ok(match value {
0 => MessageSecurityMode::Invalid,
1 => MessageSecurityMode::None,
2 => MessageSecurityMode::Sign,
3 => MessageSecurityMode::SignAndEncrypt,
_ => {
error!("Mode value is invalid = {}", value);
MessageSecurityMode::Invalid
}
})
}
}
impl fmt::Display for MessageSecurityMode {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let name = match *self {
MessageSecurityMode::None => MESSAGE_SECURITY_MODE_NONE,
MessageSecurityMode::Sign => MESSAGE_SECURITY_MODE_SIGN,
MessageSecurityMode::SignAndEncrypt => MESSAGE_SECURITY_MODE_SIGN_AND_ENCRYPT,
_ => "",
};
write!(f, "{}", name)
}
}
impl From<MessageSecurityMode> for String {
fn from(security_mode: MessageSecurityMode) -> Self {
String::from(
match security_mode {
MessageSecurityMode::None => MESSAGE_SECURITY_MODE_NONE,
MessageSecurityMode::Sign => MESSAGE_SECURITY_MODE_SIGN,
MessageSecurityMode::SignAndEncrypt => MESSAGE_SECURITY_MODE_SIGN_AND_ENCRYPT,
_ => "",
}
)
}
}
impl<'a> From<&'a str> for MessageSecurityMode {
fn from(str: &'a str) -> Self {
match str {
MESSAGE_SECURITY_MODE_NONE => MessageSecurityMode::None,
MESSAGE_SECURITY_MODE_SIGN => MessageSecurityMode::Sign,
MESSAGE_SECURITY_MODE_SIGN_AND_ENCRYPT => MessageSecurityMode::SignAndEncrypt,
_ => {
error!("Specified security mode {} is not recognized", str);
MessageSecurityMode::Invalid
}
}
}
}
pub type Duration = Double;
pub type UtcTime = DateTime;
#[derive(Debug, Clone, PartialEq, Copy)]
pub enum MonitoringMode {
Disabled = 0,
Sampling = 1,
Reporting = 2,
}
impl BinaryEncoder<MonitoringMode> for MonitoringMode {
fn byte_len(&self) -> usize {
4
}
fn encode<S: Write>(&self, stream: &mut S) -> EncodingResult<usize> {
write_i32(stream, *self as Int32)
}
fn decode<S: Read>(stream: &mut S) -> EncodingResult<Self> {
let value = read_i32(stream)?;
match value {
0 => Ok(MonitoringMode::Disabled),
1 => Ok(MonitoringMode::Sampling),
2 => Ok(MonitoringMode::Reporting),
_ => {
error!("Don't know what monitoring mode {} is", value);
Err(BadMonitoringModeInvalid)
}
}
}
}