添加 protocol.py

This commit is contained in:
2025-12-26 13:43:19 +08:00
parent 21f3cdd687
commit c8cfb92871

12
protocol.py Normal file
View 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