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
struct.pack_into('!ii', output, offset, -1, len(self._reqs))
offset += 8
for topic_name, partitions in iteritems(self._reqs):
fmt = '!h%dsi' % len(topic_name)
struct.pack_into(fmt, output, offset, len(topic_name),
topic_name, len(partitions))
offset += struct.calcsize(fmt)
for pnum, (offsets_before, max_offsets) in iteritems(partitions):
struct.pack_into('!iqi', output, offset,
pnum, offsets_before, max_offsets)
offset += 16
return output
评论列表
文章目录