ireko/src/array_property.rs

40 lines
1.1 KiB
Rust
Raw Normal View History

2025-02-19 19:34:13 -05:00
use crate::set_property::SetEntry;
use binrw::{binrw, BinRead, BinResult};
use crate::map_property::{KeyType, MapEntry};
#[binrw::parser(reader, endian)]
fn custom_parser(size_in_bytes: u32, key_name: &str) -> BinResult<Vec<SetEntry>> {
let mut result = Vec::<SetEntry>::new();
let mut current = reader.stream_position().unwrap();
let end = current + size_in_bytes as u64 - 4;
while current < end {
result.push(SetEntry::read_options(reader, endian, (key_name,)).unwrap());
current = reader.stream_position().unwrap();
}
Ok(result)
}
2025-02-19 19:34:13 -05:00
#[binrw]
#[derive(Debug)]
pub struct ArrayProperty {
// Plus this int
pub size_in_bytes: u32,
2025-02-19 19:34:13 -05:00
#[br(temp)]
#[bw(ignore)]
#[br(pad_before = 4)]
pub key_name_length: u32,
#[br(count = key_name_length)]
#[bw(map = |x : &String | x.as_bytes())]
#[br(map = | x: Vec<u8> | String::from_utf8(x).unwrap().trim_matches(char::from(0)).to_string())]
pub key_name: String,
#[br(pad_before = 1)]
pub unk: u32,
2025-02-19 19:34:13 -05:00
#[br(parse_with = custom_parser, args(size_in_bytes, &key_name))]
2025-02-19 19:34:13 -05:00
pub entries: Vec<SetEntry>,
}