From bb2effcd706b1257ef3c5c75d4d57cd9d119e5f4 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Mon, 29 Apr 2024 20:06:34 -0400 Subject: [PATCH] Add ULD module --- src/lib.rs | 3 +++ src/uld.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/uld.rs diff --git a/src/lib.rs b/src/lib.rs index 1aa35aa..bb5c68d 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -126,3 +126,6 @@ pub mod dic; #[doc(hidden)] pub const PHYSIS_VERSION: &str = env!("CARGO_PKG_VERSION"); + +/// Reading ULD files +pub mod uld; diff --git a/src/uld.rs b/src/uld.rs new file mode 100644 index 0000000..cfe2b05 --- /dev/null +++ b/src/uld.rs @@ -0,0 +1,43 @@ +// SPDX-FileCopyrightText: 2024 Joshua Goins +// SPDX-License-Identifier: GPL-3.0-or-later + +use std::io::Cursor; + +use crate::ByteSpan; +use binrw::binrw; +use binrw::BinRead; + +#[binrw] +#[derive(Debug)] +#[brw(little)] +struct UldHeader { + #[br(count = 4)] + #[bw(pad_size_to = 4)] + #[bw(map = |x : &String | x.as_bytes())] + #[br(map = | x: Vec | String::from_utf8(x).unwrap().trim_matches(char::from(0)).to_string())] + pub identifier: String, + + #[br(count = 4)] + #[bw(pad_size_to = 4)] + #[bw(map = |x : &String | x.as_bytes())] + #[br(map = | x: Vec | String::from_utf8(x).unwrap().trim_matches(char::from(0)).to_string())] + pub version: String, + + component_offset: u32, + widget_offset: u32 +} + +#[derive(Debug)] +pub struct Uld { + +} + +impl Uld { + /// Reads an existing ULD file + pub fn from_existing(buffer: ByteSpan) -> Option { + let mut cursor = Cursor::new(buffer); + let header = UldHeader::read(&mut cursor).ok()?; + + Some(Uld{}) + } +}