當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。