use deku::prelude::*;
#[derive(Debug, PartialEq, DekuRead)]
#[deku(endian = "big", magic = b"BOMStore")]
pub struct StoreHeader {
pub version: u32,
block_count: u32,
index_offset: u32,
index_len: u32,
var_offset: u32,
var_len: u32,
#[deku(seek_from_start = "*index_offset as u64")]
pub index_store: IndexStore,
#[deku(seek_from_start = "*var_offset as u64")]
pub var_store: VariableStore,
}
#[derive(Debug, PartialEq, DekuRead)]
#[deku(endian = "big", ctx = "endian: deku::ctx::Endian")]
pub struct IndexStore {
count: u32,
#[deku(count = "count")]
pub indexs: Vec<Index>,
}
#[derive(Debug, PartialEq, DekuRead)]
#[deku(endian = "big", ctx = "endian: deku::ctx::Endian")]
pub struct Index {
pub offset: u32,
pub len: u32,
}
#[derive(Debug, PartialEq, DekuRead)]
#[deku(endian = "big", ctx = "endian: deku::ctx::Endian")]
pub struct VariableStore {
count: u32,
#[deku(count = "count")]
pub vars: Vec<Variable>,
}
#[derive(Debug, PartialEq, DekuRead)]
#[deku(endian = "big", ctx = "endian: deku::ctx::Endian")]
pub struct Variable {
pub index: u32,
pub len: u8,
#[deku(count = "len")]
pub name: Vec<u8>,
}
impl StoreHeader {
pub fn index_with_name(&self, name: &[u8]) -> Option<&Index> {
self.var_with_name(name)
.and_then(|var| self.index_store.indexs.get(var.index as usize))
}
pub fn var_with_name(&self, name: &[u8]) -> Option<&Variable> {
self.var_store.vars.iter().find(|var| var.name == name)
}
}
#[derive(Debug, PartialEq, DekuRead)]
#[deku(endian = "big", magic = b"tree")]
pub struct TreeHeader {
pub version: u32,
pub index: u32,
pub block_size: u32,
pub path_count: u32,
unknown: u8,
}
#[derive(Debug, PartialEq, DekuRead)]
#[deku(endian = "big")]
pub struct TreePaths {
pub is_leaf: u16,
pub count: u16,
pub forward: u32,
pub backward: u32,
#[deku(count = "count")]
pub indices: Vec<TreePathIndex>,
}
#[derive(Debug, PartialEq, DekuRead)]
#[deku(endian = "big", ctx = "endian: deku::ctx::Endian")]
pub struct TreePathIndex {
pub val: u32,
pub key: u32,
}
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, deku::DekuRead)]
pub struct BOMStr {
#[deku(read_all, map = "crate::deku_read_str")]
pub content: String,
}
#[derive(Debug, PartialEq, PartialOrd, Eq, Ord, deku::DekuRead)]
pub struct BOMBytes {
#[deku(read_all)]
pub content: Vec<u8>,
}