added packet.py and the Packet class

This commit is contained in:
Nicholas Dyer 2022-12-21 13:06:04 -05:00
parent a5c47f72ef
commit 1102e075c0
No known key found for this signature in database
GPG Key ID: E4E6388793FA2105

View File

@ -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