ableos_userland/libraries/exi/src/lib.rs

88 lines
2.1 KiB
Rust

use types::NBitUnsignedInteger;
pub mod types;
pub const EXI_HEADER_START: &str = "$EXI";
pub struct ExiOptions {
// NOTE: Go back to the EXI spec and fix this
pub alignment: u8,
pub compression: bool,
pub strict: bool,
pub fragment: bool,
// https://www.w3.org/TR/exi/#key-preserveOption
pub preserve: bool,
// https://www.w3.org/TR/exi/#key-selfContained
pub self_contained: bool,
// https://www.w3.org/TR/exi/#key-schemaIdOption
pub schema_id: String,
// https://www.w3.org/TR/exi/#key-datatypeRepresentationOption
// NOTE: What possible usecase could you have for changing the representation of data types.
// Touching this will be UB. Cry about it.
pub datatype_representation_map: bool,
// https://www.w3.org/TR/exi/#key-blockSizeOption
pub block_size: NBitUnsignedInteger,
// https://www.w3.org/TR/exi/#key-valueMaxLengthOption
pub value_max_length: NBitUnsignedInteger,
// https://www.w3.org/TR/exi/#key-valuePartitionCapacityOption
pub value_partition_capacity: NBitUnsignedInteger,
// https://www.w3.org/TR/exi/#key-userMetaData
pub user_defined_meta_data: String,
}
pub enum ExiFormatVersion {
PreviewVersion1 = 1_0000,
// The ableOS standard
FinalVersion1 = 0_0000,
FinalVersion15 = 0_1110,
FinalVersion16 = 0_1111_0000,
FinalVersion17 = 0_1111_0001,
}
pub struct ExiHeader {
exi_format: ExiFormatVersion,
exi_options: ExiOptions,
}
pub struct ExiDocument {}
impl ExiDocument {
pub fn new_from_xml(xml_string: String) -> Self {
println!("{}", xml_string);
Self {}
}
}
#[cfg(unix)]
mod unix {
use std::{
fs::{self, File},
io::Read,
path::Path,
};
use crate::ExiDocument;
fn parse_exi_from_file(path: &Path) -> ExiDocument {
let file_contents = fs::read_to_string(path).unwrap();
ExiDocument::new_from_xml(file_contents)
// ExiDocument {}
}
#[test]
fn test_xml_to_exi() {
parse_exi_from_file(Path::new(
"/home/able/Projects/ableos_userland/libraries/exi/assets/sample.xml",
));
}
}