infinite_rs/tag/
reference.rs

1//! Reference to external tag that will get loaded on access.
2
3use byteorder::{LE, ReadBytesExt};
4use std::io::BufRead;
5
6use crate::Result;
7use crate::common::extensions::Enumerable;
8
9#[derive(Default, Debug)]
10/// Structure that defines a reference to a tag.
11pub struct TagReference {
12    /// The index of the data block containing the tag field.
13    pub field_block: i32,
14    /// The offset of the tag data block containing the referenced data.
15    /// Can be -1 for null references.
16    pub field_offset: u32,
17    /// The offset of the tag file name inside the tag string table.
18    pub(crate) name_offset: u32,
19    /// The index of the tag dependency in the tag dependency list.
20    /// Can be -1 for null tag references.
21    pub dependency_index: i32,
22    /// Tag name of the reference, located at the position of the [`Self::name_offset`] in the tag string table.
23    /// This only contains values before Season 3.
24    pub name: Option<String>,
25}
26
27impl Enumerable for TagReference {
28    fn read<R: BufRead>(&mut self, reader: &mut R) -> Result<()> {
29        self.field_block = reader.read_i32::<LE>()?;
30        self.field_offset = reader.read_u32::<LE>()?;
31        self.name_offset = reader.read_u32::<LE>()?;
32        self.dependency_index = reader.read_i32::<LE>()?;
33        Ok(())
34    }
35}