diff --git a/Cargo.lock b/Cargo.lock index b76e9ec..db77dbf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,6 +37,21 @@ version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" +[[package]] +name = "ari_client" +version = "0.1.0" + +[[package]] +name = "ari_interface" +version = "0.1.0" +dependencies = [ + "log", +] + +[[package]] +name = "ari_server" +version = "0.1.0" + [[package]] name = "audio_interface" version = "0.1.0" @@ -60,6 +75,15 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -478,6 +502,10 @@ dependencies = [ [[package]] name = "xml" version = "0.1.0" +dependencies = [ + "bincode", + "serde", +] [[package]] name = "xml_tests" diff --git a/Cargo.toml b/Cargo.toml index 7ef3f7d..7d433dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ members = [ "drivers/mice/ps2_mouse", "libraries/able_graphics_library", + "libraries/ari_interface", "libraries/audio_interface", "libraries/clparse", "libraries/cryptography", @@ -29,6 +30,8 @@ members = [ "libraries/trash_manifest", "libraries/versioning", + "programs/ari_client", + "programs/ari_server", "programs/delete", "programs/list", "programs/shell", diff --git a/libraries/ari_interface/Cargo.toml b/libraries/ari_interface/Cargo.toml new file mode 100644 index 0000000..e5b9da4 --- /dev/null +++ b/libraries/ari_interface/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "ari_interface" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +log = "*" diff --git a/libraries/ari_interface/src/lib.rs b/libraries/ari_interface/src/lib.rs new file mode 100644 index 0000000..a9bb032 --- /dev/null +++ b/libraries/ari_interface/src/lib.rs @@ -0,0 +1,79 @@ +use log::trace; + +// ARI is a set of programs to manage an ableOS remote install. +// In the case of this being enabled ableOS will require a dedicated Server with an ableOS install and a number of Client devices +// A Client will fetch programs and files from the Server and cache them locally for a configurable amount of time +// TODO: Expand this explination + +/// The size of blocks sent over the network by ARI +pub const ARIFILE_BLOCK_SIZE: usize = 4096/*bytes*/; + +#[derive(Debug, Hash, PartialEq)] +pub struct ARIFileBlock([u8; ARIFILE_BLOCK_SIZE]); + +#[derive(Debug, Hash, PartialEq)] +pub struct ARIFile { + inner_data: Vec, +} + +impl ARIFile { + pub fn new() -> Self { + Self { inner_data: vec![] } + } + pub fn file_from_vec(vec: Vec) -> Self { + let mut data = vec![]; + let mut data_chunk = vec![]; + for x in vec.into_iter() { + if data_chunk.len() == ARIFILE_BLOCK_SIZE { + let data_block: [u8; ARIFILE_BLOCK_SIZE] = data_chunk[0..ARIFILE_BLOCK_SIZE] + .try_into() + .expect("slice with incorrect length"); + data.push(ARIFileBlock(data_block)); + data_chunk = vec![]; + } + data_chunk.push(x); + } + if !data_chunk.is_empty() { + let missing_byte_count = ARIFILE_BLOCK_SIZE - data_chunk.len(); + let msg: String = format!("Length Not Aligned missing {} bytes", missing_byte_count); + trace!("{}", msg); + + for _ in data_chunk.len()..ARIFILE_BLOCK_SIZE { + data_chunk.push(0) + } + data.push(ARIFileBlock( + data_chunk[0..ARIFILE_BLOCK_SIZE] + .try_into() + .expect("slice with incorrect length"), + )) + } + + Self { inner_data: data } + } +} + +use std::collections::hash_map::DefaultHasher; +use std::hash::{Hash, Hasher}; + +pub fn calculate_hash(t: &T) -> u64 { + let mut s = DefaultHasher::new(); + t.hash(&mut s); + s.finish() +} + +#[test] +pub fn file_diffrence_hash() { + let file_1 = ARIFile::file_from_vec(vec![1]); + let hash_1 = calculate_hash(&file_1.inner_data[0]); + + let file_2 = ARIFile::file_from_vec(vec![1, 1, 1, 1, 1, 1, 1, 1]); + let hash_2 = calculate_hash(&file_2.inner_data[0]); + + assert_ne!(hash_1, hash_2); +} + +#[test] +pub fn hash_test() { + let file = ARIFile::file_from_vec(vec![1]); + assert_eq!(calculate_hash(&file.inner_data[0]), 174020520262829630); +} diff --git a/libraries/xml/Cargo.toml b/libraries/xml/Cargo.toml index 71a2006..b4a752d 100644 --- a/libraries/xml/Cargo.toml +++ b/libraries/xml/Cargo.toml @@ -6,3 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +bincode = "1.3.3" +serde = { version = "1.0", features = ["derive"] } diff --git a/libraries/xml/src/lib.rs b/libraries/xml/src/lib.rs index 4533e44..2c33d7a 100644 --- a/libraries/xml/src/lib.rs +++ b/libraries/xml/src/lib.rs @@ -1,6 +1,16 @@ +#![no_std] + use core::fmt::{Debug, Display}; -#[derive(PartialEq, Clone)] +#[macro_use] +extern crate alloc; + +use alloc::string::{String, ToString}; +use alloc::vec::Vec; + +use serde::{Deserialize, Serialize}; +#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] + pub struct Attribute { name: String, value: String, @@ -11,7 +21,8 @@ impl Attribute { format!("{:?}={:?}", self.name, self.value) } } -#[derive(Clone)] +#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)] + // TODO Add an autotype attribute that defaults to true pub struct XMLElement { pub name: String, @@ -19,6 +30,19 @@ pub struct XMLElement { pub attributes: Vec, pub children: Vec, } + +impl XMLElement { + pub fn to_bin(&self) -> Result, XMLError> { + match bincode::serialize(&self) { + Ok(bin) => return Ok(bin), + Err(err) => return Err(XMLError::EncodingError(err)), + } + } + pub fn from_bin(bin: Vec) -> Self { + todo!() + } +} + impl XMLElement { pub fn new(name: T) -> Self { Self { @@ -158,10 +182,10 @@ impl From for UInt { } } -#[test] -pub fn test_string_to_num() { - println!("{:?}", string_to_num("-256.0")); -} +// #[test] +// pub fn test_string_to_num() { +// string_to_num("-256.0") +// } pub fn string_to_num(string: T) -> Result { // let string = "-27".to_string(); // `parse()` works with `&str` and `String`! @@ -222,30 +246,34 @@ pub fn string_to_num(string: T) -> Result { } // TODO: Decimal handler - if false { + { let mut split_string = string.split("."); let positive; let mut lhs = split_string.next().unwrap(); - println!("{:?}", lhs.chars().next()); + // println!("{:?}", lhs.chars().next()); + let mut lhs_median: Vec = lhs.chars().collect(); if lhs.chars().next() == Some('-') { // lhs positive = false; - let mut lhs_median: Vec = lhs.chars().collect(); lhs_median.remove(0); - println!("A {:?}", lhs_median); + // println!("A {:?}", lhs_median); } else { positive = true; } - println!("{:?}", lhs); + // println!("{:?}", lhs); + let lhs_median_2 = lhs_median.iter().cloned().collect::(); let mut lhs_final: Types = Types::None; - let abc = string_to_num(lhs); + let abc = string_to_num(lhs_median_2); - println!("{:?}", lhs_final); - let rhs = split_string.next(); - println!("{:?}", rhs); + // println!("{:?}", lhs_final); + let rhs = split_string.next().unwrap(); + // println!("{:?}", rhs); + let xyz = string_to_num(rhs); + // println!("{:?}", abc); + // println!("{:?}", xyz); // return Types::Fixed(); } @@ -255,4 +283,6 @@ pub fn string_to_num(string: T) -> Result { #[derive(Debug)] pub enum XMLError { TypeNotANumber, + EncodingError(bincode::Error), + DecodingError(bincode::Error), } diff --git a/programs/ari_client/Cargo.toml b/programs/ari_client/Cargo.toml new file mode 100644 index 0000000..77c1bf0 --- /dev/null +++ b/programs/ari_client/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "ari_client" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/programs/ari_client/src/main.rs b/programs/ari_client/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/programs/ari_client/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/programs/ari_server/Cargo.toml b/programs/ari_server/Cargo.toml new file mode 100644 index 0000000..bc35aa1 --- /dev/null +++ b/programs/ari_server/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "ari_server" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/programs/ari_server/src/main.rs b/programs/ari_server/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/programs/ari_server/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/programs/xml_tests/src/main.rs b/programs/xml_tests/src/main.rs index ea39a23..7c9823c 100644 --- a/programs/xml_tests/src/main.rs +++ b/programs/xml_tests/src/main.rs @@ -2,6 +2,6 @@ use xml; fn main() { let root = xml::XMLElement::new("name"); - - println!("{}", root.to_string()) + println!("{:?}", root.to_bin().unwrap()); + println!("{}", root.to_string()); }