fix: everything up to spec

This commit is contained in:
Strix 2023-10-15 18:06:32 +02:00
parent 3068bf25be
commit a6366d61e0
No known key found for this signature in database
GPG key ID: 49B2E37B8915B774
2 changed files with 16 additions and 8 deletions

View file

@ -13,7 +13,7 @@ mod tests {
pub fn data_types() { pub fn data_types() {
// test Vec<u8> -> Vec<DataType> // test Vec<u8> -> Vec<DataType>
assert_eq!( assert_eq!(
DataType::get_data(vec![0x00, 0x01, 0x00]), DataType::get_data(vec![0x00, 0x10, 0x00]),
vec![ vec![
DataType::Nothing, DataType::Nothing,
DataType::Switch(false), DataType::Switch(false),
@ -22,7 +22,7 @@ mod tests {
// test DataType -> Vec<u8> // test DataType -> Vec<u8>
assert_eq!( assert_eq!(
Into::<Vec<u8>>::into(DataType::Switch(true)), Into::<Vec<u8>>::into(DataType::Switch(true)),
vec![0x01, 0x01] vec![0x10, 0x01]
) )
} }

View file

@ -4,21 +4,29 @@ use crate::prelude::as_u64_be;
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
pub enum DataType { pub enum DataType {
// Meta // Meta
/// Meta type: Nothing [0x00]
Nothing, Nothing,
/// Meta type: Array [0x01]
Array(Vec<DataType>), Array(Vec<DataType>),
// Basic types // Basic types
/// Basic Type: Switch [0x10]
Switch(bool), Switch(bool),
/// Basic Type: Slider [0x11]
Slider(u8), Slider(u8),
/// Basic Type: Text [0x12]
Text(String), Text(String),
// Cosmetic // Cosmetic
/// Cosmetic Type: RGB [0x20]
RGB(u8, u8, u8), RGB(u8, u8, u8),
// Time & Space // Time & Space
/// Time & Space Type: Seconds [0x90]
Seconds(u64), Seconds(u64),
// Domo Types // Domo Types
/// Domo type: Node Ref [0xF0]
NodeRef(Identifier), NodeRef(Identifier),
} }
@ -116,27 +124,27 @@ impl Into<Vec<u8>> for DataType {
match self { match self {
DataType::Nothing => vec![0x00], DataType::Nothing => vec![0x00],
DataType::Array(vec) => { DataType::Array(vec) => {
let mut res = vec![]; let mut res = vec![0x01];
for item in vec { for item in vec {
res.extend(Into::<Vec<u8>>::into(item).iter()); res.extend(Into::<Vec<u8>>::into(item).iter());
} }
res res
}, },
DataType::Switch(b) => vec![0x01, b as u8], DataType::Switch(b) => vec![0x10, b as u8],
DataType::Slider(v) => vec![0x02, v], DataType::Slider(v) => vec![0x11, v],
DataType::Text(s) => { DataType::Text(s) => {
let mut bytes = vec![0x03]; let mut bytes = vec![0x12];
bytes.extend(s.into_bytes()); bytes.extend(s.into_bytes());
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) => { DataType::Seconds(s) => {
let mut bytes = vec![0x90]; let mut bytes = vec![0x90];
bytes.extend_from_slice(s.to_be_bytes().as_ref()); bytes.extend_from_slice(s.to_be_bytes().as_ref());
bytes bytes
}, },
DataType::NodeRef(id) => { DataType::NodeRef(id) => {
let mut bytes = vec![0x90]; let mut bytes = vec![0xF0];
bytes.extend_from_slice(id.bytes.as_ref()); bytes.extend_from_slice(id.bytes.as_ref());
bytes bytes
}, },