From 1102e075c0ee27ffd08b98cfd7a93eada23aebe8 Mon Sep 17 00:00:00 2001 From: ndyer Date: Wed, 21 Dec 2022 13:06:04 -0500 Subject: [PATCH] added packet.py and the Packet class --- pypong/networking/packet.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 pypong/networking/packet.py diff --git a/pypong/networking/packet.py b/pypong/networking/packet.py new file mode 100644 index 0000000..e586691 --- /dev/null +++ b/pypong/networking/packet.py @@ -0,0 +1,36 @@ +""" +Contains the Packet class to help with the transmission, reading, and verification of infermation over the network +""" + + +class Packet: + """ + Class that contains information to be sent over the network. Can self-verify and has methods (will have methods) to + easily encode and decode packet information + """ + VALID_HEADERS = [ + 'PYPONGREQ', + 'PYPONGRST' + ] + VALID_TYPES = [ + 'SVRINFO' + ] + + def __init__(self, header, msg_type, *message): + self.header = header + self.msg_type = msg_type + self.message = [] + for x in message: + self.message.append(x) + + def integrity_check(self): + """ + Verify that the information in the packet is correct and makes sense + + :return: True if packet verifies correctly, False if not + """ + if self.header not in Packet.VALID_HEADERS: + return False + if self.msg_type not in Packet.VALID_TYPES: + return False + return True