-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpacket.py
More file actions
33 lines (25 loc) · 783 Bytes
/
Copy pathpacket.py
File metadata and controls
33 lines (25 loc) · 783 Bytes
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
from struct import pack, unpack
from actions import Actions
def PackInt(number: int) -> [int]:
return list(pack("i", number))
def UnpackBytes(byteArr: bytes) -> int:
return unpack('i', byteArr)[0]
class Packet:
data: [int]
action: Actions
position: int
def __init__(self, action: Actions):
self.position = 0
self.action = action
self.data = bytearray()
self.add(int(action))
def __init__(self, data: bytes):
self.data = list(data)
self.action = self.get()
def add(self, number: int):
self.data.extend(PackInt(number))
self.position += 4
def get(self) -> int:
data = UnpackBytes(self.data[self.position:self.position+4])
self.position += 4
return data