pub struct List { pub length: usize, pub values: Vec, } // https://www.w3.org/TR/exi/#encodingUnsignedInteger pub struct NBitUnsignedInteger { pub length: Option, pub bits: Vec, } impl NBitUnsignedInteger { pub fn new(length: Integer) -> Self { let c = if length.bits == vec![0] { None } else { Some(length) }; Self { length: c, bits: Vec::new(), } } } pub struct BinaryBlob { pub length: Integer, pub bytes: Vec, } pub struct Decimal { pub lhs: UnsignedInteger, pub rhs: UnsignedInteger, } pub enum EXITypes { Binary(BinaryBlob), Boolean(bool), Decimal(Decimal), Float(f64), Integer(Integer), UnsignedInteger(UnsignedInteger), QName(String), DateTime(DateTime), NBitUnsignedInteger(NBitUnsignedInteger), String(String), List(List), } pub struct DateTime { pub year: Integer, pub month_day: NBitUnsignedInteger, pub time: NBitUnsignedInteger, pub fractional_secs: NBitUnsignedInteger, pub timezone: NBitUnsignedInteger, pub presence: bool, } impl DateTime { pub fn new() -> Self { Self { year: Integer::new(), month_day: NBitUnsignedInteger::new(9.into()), time: NBitUnsignedInteger::new(17.into()), fractional_secs: NBitUnsignedInteger::new(9.into()), timezone: NBitUnsignedInteger::new(11.into()), presence: false, } } } pub struct Integer { pub negative: bool, pub bits: Vec, } impl Integer { pub fn new() -> Self { Self { negative: false, bits: vec![0], } } } impl From for Integer { fn from(value: i8) -> Self { Self { negative: value.is_negative(), bits: value.abs().to_le_bytes().to_vec(), } } } pub struct UnsignedInteger { pub bits: Vec, } impl UnsignedInteger { pub fn new() -> Self { Self { bits: vec![0] } } } impl From for UnsignedInteger { fn from(value: i8) -> Self { Self { bits: value.abs().to_le_bytes().to_vec(), } } }