From c8cfb928716c99895dc45190ecb2d1aae69c7dd4 Mon Sep 17 00:00:00 2001 From: xinghenLuyus <2593026969@qq.com> Date: Fri, 26 Dec 2025 13:43:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20protocol.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocol.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 protocol.py diff --git a/protocol.py b/protocol.py new file mode 100644 index 0000000..83c6e0f --- /dev/null +++ b/protocol.py @@ -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