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

use crate::{eav, eav_helpers, msg_types, Deserialize, IMessage, Serialize};

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

impl IMessage for ExampleMessage {
    fn into_eav(self) -> Vec<eav::EavModel> {
        match self {
            ExampleMessage::ValueInstantF64(msg_content) => eav_helpers::ValueInstant {
                ts: msg_content.ts,
                entity: "ValueInstantF64".into(),
                attr: "".into(),
                value: msg_content.value.into(),
            }
            .into(),

            ExampleMessage::ValueInstantBool(msg_content) => eav_helpers::ValueInstant {
                ts: msg_content.ts,
                entity: "ValueInstantBool".into(),
                attr: "".into(),
                value: msg_content.value.into(),
            }
            .into(),

            ExampleMessage::ValueInstantString(msg_content) => eav_helpers::ValueInstant {
                ts: msg_content.ts,
                entity: "ValueInstantString".into(),
                attr: "".into(),
                value: msg_content.value.clone().into(),
            }
            .into(),
            ExampleMessage::Command(msg_content) => eav_helpers::Command {
                ts: msg_content.ts,
                entity: "Command".into(),
                attr: "".into(),
            }
            .into(),
        }
    }
}

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

    #[test]
    fn test1() {
        let msg = ExampleMessage::ValueInstantF64(msg_types::Value::new(12.3));
        let eav = msg.into_eav();
        println!("{:?}", eav);
    }
}