From a6366d61e0a7698cc425235a835eb75a2931de25 Mon Sep 17 00:00:00 2001 From: Raine Date: Sun, 15 Oct 2023 18:06:32 +0200 Subject: [PATCH] fix: everything up to spec --- domo_proto/src/lib.rs | 4 ++-- domo_proto/src/packet/data_types.rs | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/domo_proto/src/lib.rs b/domo_proto/src/lib.rs index a76bf39..0d50428 100644 --- a/domo_proto/src/lib.rs +++ b/domo_proto/src/lib.rs @@ -13,7 +13,7 @@ mod tests { pub fn data_types() { // test Vec -> Vec assert_eq!( - DataType::get_data(vec![0x00, 0x01, 0x00]), + DataType::get_data(vec![0x00, 0x10, 0x00]), vec![ DataType::Nothing, DataType::Switch(false), @@ -22,7 +22,7 @@ mod tests { // test DataType -> Vec assert_eq!( Into::>::into(DataType::Switch(true)), - vec![0x01, 0x01] + vec![0x10, 0x01] ) } diff --git a/domo_proto/src/packet/data_types.rs b/domo_proto/src/packet/data_types.rs index 84266c2..7d521bd 100644 --- a/domo_proto/src/packet/data_types.rs +++ b/domo_proto/src/packet/data_types.rs @@ -4,21 +4,29 @@ use crate::prelude::as_u64_be; #[derive(Debug, Eq, PartialEq)] pub enum DataType { // Meta + /// Meta type: Nothing [0x00] Nothing, + /// Meta type: Array [0x01] Array(Vec), // Basic types + /// Basic Type: Switch [0x10] Switch(bool), + /// Basic Type: Slider [0x11] Slider(u8), + /// Basic Type: Text [0x12] Text(String), // Cosmetic + /// Cosmetic Type: RGB [0x20] RGB(u8, u8, u8), // Time & Space + /// Time & Space Type: Seconds [0x90] Seconds(u64), // Domo Types + /// Domo type: Node Ref [0xF0] NodeRef(Identifier), } @@ -116,27 +124,27 @@ impl Into> for DataType { match self { DataType::Nothing => vec![0x00], DataType::Array(vec) => { - let mut res = vec![]; + let mut res = vec![0x01]; for item in vec { res.extend(Into::>::into(item).iter()); } res }, - DataType::Switch(b) => vec![0x01, b as u8], - DataType::Slider(v) => vec![0x02, v], + DataType::Switch(b) => vec![0x10, b as u8], + DataType::Slider(v) => vec![0x11, v], DataType::Text(s) => { - let mut bytes = vec![0x03]; + let mut bytes = vec![0x12]; bytes.extend(s.into_bytes()); bytes }, - DataType::RGB(r, g, b) => vec![0x10, r, g, b], + DataType::RGB(r, g, b) => vec![0x20, r, g, b], DataType::Seconds(s) => { let mut bytes = vec![0x90]; bytes.extend_from_slice(s.to_be_bytes().as_ref()); bytes }, DataType::NodeRef(id) => { - let mut bytes = vec![0x90]; + let mut bytes = vec![0xF0]; bytes.extend_from_slice(id.bytes.as_ref()); bytes },