bililive_core/packet/
types.rs1use std::convert::TryFrom;
2
3use crate::errors::ParseError;
4
5#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
7#[repr(u32)]
8pub enum Operation {
9 HeartBeat = 2,
10 HeartBeatResponse = 3,
11 Notification = 5,
12 RoomEnter = 7,
13 RoomEnterResponse = 8,
14 Unknown = u32::MAX,
15}
16
17impl From<u32> for Operation {
18 fn from(i: u32) -> Self {
19 match i {
20 2 => Self::HeartBeat,
21 3 => Self::HeartBeatResponse,
22 5 => Self::Notification,
23 7 => Self::RoomEnter,
24 8 => Self::RoomEnterResponse,
25 _ => Self::Unknown,
26 }
27 }
28}
29
30#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
34#[repr(u16)]
35pub enum Protocol {
36 Json = 0,
37 Int32BE = 1,
38 Zlib = 2,
39}
40
41impl TryFrom<u16> for Protocol {
42 type Error = ParseError;
43
44 fn try_from(value: u16) -> Result<Self, Self::Error> {
45 match value {
46 0 => Ok(Self::Json),
47 1 => Ok(Self::Int32BE),
48 2 => Ok(Self::Zlib),
49 _ => Err(ParseError::UnknownProtocol),
50 }
51 }
52}