domo/domo_proto/src/lib.rs
2023-10-15 18:06:32 +02:00

51 lines
1.4 KiB
Rust

pub mod commands;
pub mod packet;
pub mod prelude;
#[cfg(test)]
mod tests {
use crate::packet;
use crate::packet::data_types::DataType;
use crate::packet::identifier::Identifier;
use crate::packet::packet_data::PacketData;
#[test]
pub fn data_types() {
// test Vec<u8> -> Vec<DataType>
assert_eq!(
DataType::get_data(vec![0x00, 0x10, 0x00]),
vec![
DataType::Nothing,
DataType::Switch(false),
]);
// test DataType -> Vec<u8>
assert_eq!(
Into::<Vec<u8>>::into(DataType::Switch(true)),
vec![0x10, 0x01]
)
}
#[test]
pub fn packets() {
assert_eq!(packet::Packet {
src: Identifier::from(0xAABBCCDD),
dest: Identifier::from(0xAABBCCDD),
packet_id: Identifier::from(0x00000001),
reply_to: Identifier::from(0x00000000),
command: 0x00,
data: PacketData::default(),
}.build_base_packet(),
vec![
0x01, // version
0xAA, 0xBB, 0xCC, 0xDD, // dest
0xAA, 0xBB, 0xCC, 0xDD, // src
0x00, 0x00, 0x00, 0x01, // packet_id
0x00, 0x00, 0x00, 0x00, // reply_to
0x00, // command
0x00, 0x00, // data length
// no packet data
]
);
}
}