wolfrpg_map_parser/command/event_control_command/
label.rs

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
use crate::byte_utils::parse_string;
#[cfg(feature = "serde")]
use serde::Serialize;

#[cfg_attr(feature = "serde", derive(Serialize))]
pub struct Label {
    label: String
}

impl Label {
    pub fn parse(bytes: &[u8]) -> (usize, Self) {
        let mut offset: usize = 0;
        offset += 2; // padding + string_count which are always 0x0001

        let (bytes_read, label): (usize, String) = parse_string(&bytes[offset..]);
        offset += bytes_read;

        offset += 1; // Command end

        (offset, Self {
            label
        })
    }

    pub fn label(&self) -> &str {
        &self.label
    }
    
    pub fn label_mut(&mut self) -> &mut String {
        &mut self.label
    }
}