77 lines
2.1 KiB
Rust
77 lines
2.1 KiB
Rust
//! Welcome to the Domo protocol rust implementation.
|
|
//!
|
|
//! This implementation is up-to-date with DomoProto v1.
|
|
//!
|
|
//! Most code that should/is actually used (usually) has documentation with it.
|
|
|
|
#![forbid(clippy::unwrap_used, clippy::expect_used)]
|
|
|
|
#[macro_use]
|
|
#[doc(hidden)]
|
|
pub mod prelude;
|
|
|
|
/// Domo protocol packet abstraction.
|
|
pub mod packet;
|
|
|
|
/// Identifier helper code.
|
|
pub mod identifier;
|
|
|
|
/// Data Types as stated in the Domo protocol spec.
|
|
pub mod data_types;
|
|
|
|
/// Commands are according to Domo protocol spec.
|
|
pub mod commands;
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use crate::packet;
|
|
use crate::data_types::{DataType, get_data_types};
|
|
use crate::identifier::Identifier;
|
|
use crate::packet::Packet;
|
|
use crate::packet::packet_data::PacketData;
|
|
|
|
#[test]
|
|
pub fn data_types() {
|
|
// test Vec<u8> -> Vec<DataType>
|
|
assert_eq!(
|
|
get_data_types(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!(
|
|
Into::<Vec<u8>>::into(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(),
|
|
}),
|
|
{
|
|
let mut v: Vec<u8> = 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
|
|
];
|
|
v.extend(crc32fast::hash(&v).to_be_bytes().to_vec());
|
|
v
|
|
}
|
|
);
|
|
}
|
|
}
|