wolfrpg_map_parser/command/db_management_command/
string.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
33
34
use crate::byte_utils::parse_string;
#[cfg(feature = "serde")]
use serde::Serialize;
use std::string::String as StdString;

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

impl String {
    pub fn parse(bytes: &[u8]) -> (usize, Self) {
        let mut offset: usize = 0;

        offset += 1; // padding

        offset += 1; // String count, should always be 4

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

        (offset, Self {
            value
        })
    }

    pub fn value(&self) -> &str {
        &self.value
    }

    pub fn value_mut(&mut self) -> &mut StdString {
        &mut self.value
    }
}