rsiot/message/
example_message.rsuse super::{
example_service::Service, Deserialize, MsgDataBound, MsgRoute, Serialize, TimeToLiveValue,
};
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[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),
MotorM1(Motor),
MotorM2(Motor),
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)]
pub enum DataGroup {
DataGroupF64(f64),
DataGroupStruct(StructInDataGroup),
DataGroupVectorBool(Vec<bool>),
DataGroupVectorTuple(Vec<(bool, String)>),
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[allow(missing_docs)]
pub enum Motor {
Status1(bool),
Status2(bool),
Status3(bool),
Status4(bool),
}
impl MsgDataBound for Custom {
type TService = Service;
fn define_enabled_routes(&self) -> MsgRoute<Self::TService> {
MsgRoute::default()
}
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);
let msg = Message::new_custom(Custom::MotorM1(Motor::Status1(false)));
assert_eq!("Custom-MotorM1-Status1", msg.key);
let msg = Message::new_custom(Custom::MotorM2(Motor::Status1(false)));
assert_eq!("Custom-MotorM2-Status1", msg.key);
}
}