Pascal Serrarens fa2895dd81 Refactoring
2025-01-20 20:09:53 +01:00

70 lines
2.1 KiB
Python

# from . import IMessage
## A client message announces the presence of a participant
#
## When received by another participant, it can be followed by a NetworkIdMsg
## to announce that participant to this client such that it can join privately
class ClientMsg():
id = 0xA0
length = 2
network_id = None
## Create a Client message
#
# @param network_id The network id of the local participant. Use 0 if it is unknown
def __init__(self, network_id):
if isinstance(network_id, int):
self.network_id = network_id
elif isinstance(network_id, bytes):
self.network_id = network_id[1]
## Serialize the message into the given buffer
#
## @param buffer_ref A reference to the buffer to use. This should be a list with the buffer as its first and only element
## @returns the length of the message
def Serialize(self, buffer_ref):
if buffer_ref is None or self.network_id is None:
return 0
buffer: bytearray = buffer_ref[0]
buffer[0:ClientMsg.length] = [
ClientMsg.id,
self.network_id
]
return ClientMsg.length
# @staticmethod
# def Serialized(buffer_ref, network_id):
# if buffer_ref is None or network_id is None:
# return 0
# buffer: bytearray = buffer_ref[0]
# buffer[0:ClientMsg.length] = [
# ClientMsg.id,
# network_id
# ]
# return ClientMsg.length
## Send the network_id to the participant
# def SendTo(participant, network_id):
# if participant is None or network_id is None:
# return False
# participant.buffer[0:2] = [
# ClientMsg.id,
# network_id
# ]
# participant.SendBuffer(ClientMsg.length)
## Publish the network_id
# def Publish(participant, network_id):
# if participant is None or network_id is None:
# return False
# participant.buffer[0:2] = [
# ClientMsg.id,
# network_id
# ]
# participant.PublishBuffer(ClientMsg.length)