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('!iiii', output, offset,
-1, self.timeout, self.min_bytes, len(self._reqs))
offset += 16
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 partition_id, (fetch_offset, max_bytes) in iteritems(partitions):
struct.pack_into('!iqi', output, offset,
partition_id, fetch_offset, max_bytes)
offset += 16
return output
评论列表
文章目录