本文整理匯總了Python中afkak.kafkacodec.KafkaCodec.decode_fetch_response方法的典型用法代碼示例。如果您正苦於以下問題:Python KafkaCodec.decode_fetch_response方法的具體用法?Python KafkaCodec.decode_fetch_response怎麽用?Python KafkaCodec.decode_fetch_response使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類afkak.kafkacodec.KafkaCodec
的用法示例。
在下文中一共展示了KafkaCodec.decode_fetch_response方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_decode_fetch_response
# 需要導入模塊: from afkak.kafkacodec import KafkaCodec [as 別名]
# 或者: from afkak.kafkacodec.KafkaCodec import decode_fetch_response [as 別名]
def test_decode_fetch_response(self):
t1 = "topic1"
t2 = u"topic2"
msgs = [create_message(m) for m in [b"message1", b"hi", b"boo", b"foo", b"so fun!"]]
ms1 = KafkaCodec._encode_message_set([msgs[0], msgs[1]])
ms2 = KafkaCodec._encode_message_set([msgs[2]])
ms3 = KafkaCodec._encode_message_set([msgs[3], msgs[4]])
encoded = struct.pack('>iih%dsiihqi%dsihqi%dsh%dsiihqi%ds' %
(len(t1), len(ms1), len(ms2), len(t2), len(ms3)),
4, 2, len(t1), t1.encode(), 2, 0, 0, 10, len(ms1), ms1, 1,
1, 20, len(ms2), ms2, len(t2), t2.encode(), 1, 0, 0, 30,
len(ms3), ms3)
responses = list(KafkaCodec.decode_fetch_response(encoded))
def expand_messages(response):
return FetchResponse(response.topic, response.partition,
response.error, response.highwaterMark,
list(response.messages))
expanded_responses = [expand_messages(r) for r in responses]
expect = [FetchResponse(t1, 0, 0, 10, [OffsetAndMessage(0, msgs[0]),
OffsetAndMessage(0, msgs[1])]),
FetchResponse(t1, 1, 1, 20, [OffsetAndMessage(0, msgs[2])]),
FetchResponse(t2, 0, 0, 30, [OffsetAndMessage(0, msgs[3]),
OffsetAndMessage(0, msgs[4])])]
self.assertEqual(expanded_responses, expect)