1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//! Reference to binary blob inside tag that isn't defined by a structure.

use std::io::BufRead;

use byteorder::{ReadBytesExt, LE};

#[derive(Default, Debug)]
/// Structure that defines a reference to a blob of data inside tag data.
pub struct TagDataReference {
    /// The index of the tag struct containing the tag field.
    pub parent_struct_index: i32,
    /// Unknown: seems to vary.
    pub unknown: i32,
    /// The index of the tag struct containing the referenced data.
    /// Can be -1 for null references.
    pub target_index: i32,
    /// The index of the data block containing the tag field.
    pub field_block: u32,
    /// The offset of the tag field inside the data block.
    pub field_offset: u32,
}

impl TagDataReference {
    /// Allocate new TagDataReference and set it to default values.
    pub fn new() -> Self {
        Self::default()
    }
    /// Reads the tag data reference from the given readers implementing "BufRead".
    /// # Arguments
    ///
    /// * `reader` - A mutable reference to a reader that implements `BufRead` from which to read the data.
    ///
    /// # Returns
    ///
    /// Returns `Ok(())` if the header is successfully read, or an `Err` if an I/O error occurs
    /// or if the header data is invalid.
    pub fn read<R: BufRead>(&mut self, reader: &mut R) -> std::io::Result<()> {
        self.parent_struct_index = reader.read_i32::<LE>()?;
        self.unknown = reader.read_i32::<LE>()?;
        self.target_index = reader.read_i32::<LE>()?;
        self.field_block = reader.read_u32::<LE>()?;
        self.field_offset = reader.read_u32::<LE>()?;
        Ok(())
    }
}