wolfrpg_map_parser/command/db_management_command/
state.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
#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};
use crate::command::db_management_command::base::Base;
use crate::command::db_management_command::csv::CSV;
use crate::command::db_management_command::string;

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(PartialEq)]
pub enum State {
    Base(Base),
    String(string::String),
    CSV(CSV)
}

impl State {
    pub(crate) fn parse_base(bytes: &[u8]) -> (usize, Self) {
        let (bytes_read, command): (usize, Base) = Base::parse(bytes);

        (bytes_read, Self::Base(command))
    }

    pub(crate) fn parse_string(bytes: &[u8]) -> (usize, Self) {
        let (bytes_read, command): (usize, string::String) = string::String::parse(bytes);

        (bytes_read, Self::String(command))
    }

    pub(crate) fn parse_csv(bytes: &[u8]) -> (usize, Self) {
        let (bytes_read, command): (usize, CSV) = CSV::parse(bytes);

        (bytes_read, Self::CSV(command))
    }
}