def get_bytes(self):
output = bytearray(len(self))
offset = 0
fmt = '!hi'
struct.pack_into(fmt, output, offset, self.version,
len(self.partition_assignment))
offset += struct.calcsize(fmt)
for topic_name, partitions in self.partition_assignment:
fmt = '!h%dsi' % len(topic_name)
struct.pack_into(fmt, output, offset, len(topic_name), topic_name,
len(partitions))
offset += struct.calcsize(fmt)
for partition_id in partitions:
fmt = '!i'
struct.pack_into(fmt, output, offset, partition_id)
offset += struct.calcsize(fmt)
return output
评论列表
文章目录