tars_stream/
tars_type.rs

1#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
2pub enum TarsTypeMark {
3    EnInt8 = 0,
4    EnInt16 = 1,
5    EnInt32 = 2,
6    EnInt64 = 3,
7    EnFloat = 4,
8    EnDouble = 5,
9    EnString1 = 6,
10    EnString4 = 7,
11    EnMaps = 8,
12    EnList = 9,
13    EnStructBegin = 10,
14    EnStructEnd = 11,
15    EnZero = 12,
16    EnSimplelist = 13,
17}
18
19impl TarsTypeMark {
20    pub fn value(self) -> u8 {
21        self as u8
22    }
23}
24
25impl From<u8> for TarsTypeMark {
26    fn from(v: u8) -> Self {
27        match v {
28            0 => TarsTypeMark::EnInt8,
29            1 => TarsTypeMark::EnInt16,
30            2 => TarsTypeMark::EnInt32,
31            3 => TarsTypeMark::EnInt64,
32            4 => TarsTypeMark::EnFloat,
33            5 => TarsTypeMark::EnDouble,
34            6 => TarsTypeMark::EnString1,
35            7 => TarsTypeMark::EnString4,
36            8 => TarsTypeMark::EnMaps,
37            9 => TarsTypeMark::EnList,
38            10 => TarsTypeMark::EnStructBegin,
39            11 => TarsTypeMark::EnStructEnd,
40            12 => TarsTypeMark::EnZero,
41            13 => TarsTypeMark::EnSimplelist,
42            _ => TarsTypeMark::EnZero, // unknown type, read nothing from buffer
43        }
44    }
45}
46
47#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
48pub enum ProtocolVersion {
49    Tars = 1,
50    TupSimple = 2,
51    TupComplex = 3,
52}
53
54impl ProtocolVersion {
55    pub fn value(self) -> i8 {
56        self as i8
57    }
58}
59
60impl From<i8> for ProtocolVersion {
61    fn from(v: i8) -> Self {
62        if v == 1 {
63            ProtocolVersion::Tars
64        } else if v == 2 {
65            ProtocolVersion::TupSimple
66        } else {
67            ProtocolVersion::TupComplex
68        }
69    }
70}