def get_bytes(self):
"""Serialize the message
:returns: Serialized message
:rtype: :class:`bytearray`
"""
output = bytearray(len(self))
self._write_header(output)
offset = self.HEADER_LEN
fmt = '!h%dsih%dsh%dsi' % (len(self.group_id), len(self.member_id),
len(self.protocol_type))
struct.pack_into(fmt, output, offset, len(self.group_id), self.group_id,
self.session_timeout, len(self.member_id), self.member_id,
len(self.protocol_type), self.protocol_type,
len(self.group_protocols))
offset += struct.calcsize(fmt)
for protocol_name, protocol_metadata in self.group_protocols:
fmt = '!h%dsi%ds' % (len(protocol_name), len(protocol_metadata))
struct.pack_into(fmt, output, offset, len(protocol_name), protocol_name,
len(protocol_metadata), protocol_metadata)
offset += struct.calcsize(fmt)
return output
评论列表
文章目录