changes...

This commit is contained in:
DJMrTV 2025-01-26 12:09:56 +01:00
commit 40ca10651f
18 changed files with 998 additions and 112 deletions

28
src/rmc/structures/any.rs Normal file
View file

@ -0,0 +1,28 @@
use std::io::{Read, Seek};
use crate::endianness::{IS_BIG_ENDIAN, ReadExtensions};
use super::{string, Result};
#[derive(Debug)]
pub struct Any{
pub name: String,
pub data: Vec<u8>
}
pub fn read(reader: &mut (impl Read + Seek)) -> Result<Any>{
let name = string::read(reader)?;
// also length ?
let len2: u32 = reader.read_struct(IS_BIG_ENDIAN)?;
let length: u32 = reader.read_struct(IS_BIG_ENDIAN)?;
let mut data = vec![0; length as usize];
reader.read_exact(&mut data)?;
Ok(
Any{
name,
data
}
)
}

19
src/rmc/structures/mod.rs Normal file
View file

@ -0,0 +1,19 @@
use std::io;
use std::str::Utf8Error;
use std::string::FromUtf8Error;
use thiserror::Error;
//ideas for the future: make a proc macro library which allows generation of struct reads
#[derive(Error, Debug)]
pub enum Error{
#[error("Io Error: {0}")]
Io(#[from] io::Error),
#[error("UTF8 conversion Error: {0}")]
Utf8(#[from] FromUtf8Error)
}
type Result<T> = std::result::Result<T, Error>;
pub mod string;
pub mod any;

View file

@ -0,0 +1,18 @@
use std::ffi::CString;
use std::io::{Read, Seek};
use log::error;
use crate::endianness::{IS_BIG_ENDIAN, ReadExtensions};
use super::Result;
pub fn read(reader: &mut (impl Read + Seek)) -> Result<String>{
let len: u16 = reader.read_struct(IS_BIG_ENDIAN)?;
let mut data = vec![0; len as usize - 1];
reader.read_exact(&mut data)?;
let null: u8 = reader.read_struct(IS_BIG_ENDIAN)?;
if null != 0{
error!("unable to find null terminator... continuing anyways");
}
Ok(String::from_utf8(data)?)
}