本文整理汇总了Python中afkak.kafkacodec.KafkaCodec._decode_message方法的典型用法代码示例。如果您正苦于以下问题:Python KafkaCodec._decode_message方法的具体用法?Python KafkaCodec._decode_message怎么用?Python KafkaCodec._decode_message使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类afkak.kafkacodec.KafkaCodec
的用法示例。
在下文中一共展示了KafkaCodec._decode_message方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_decode_message
# 需要导入模块: from afkak.kafkacodec import KafkaCodec [as 别名]
# 或者: from afkak.kafkacodec.KafkaCodec import _decode_message [as 别名]
def test_decode_message(self):
encoded = b"".join([
struct.pack(">i", -1427009701), # CRC
struct.pack(">bb", 0, 0), # Magic, flags
struct.pack(">i", 3), # Length of key
b"key", # key
struct.pack(">i", 4), # Length of value
b"test", # value
])
offset = 10
(returned_offset, decoded_message) = list(
KafkaCodec._decode_message(encoded, offset))[0]
self.assertEqual(returned_offset, offset)
self.assertEqual(decoded_message, create_message(b"test", b"key"))
示例2: test_decode_message_gzip
# 需要导入模块: from afkak.kafkacodec import KafkaCodec [as 别名]
# 或者: from afkak.kafkacodec.KafkaCodec import _decode_message [as 别名]
def test_decode_message_gzip(self):
gzip_encoded = (b'\xc0\x11\xb2\xf0\x00\x01\xff\xff\xff\xff\x00\x00\x000'
b'\x1f\x8b\x08\x00\xa1\xc1\xc5R\x02\xffc`\x80\x03\x01'
b'\x9f\xf9\xd1\x87\x18\x18\xfe\x03\x01\x90\xc7Tf\xc8'
b'\x80$wu\x1aW\x05\x92\x9c\x11\x00z\xc0h\x888\x00\x00'
b'\x00')
offset = 11
messages = list(KafkaCodec._decode_message(gzip_encoded, offset))
self.assertEqual(len(messages), 2)
msg1, msg2 = messages
returned_offset1, decoded_message1 = msg1
self.assertEqual(returned_offset1, 0)
self.assertEqual(decoded_message1, create_message(b"v1"))
returned_offset2, decoded_message2 = msg2
self.assertEqual(returned_offset2, 0)
self.assertEqual(decoded_message2, create_message(b"v2"))
示例3: test_decode_message_snappy
# 需要导入模块: from afkak.kafkacodec import KafkaCodec [as 别名]
# 或者: from afkak.kafkacodec.KafkaCodec import _decode_message [as 别名]
def test_decode_message_snappy(self):
if not has_snappy():
raise SkipTest("Snappy not available") # pragma: no cover
snappy_encoded = (b'\xec\x80\xa1\x95\x00\x02\xff\xff\xff\xff\x00\x00'
b'\x00,8\x00\x00\x19\[email protected]\x10L\x9f[\xc2\x00\x00\xff'
b'\xff\xff\xff\x00\x00\x00\x02v1\x19\x1bD\x00\x10\xd5'
b'\x96\nx\x00\x00\xff\xff\xff\xff\x00\x00\x00\x02v2')
offset = 11
messages = list(KafkaCodec._decode_message(snappy_encoded, offset))
self.assertEqual(len(messages), 2)
msg1, msg2 = messages
returned_offset1, decoded_message1 = msg1
self.assertEqual(returned_offset1, 0)
self.assertEqual(decoded_message1, create_message(b"v1"))
returned_offset2, decoded_message2 = msg2
self.assertEqual(returned_offset2, 0)
self.assertEqual(decoded_message2, create_message(b"v2"))
示例4: test_decode_message_checksum_error
# 需要导入模块: from afkak.kafkacodec import KafkaCodec [as 别名]
# 或者: from afkak.kafkacodec.KafkaCodec import _decode_message [as 别名]
def test_decode_message_checksum_error(self):
invalid_encoded_message = b"This is not a valid encoded message"
iter = KafkaCodec._decode_message(invalid_encoded_message, 0)
self.assertRaises(ChecksumError, list, iter)