jcers/
util.rs

1/// Jce Types
2#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
3pub enum JceType {
4    /// 0
5    U8,
6    /// 0
7    Bool,
8    /// 1
9    I16,
10    /// 2
11    I32,
12    /// 3
13    I64,
14    /// 4
15    F32,
16    /// 5
17    F64,
18    /// 6
19    ShortString,
20    /// 7
21    LongString,
22    /// 8
23    Map,
24    /// 9
25    List,
26    /// 10
27    Struct,
28    /// 11
29    StructEnd,
30    /// 12
31    Empty,
32    /// 13
33    Bytes,
34    /// ..
35    Unknown,
36    /// for Default
37    UnInit,
38}
39
40impl From<u8> for JceType {
41    fn from(ty: u8) -> JceType {
42        match ty {
43            0 => JceType::U8,
44            1 => JceType::I16,
45            2 => JceType::I32,
46            3 => JceType::I64,
47            4 => JceType::F32,
48            5 => JceType::F64,
49            6 => JceType::ShortString,
50            7 => JceType::LongString,
51            8 => JceType::Map,
52            9 => JceType::List,
53            10 => JceType::Struct,
54            11 => JceType::StructEnd,
55            12 => JceType::Empty,
56            13 => JceType::Bytes,
57            _ => JceType::Unknown,
58        }
59    }
60}
61
62impl Default for JceType {
63    fn default() -> Self {
64        JceType::UnInit
65    }
66}
67
68impl std::fmt::Display for JceType {
69    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
70        match self {
71            JceType::U8 => write!(f, "U8"),
72            JceType::Bool => write!(f, "Bool"),
73            JceType::I16 => write!(f, "I16"),
74            JceType::I32 => write!(f, "I32"),
75            JceType::I64 => write!(f, "I64"),
76            JceType::F32 => write!(f, "F32"),
77            JceType::F64 => write!(f, "F64"),
78            JceType::ShortString => write!(f, "ShortString"),
79            JceType::LongString => write!(f, "LongString"),
80            JceType::Map => write!(f, "Map"),
81            JceType::List => write!(f, "List"),
82            JceType::Struct => write!(f, "Struct"),
83            JceType::StructEnd => write!(f, "StructEnd"),
84            JceType::Empty => write!(f, "Empty"),
85            JceType::Bytes => write!(f, "Bytes"),
86            JceType::Unknown => write!(f, "Unknown"),
87            JceType::UnInit => write!(f, "UnInit"),
88        }
89    }
90}
91
92/// Jce head code
93#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
94pub struct JceHead {
95    pub ty:  JceType,
96    pub tag: u8,
97}