httlib_protos/
typ.rs

1use core::convert::TryFrom;
2
3/// Provides available wire types supported by proto3.
4#[derive(Clone, Copy, Debug, PartialEq)]
5pub enum Typ {
6    /// Represents the wire type `0` which allows for encoding of data formats
7    /// `int32`, `int64`, `uint32`, `uint64`, `sint32`, `sint64` and `bool`.
8    Varint = 0,
9
10    /// Represents the wire type `1` which allows for encoding of data formats
11    /// `fixed64`, `sfixed64` and `double`.
12    Bit64 = 1,
13
14    /// Represents the wire type `2` which allows for encoding of data formats
15    /// `string`, `bytes`, `embedded messages` and `packed repeated fields`.
16    LengthDelimited = 2,
17
18    /// Represents the wire type `5` which allows for encoding of data formats
19    /// `fixed32`, `sfixed32` and `float`.
20    Bit32 = 5,
21
22    /// Represents un unknown wire type.
23    Unknown = -1,
24}
25
26impl TryFrom<u64> for Typ {
27    type Error = std::io::Error;
28
29    fn try_from(value: u64) -> Result<Self, Self::Error> {
30        match value {
31            0 => Ok(Typ::Varint),
32            1 => Ok(Typ::Bit64),
33            2 => Ok(Typ::LengthDelimited),
34            5 => Ok(Typ::Bit32),
35            _ => Ok(Typ::Unknown),
36        }
37    }
38}