forked from AbleOS/ableos_userland
Port XML to no_std
This commit is contained in:
parent
88a3fcd508
commit
4a19acb430
28
Cargo.lock
generated
28
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -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",
|
||||
|
|
9
libraries/ari_interface/Cargo.toml
Normal file
9
libraries/ari_interface/Cargo.toml
Normal file
|
@ -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 = "*"
|
79
libraries/ari_interface/src/lib.rs
Normal file
79
libraries/ari_interface/src/lib.rs
Normal file
|
@ -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<ARIFileBlock>,
|
||||
}
|
||||
|
||||
impl ARIFile {
|
||||
pub fn new() -> Self {
|
||||
Self { inner_data: vec![] }
|
||||
}
|
||||
pub fn file_from_vec(vec: Vec<u8>) -> 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: 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);
|
||||
}
|
|
@ -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"] }
|
||||
|
|
|
@ -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<Attribute>,
|
||||
pub children: Vec<XMLElement>,
|
||||
}
|
||||
|
||||
impl XMLElement {
|
||||
pub fn to_bin(&self) -> Result<Vec<u8>, XMLError> {
|
||||
match bincode::serialize(&self) {
|
||||
Ok(bin) => return Ok(bin),
|
||||
Err(err) => return Err(XMLError::EncodingError(err)),
|
||||
}
|
||||
}
|
||||
pub fn from_bin(bin: Vec<u8>) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl XMLElement {
|
||||
pub fn new<T: Display + Debug>(name: T) -> Self {
|
||||
Self {
|
||||
|
@ -158,10 +182,10 @@ impl From<u64> 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<T: Debug + Display>(string: T) -> Result<Types, XMLError> {
|
||||
// let string = "-27".to_string(); // `parse()` works with `&str` and `String`!
|
||||
|
@ -222,30 +246,34 @@ pub fn string_to_num<T: Debug + Display>(string: T) -> Result<Types, XMLError> {
|
|||
}
|
||||
|
||||
// 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<char> = lhs.chars().collect();
|
||||
|
||||
if lhs.chars().next() == Some('-') {
|
||||
// lhs
|
||||
positive = false;
|
||||
let mut lhs_median: Vec<char> = 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::<String>();
|
||||
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<T: Debug + Display>(string: T) -> Result<Types, XMLError> {
|
|||
#[derive(Debug)]
|
||||
pub enum XMLError {
|
||||
TypeNotANumber,
|
||||
EncodingError(bincode::Error),
|
||||
DecodingError(bincode::Error),
|
||||
}
|
||||
|
|
8
programs/ari_client/Cargo.toml
Normal file
8
programs/ari_client/Cargo.toml
Normal file
|
@ -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]
|
3
programs/ari_client/src/main.rs
Normal file
3
programs/ari_client/src/main.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
8
programs/ari_server/Cargo.toml
Normal file
8
programs/ari_server/Cargo.toml
Normal file
|
@ -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]
|
3
programs/ari_server/src/main.rs
Normal file
3
programs/ari_server/src/main.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue