rsiot/message/
example_message.rsuse super::{Deserialize, MsgDataBound, MsgKey, Serialize, TimeToLiveValue};
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, MsgKey)]
#[allow(missing_docs)]
pub enum Custom {
ValueInstantF64(f64),
ValueInstantBool(bool),
ValueInstantString(String),
DataUnit(()),
DataGroup(DataGroup),
Tuple((String, (bool, bool))),
ValueStruct {
a: f64,
},
EspBootButton(bool),
EspRelay(bool),
SaveToFilesystem(u64),
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct StructInDataGroup {
pub struct_field1: bool,
pub struct_field2: f64,
}
#[allow(missing_docs)]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, MsgKey)]
pub enum DataGroup {
DataGroupF64(f64),
DataGroupStruct(StructInDataGroup),
DataGroupVectorBool(Vec<bool>),
DataGroupVectorTuple(Vec<(bool, String)>),
}
impl MsgDataBound for Custom {
fn define_time_to_live(&self) -> TimeToLiveValue {
TimeToLiveValue::Infinite
}
}
#[cfg(test)]
mod tests {
use super::super::Message;
use super::*;
#[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);
}
}