1use super::blocks::NiString;
2use super::error::NifError;
3use super::parse_utils;
4use binrw::{
5 io::{Read, Seek},
6 BinRead, BinReaderExt,
7};
8
9#[derive(Debug, PartialEq, BinRead)]
10#[br(magic = b"Gamebryo File Format, Version ")]
11#[br(assert(version == 0x14000004, NifError::NotImplemented("Version not implemented")))]
12pub struct Header {
13 #[br(parse_with = parse_utils::parse_version)]
14 pub version_from_str: u32,
15 pub version: u32,
16 pub endian_type: EndianType,
17 pub user_version: u32,
18 pub num_blocks: u32,
19 pub num_block_types: u16,
20 #[br(count = num_block_types)]
21 pub block_types: Vec<NiString>,
22 #[br(count = num_blocks)]
23 pub block_type_index: Vec<u16>,
24 pub unknown: u32,
25}
26
27#[derive(Debug, PartialEq, BinRead)]
28pub enum EndianType {
29 #[br(magic = 1u8)]
30 LittleEndian,
31 #[br(magic = 0u8)]
32 BigEndian,
33}
34
35impl Header {
36 pub fn parse<R: Read + Seek>(reader: &mut R) -> anyhow::Result<Self> {
37 Ok(reader.read_le()?)
38 }
39}