Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from typing import NamedTuple
from typing import Union
from typing_extensions import Self
__all__ = [
"RESPONSE_TYPES",
"Header",
"LoginRequest",
"LoginResponse",
"CommandRequest",
"CommandResponse",
"ServerMessage",
"Request",
"Response",
]
class Header(NamedTuple):
crc32: int
type: int
def __bytes__(self) -> bytes: ...
@classmethod
def create(cls, typ: int, payload: bytes) -> Self: ...
@classmethod
def from_bytes(cls, payload: bytes) -> Self: ...
class LoginRequest(str):
def __bytes__(self) -> bytes: ...
@property
def payload(self) -> bytes: ...
@property
def header(self) -> Header: ...
class LoginResponse(NamedTuple):
header: Header
success: bool
@classmethod
def from_bytes(cls, header: Header, payload: bytes) -> Self: ...
class CommandRequest(NamedTuple):
seq: int
command: str
def __bytes__(self) -> bytes: ...
@property
def payload(self) -> bytes: ...
@property
def header(self) -> Header: ...
@classmethod
def from_string(cls, command: str) -> Self: ...
@classmethod
def from_command(cls, command: str, *args: str) -> Self: ...
class CommandResponse(NamedTuple):
header: Header
seq: int
payload: bytes
@classmethod
def from_bytes(cls, header: Header, payload: bytes) -> Self: ...
@property
def message(self) -> str: ...
class ServerMessage(NamedTuple):
header: Header
seq: int
payload: bytes
@classmethod
def from_bytes(cls, header: Header, payload: bytes) -> Self: ...
@property
def message(self) -> str: ...
Request = Union[LoginRequest, CommandRequest]
Response = Union[LoginResponse, CommandResponse, ServerMessage]
RESPONSE_TYPES = {
0x00: LoginResponse,
0x01: CommandResponse,
0x02: ServerMessage,
}