rsiot/message/
example_message.rs1use super::{Deserialize, MsgDataBound, MsgKey, Serialize};
4
5#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, MsgKey)]
7#[allow(missing_docs)]
8pub enum Custom {
9 ValueInstantF64(f64),
11 ValueInstantBool(bool),
13 ValueInstantString(String),
15 DataUnit(()),
17 DataGroup(DataGroup),
19 Tuple((String, (bool, bool))),
21 ValueStruct {
23 a: f64,
24 },
25 EspBootButton(bool),
27 EspRelay(bool),
29 SaveToFilesystem(u64),
30}
31
32#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
34pub struct StructInDataGroup {
35 pub struct_field1: bool,
37 pub struct_field2: f64,
39}
40
41#[allow(missing_docs)]
43#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, MsgKey)]
44pub enum DataGroup {
45 DataGroupF64(f64),
47 DataGroupStruct(StructInDataGroup),
49 DataGroupVectorBool(Vec<bool>),
50 DataGroupVectorTuple(Vec<(bool, String)>),
51}
52
53impl MsgDataBound for Custom {}
54
55#[cfg(test)]
56mod tests {
57 use super::super::Message;
58 use super::*;
59
60 #[test]
61 fn test1() {
62 let _msg = Custom::ValueInstantF64(12.3456);
63 }
64
65 #[test]
71 fn test_key() {
72 let msg = Message::new_custom(Custom::DataUnit(()));
73 assert_eq!("Custom-DataUnit", msg.key);
74
75 let msg = Message::new_custom(Custom::ValueInstantF64(0.0));
76 assert_eq!("Custom-ValueInstantF64", msg.key);
77
78 let msg = Message::new_custom(Custom::DataGroup(DataGroup::DataGroupF64(0.0)));
79 assert_eq!("Custom-DataGroup-DataGroupF64", msg.key);
80
81 let msg = Message::new_custom(Custom::DataGroup(DataGroup::DataGroupStruct(
82 StructInDataGroup {
83 struct_field1: false,
84 struct_field2: 0.0,
85 },
86 )));
87 assert_eq!("Custom-DataGroup-DataGroupStruct", msg.key);
88 }
89}