rsiot_messages_core/
example_message.rs1use crate::{Deserialize, MsgDataBound, Serialize};
4
5#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
7pub enum Custom {
8 ValueInstantF64(f64),
9 ValueInstantBool(bool),
10 ValueInstantString(String),
11 DataUnit(()),
12 DataGroup(DataGroup),
13}
14
15#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
16pub struct StructInDataGroup {
17 pub struct_field1: bool,
18 pub struct_field2: f64,
19}
20
21#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
22pub enum DataGroup {
23 DataGroupF64(f64),
24 DataGroupStruct(StructInDataGroup),
25}
26
27impl MsgDataBound for Custom {}
28
29#[cfg(test)]
30mod tests {
31 use super::*;
32 use crate::Message;
33
34 #[test]
35 fn test1() {
36 let _msg = Custom::ValueInstantF64(12.3456);
37 }
38
39 #[test]
40 fn test_key() {
41 let msg = Message::new_custom(Custom::DataUnit(()));
42 assert_eq!("Custom-DataUnit", msg.key);
43
44 let msg = Message::new_custom(Custom::ValueInstantF64(0.0));
45 assert_eq!("Custom-ValueInstantF64", msg.key);
46
47 let msg = Message::new_custom(Custom::DataGroup(DataGroup::DataGroupF64(0.0)));
48 assert_eq!("Custom-DataGroup-DataGroupF64", msg.key);
49
50 let msg = Message::new_custom(Custom::DataGroup(DataGroup::DataGroupStruct(
51 StructInDataGroup {
52 struct_field1: false,
53 struct_field2: 0.0,
54 },
55 )));
56
57 assert_eq!("Custom-DataGroup-DataGroupStruct", msg.key);
58 }
59}