leejunyoung5819wayland-android-remote

공개

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

75줄2.0 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 Ack = 0xF0,
24 Error = 0xFF,
25}
26
27impl MsgType {
28 /// 인증 완료(AUTH_RESULT OK) 전에도 처리할 수 있는 메시지인지 여부 (기획서 7.3 6항).
29 pub fn allowed_before_auth(self) -> bool {
30 matches!(
31 self,
32 Self::Ping
33 | Self::Pong
34 | Self::AuthHello
35 | Self::AuthChallenge
36 | Self::AuthResponse
37 | Self::AuthResult
38 | Self::Error
39 )
40 }
41}
42
43impl TryFrom<u8> for MsgType {
44 type Error = ProtocolError;
45
46 fn try_from(value: u8) -> Result<Self, ProtocolError> {
47 Ok(match value {
48 0x01 => Self::Ping,
49 0x02 => Self::Pong,
50 0x03 => Self::AuthHello,
51 0x04 => Self::AuthChallenge,
52 0x05 => Self::AuthResponse,
53 0x06 => Self::AuthResult,
54 0x07 => Self::ChannelAttach,
55 0x10 => Self::KeyEvent,
56 0x11 => Self::TextInput,
57 0x12 => Self::SystemAction,
58 0x20 => Self::ClipboardSync,
59 0x30 => Self::TouchEvent,
60 0x31 => Self::ScrollEvent,
61 0x40 => Self::VideoConfigRequest,
62 0x41 => Self::VideoConfig,
63 0x42 => Self::VideoRequestKeyframe,
64 0xF0 => Self::Ack,
65 0xFF => Self::Error,
66 other => return Err(ProtocolError::UnknownMsgType(other)),
67 })
68 }
69}
70
71impl From<MsgType> for u8 {
72 fn from(value: MsgType) -> Self {
73 value as u8
74 }
75}