45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
from Messages import IMessage
|
|
|
|
## A network id message invites another participant to a site
|
|
#
|
|
## This can be sent in response to a ClientMsg
|
|
class NetworkIdMsg(IMessage):
|
|
id = 0xA1
|
|
length = 2
|
|
|
|
## Create a network id message
|
|
#
|
|
# @param network_id The network id assigned to the remote participant.
|
|
def __init__(self, network_id):
|
|
self.network_id = None
|
|
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 self.network_id is None:
|
|
return 0
|
|
|
|
buffer: bytearray = buffer_ref[0]
|
|
buffer[0:NetworkIdMsg.length] = [
|
|
NetworkIdMsg.id,
|
|
self.network_id
|
|
]
|
|
return NetworkIdMsg.length
|
|
|
|
# def SendTo(participant, network_id):
|
|
# if network_id is None:
|
|
# return 0
|
|
|
|
# participant.buffer[0:2] = [
|
|
# NetworkIdMsg.id,
|
|
# network_id
|
|
# ]
|
|
# return NetworkIdMsg.length
|
|
|