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
//! Пример реализации сообщения. Можно использовать для тестирования компонентов

use crate::{Deserialize, MsgDataBound, Serialize};

/// Пример реализации сообщения. Можно использовать для тестирования компонентов
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub enum Custom {
    ValueInstantF64(f64),
    ValueInstantBool(bool),
    ValueInstantString(String),
    DataUnit(()),
    DataGroup(DataGroup),
}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct StructInDataGroup {
    pub struct_field1: bool,
    pub struct_field2: f64,
}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub enum DataGroup {
    DataGroupF64(f64),
    DataGroupStruct(StructInDataGroup),
}

impl MsgDataBound for Custom {}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::Message;

    #[test]
    fn test1() {
        let _msg = Custom::ValueInstantF64(12.3456);
    }

    #[test]
    fn test_key() {
        let msg = Message::new_custom(Custom::DataUnit(()));
        assert_eq!("Custom-DataUnit", msg.key);

        let msg = Message::new_custom(Custom::ValueInstantF64(0.0));
        assert_eq!("Custom-ValueInstantF64", msg.key);

        let msg = Message::new_custom(Custom::DataGroup(DataGroup::DataGroupF64(0.0)));
        assert_eq!("Custom-DataGroup-DataGroupF64", msg.key);

        let msg = Message::new_custom(Custom::DataGroup(DataGroup::DataGroupStruct(
            StructInDataGroup {
                struct_field1: false,
                struct_field2: 0.0,
            },
        )));

        assert_eq!("Custom-DataGroup-DataGroupStruct", msg.key);
    }
}