leejunyoung5819wayland-android-remote

공개

Ubuntu(Wayland/X11)에서 Android 기기 화면 미러링 및 원격 제어 (Rust)

85줄2.3 KB
1use super::ProtocolError;
2
3/// 제어 메시지 유형 (기획서 7.2).
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[repr(u8)]
6pub enum MsgType {
7 Ping = 0x01,
8 Pong = 0x02,
9 AuthHello = 0x03,
10 AuthChallenge = 0x04,
11 AuthResponse = 0x05,
12 AuthResult = 0x06,
13 ChannelAttach = 0x07,
14 KeyEvent = 0x10,
15 TextInput = 0x11,
16 SystemAction = 0x12,
17 ClipboardSync = 0x20,
18 TouchEvent = 0x30,
19 ScrollEvent = 0x31,
20 VideoConfigRequest = 0x40,
21 VideoConfig = 0x41,
22 VideoRequestKeyframe = 0x42,
23 FileStart = 0x50,
24 FileData = 0x51,
25 FileEnd = 0x52,
26 FileResult = 0x53,
27 FileCancel = 0x54,
28 Ack = 0xF0,
29 Error = 0xFF,
30}
31
32impl MsgType {
33 /// 인증 완료(AUTH_RESULT OK) 전에도 처리할 수 있는 메시지인지 여부 (기획서 7.3 6항).
34 pub fn allowed_before_auth(self) -> bool {
35 matches!(
36 self,
37 Self::Ping
38 | Self::Pong
39 | Self::AuthHello
40 | Self::AuthChallenge
41 | Self::AuthResponse
42 | Self::AuthResult
43 | Self::Error
44 )
45 }
46}
47
48impl TryFrom<u8> for MsgType {
49 type Error = ProtocolError;
50
51 fn try_from(value: u8) -> Result<Self, ProtocolError> {
52 Ok(match value {
53 0x01 => Self::Ping,
54 0x02 => Self::Pong,
55 0x03 => Self::AuthHello,
56 0x04 => Self::AuthChallenge,
57 0x05 => Self::AuthResponse,
58 0x06 => Self::AuthResult,
59 0x07 => Self::ChannelAttach,
60 0x10 => Self::KeyEvent,
61 0x11 => Self::TextInput,
62 0x12 => Self::SystemAction,
63 0x20 => Self::ClipboardSync,
64 0x30 => Self::TouchEvent,
65 0x31 => Self::ScrollEvent,
66 0x40 => Self::VideoConfigRequest,
67 0x41 => Self::VideoConfig,
68 0x42 => Self::VideoRequestKeyframe,
69 0x50 => Self::FileStart,
70 0x51 => Self::FileData,
71 0x52 => Self::FileEnd,
72 0x53 => Self::FileResult,
73 0x54 => Self::FileCancel,
74 0xF0 => Self::Ack,
75 0xFF => Self::Error,
76 other => return Err(ProtocolError::UnknownMsgType(other)),
77 })
78 }
79}
80
81impl From<MsgType> for u8 {
82 fn from(value: MsgType) -> Self {
83 value as u8
84 }
85}