pub struct ChunkHeader {
pub id: ChunkId,
pub size: u32,
}Expand description
Standard ADT chunk header (8 bytes)
All chunks in ADT files follow this structure:
- 4 bytes: Magic identifier (reversed string, e.g., “MVER” stored as [0x52, 0x45, 0x56, 0x4D])
- 4 bytes: Data size (little-endian u32, excludes the 8-byte header)
§Binary Layout
Offset | Size | Field | Description
-------|------|-------|------------------------------------------
0x00 | 4 | id | Chunk magic identifier (reversed)
0x04 | 4 | size | Data size in bytes (excludes header)§Example
File bytes: [0x52, 0x45, 0x56, 0x4D] [0x04, 0x00, 0x00, 0x00] [0x12, 0x00, 0x00, 0x00]
└────── "REVM" ────────┘ └──── size: 4 ────────┘ └─── version data ──┘
(displays as "MVER")§Size Field Semantics
The size field represents the byte count of chunk data EXCLUDING the 8-byte header. This is a common source of off-by-8 errors when calculating file offsets.
If size = 100, then:
- Chunk data occupies bytes [8..108] relative to chunk start
- Total chunk size (header + data) = 108 bytes
- Next chunk starts at offset 108
§Usage with binrw
use binrw::BinRead;
use std::io::Cursor;
use wow_adt::chunk_header::ChunkHeader;
let data = [0x52, 0x45, 0x56, 0x4D, 0x04, 0x00, 0x00, 0x00];
let mut cursor = Cursor::new(&data);
let header = ChunkHeader::read(&mut cursor)?;
assert_eq!(header.size, 4);
assert_eq!(header.total_size(), 12); // 8-byte header + 4 bytes dataFields§
§id: ChunkIdChunk magic identifier (4 bytes, reversed)
Identifiers are stored in reverse byte order. For example, the “MVER” chunk is stored as [0x52, 0x45, 0x56, 0x4D] (“REVM” in ASCII).
size: u32Size of chunk data in bytes (excludes 8-byte header)
This field specifies the size of the chunk data following the header.
The total chunk size is size + 8 bytes.
Implementations§
Source§impl ChunkHeader
impl ChunkHeader
Sourcepub const fn total_size(&self) -> u64
pub const fn total_size(&self) -> u64
Total size including header (size + 8)
Returns the complete chunk size including the 8-byte header. Use this when calculating file offsets to the next chunk.
§Example
use wow_adt::chunk_header::ChunkHeader;
use wow_adt::chunk_id::ChunkId;
let header = ChunkHeader {
id: ChunkId::from_str("MVER").unwrap(),
size: 100,
};
assert_eq!(header.total_size(), 108); // 100 + 8Sourcepub fn is_chunk(&self, expected: ChunkId) -> bool
pub fn is_chunk(&self, expected: ChunkId) -> bool
Check if chunk ID matches expected value
Convenience method for validating chunk types during parsing.
§Example
use wow_adt::chunk_header::ChunkHeader;
use wow_adt::chunk_id::ChunkId;
let header = ChunkHeader {
id: ChunkId::from_str("MVER").unwrap(),
size: 4,
};
assert!(header.is_chunk(ChunkId::from_str("MVER").unwrap()));
assert!(!header.is_chunk(ChunkId::from_str("MHDR").unwrap()));Trait Implementations§
Source§impl BinRead for ChunkHeader
impl BinRead for ChunkHeader
Source§fn read_options<R: Read + Seek>(
__binrw_generated_var_reader: &mut R,
__binrw_generated_var_endian: Endian,
__binrw_generated_var_arguments: Self::Args<'_>,
) -> BinResult<Self>
fn read_options<R: Read + Seek>( __binrw_generated_var_reader: &mut R, __binrw_generated_var_endian: Endian, __binrw_generated_var_arguments: Self::Args<'_>, ) -> BinResult<Self>
Source§fn read<R>(reader: &mut R) -> Result<Self, Error>
fn read<R>(reader: &mut R) -> Result<Self, Error>
Self from the reader using default arguments. Read moreSource§fn read_be<R>(reader: &mut R) -> Result<Self, Error>
fn read_be<R>(reader: &mut R) -> Result<Self, Error>
Self from the reader using default arguments and assuming
big-endian byte order. Read moreSource§fn read_le<R>(reader: &mut R) -> Result<Self, Error>
fn read_le<R>(reader: &mut R) -> Result<Self, Error>
Self from the reader using default arguments and assuming
little-endian byte order. Read moreSource§fn read_ne<R>(reader: &mut R) -> Result<Self, Error>
fn read_ne<R>(reader: &mut R) -> Result<Self, Error>
T from the reader assuming native-endian byte order. Read moreSource§fn read_args<R>(reader: &mut R, args: Self::Args<'_>) -> Result<Self, Error>
fn read_args<R>(reader: &mut R, args: Self::Args<'_>) -> Result<Self, Error>
Self from the reader using the given arguments. Read moreSource§fn read_be_args<R>(reader: &mut R, args: Self::Args<'_>) -> Result<Self, Error>
fn read_be_args<R>(reader: &mut R, args: Self::Args<'_>) -> Result<Self, Error>
Self from the reader, assuming big-endian byte order, using the
given arguments. Read moreSource§impl BinWrite for ChunkHeader
impl BinWrite for ChunkHeader
Source§fn write_options<W: Write + Seek>(
&self,
__binrw_generated_var_writer: &mut W,
__binrw_generated_var_endian: Endian,
__binrw_generated_var_arguments: Self::Args<'_>,
) -> BinResult<()>
fn write_options<W: Write + Seek>( &self, __binrw_generated_var_writer: &mut W, __binrw_generated_var_endian: Endian, __binrw_generated_var_arguments: Self::Args<'_>, ) -> BinResult<()>
Source§fn write<W>(&self, writer: &mut W) -> Result<(), Error>
fn write<W>(&self, writer: &mut W) -> Result<(), Error>
Self to the writer using default arguments. Read moreSource§fn write_be<W>(&self, writer: &mut W) -> Result<(), Error>
fn write_be<W>(&self, writer: &mut W) -> Result<(), Error>
Self to the writer assuming big-endian byte order. Read moreSource§fn write_le<W>(&self, writer: &mut W) -> Result<(), Error>
fn write_le<W>(&self, writer: &mut W) -> Result<(), Error>
Self to the writer assuming little-endian byte order. Read moreSource§fn write_args<W>(
&self,
writer: &mut W,
args: Self::Args<'_>,
) -> Result<(), Error>
fn write_args<W>( &self, writer: &mut W, args: Self::Args<'_>, ) -> Result<(), Error>
Self to the writer using the given arguments. Read moreSource§impl Clone for ChunkHeader
impl Clone for ChunkHeader
Source§fn clone(&self) -> ChunkHeader
fn clone(&self) -> ChunkHeader
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more