当前位置: 首页>>代码示例>>Python>>正文


Python KafkaCodec._encode_message_set方法代码示例

本文整理汇总了Python中afkak.kafkacodec.KafkaCodec._encode_message_set方法的典型用法代码示例。如果您正苦于以下问题:Python KafkaCodec._encode_message_set方法的具体用法?Python KafkaCodec._encode_message_set怎么用?Python KafkaCodec._encode_message_set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在afkak.kafkacodec.KafkaCodec的用法示例。


在下文中一共展示了KafkaCodec._encode_message_set方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_decode_fetch_response

# 需要导入模块: from afkak.kafkacodec import KafkaCodec [as 别名]
# 或者: from afkak.kafkacodec.KafkaCodec import _encode_message_set [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)
开发者ID:ciena,项目名称:afkak,代码行数:30,代码来源:test_kafkacodec.py

示例2: make_fetch_response

# 需要导入模块: from afkak.kafkacodec import KafkaCodec [as 别名]
# 或者: from afkak.kafkacodec.KafkaCodec import _encode_message_set [as 别名]
        def make_fetch_response(id):
            t1 = "topic1"
            t2 = "topic2"
            msgs = map(
                create_message, ["message1", "hi", "boo", "foo", "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]])

            packFmt = '>iih{}siihqi{}sihqi{}sh{}siihqi{}s'.format(
                len(t1), len(ms1), len(ms2), len(t2), len(ms3))
            return struct.pack(
                packFmt, id, 2, len(t1), t1, 2, 0, 0, 10, len(ms1), ms1, 1,
                1, 20, len(ms2), ms2, len(t2), t2, 1, 0, 0, 30, len(ms3), ms3)
开发者ID:joshainglis,项目名称:afkak,代码行数:16,代码来源:test_brokerclient.py

示例3: test_encode_message_set

# 需要导入模块: from afkak.kafkacodec import KafkaCodec [as 别名]
# 或者: from afkak.kafkacodec.KafkaCodec import _encode_message_set [as 别名]
    def test_encode_message_set(self):
        message_set = [
            create_message(b"v1", b"k1"),
            create_message(b"v2", b"k2"),
        ]

        encoded = KafkaCodec._encode_message_set(message_set)
        expect = b"".join([
            struct.pack(">q", 0),           # MsgSet Offset
            struct.pack(">i", 18),          # Msg Size
            struct.pack(">i", 1474775406),  # CRC
            struct.pack(">bb", 0, 0),       # Magic, flags
            struct.pack(">i", 2),           # Length of key
            b"k1",                          # Key
            struct.pack(">i", 2),           # Length of value
            b"v1",                          # Value

            struct.pack(">q", 0),          # MsgSet Offset
            struct.pack(">i", 18),         # Msg Size
            struct.pack(">i", -16383415),  # CRC
            struct.pack(">bb", 0, 0),      # Magic, flags
            struct.pack(">i", 2),          # Length of key
            b"k2",                         # Key
            struct.pack(">i", 2),          # Length of value
            b"v2",                         # Value
        ])

        self.assertEqual(encoded, expect)
开发者ID:ciena,项目名称:afkak,代码行数:30,代码来源:test_kafkacodec.py


注:本文中的afkak.kafkacodec.KafkaCodec._encode_message_set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。