添加 protocol.py
This commit is contained in:
12
protocol.py
Normal file
12
protocol.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import struct
|
||||||
|
|
||||||
|
TYPE_DATA = 0
|
||||||
|
TYPE_ACK = 1
|
||||||
|
|
||||||
|
def make_packet(seq, ptype, payload=b""):
|
||||||
|
return struct.pack("BB", seq, ptype) + payload
|
||||||
|
|
||||||
|
def parse_packet(packet):
|
||||||
|
seq, ptype = struct.unpack("BB", packet[:2])
|
||||||
|
payload = packet[2:]
|
||||||
|
return seq, ptype, payload
|
||||||
Reference in New Issue
Block a user