Esempio n. 1
0
    def decode_consumer_metadata_response(cls, data):
        """
        Decode bytes to a ConsumerMetadataResponse

        Arguments:
            data: bytes to decode
        """
        ((correlation_id, error, nodeId), cur) = relative_unpack('>ihi', data, 0)
        (host, cur) = read_short_string(data, cur)
        ((port,), cur) = relative_unpack('>i', data, cur)

        return ConsumerMetadataResponse(error, nodeId, host, port)
Esempio n. 2
0
    def test_decode_consumer_metadata_response(self):
        encoded = b"".join([
            struct.pack(">i", 42),                                 # Correlation ID
            struct.pack(">h", 0),                                  # No Error
            struct.pack(">i", 1),                                  # Broker ID
            struct.pack(">h23s", 23, b"brokers1.kafka.rdio.com"),  # Broker Host
            struct.pack(">i", 1000),                               # Broker Port
        ])

        results = KafkaProtocol.decode_consumer_metadata_response(encoded)
        self.assertEqual(results,
            ConsumerMetadataResponse(error = 0, nodeId = 1, host = b'brokers1.kafka.rdio.com', port = 1000)
        )
Esempio n. 3
0
 def decode_consumer_metadata_response(cls, response):
     """
     Decode GroupCoordinatorResponse. Note that ConsumerMetadataResponse is
     renamed to GroupCoordinatorResponse in 0.9+
     Arguments:
         response: response to decode
     """
     return ConsumerMetadataResponse(
         response.error_code,
         response.coordinator_id,
         response.host,
         response.port,
     )