Skip to content

Commit 57e109c

Browse files
committed
Implement DescribeConfigs requests and responses
1 parent 7b4b06b commit 57e109c

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

lib/kafka/protocol.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,5 +168,7 @@ def self.api_name(api_key)
168168
require "kafka/protocol/create_topics_response"
169169
require "kafka/protocol/delete_topics_request"
170170
require "kafka/protocol/delete_topics_response"
171+
require "kafka/protocol/describe_configs_request"
172+
require "kafka/protocol/describe_configs_response"
171173
require "kafka/protocol/create_partitions_request"
172174
require "kafka/protocol/create_partitions_response"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module Kafka
2+
module Protocol
3+
4+
class DescribeConfigsRequest
5+
def initialize(resources:)
6+
@resources = resources
7+
end
8+
9+
def api_key
10+
DESCRIBE_CONFIGS_API
11+
end
12+
13+
def api_version
14+
0
15+
end
16+
17+
def response_class
18+
Protocol::DescribeConfigsResponse
19+
end
20+
21+
def encode(encoder)
22+
encoder.write_array(@resources) do |type, name, configs|
23+
encoder.write_int8(type)
24+
encoder.write_string(name)
25+
encoder.write_array(configs) do |config|
26+
encoder.write_string(config)
27+
end
28+
end
29+
end
30+
end
31+
32+
end
33+
end
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
module Kafka
2+
module Protocol
3+
class DescribeConfigsResponse
4+
class ResourceDescription
5+
attr_reader :name, :type, :error_code, :error_message, :configs
6+
7+
def initialize(name:, type:, error_code:, error_message:, configs:)
8+
@name = name
9+
@type = type
10+
@error_code = error_code
11+
@error_message = error_message
12+
@configs = configs
13+
end
14+
end
15+
16+
class ConfigEntry
17+
attr_reader :name, :value, :read_only, :is_default, :is_sensitive
18+
19+
def initialize(name:, value:, read_only:, is_default:, is_sensitive:)
20+
@name = name
21+
@value = value
22+
@read_only = read_only
23+
@is_default = is_default
24+
@is_sensitive = is_sensitive
25+
end
26+
end
27+
28+
attr_reader :resources
29+
30+
def initialize(throttle_time_ms:, resources:)
31+
@throttle_time_ms = throttle_time_ms
32+
@resources = resources
33+
end
34+
35+
def self.decode(decoder)
36+
throttle_time_ms = decoder.int32
37+
resources = decoder.array do
38+
error_code = decoder.int16
39+
error_message = decoder.string
40+
41+
resource_type = decoder.int8
42+
if Kafka::Protocol::RESOURCE_TYPES[resource_type].nil?
43+
raise Kafka::ProtocolError, "Resource type not supported: #{resource_type}"
44+
end
45+
resource_name = decoder.string
46+
47+
configs = decoder.array do
48+
ConfigEntry.new(
49+
name: decoder.string,
50+
value: decoder.string,
51+
read_only: decoder.boolean,
52+
is_default: decoder.boolean,
53+
is_sensitive: decoder.boolean,
54+
)
55+
end
56+
57+
ResourceDescription.new(
58+
type: RESOURCE_TYPES[resource_type],
59+
name: resource_name,
60+
error_code: error_code,
61+
error_message: error_message,
62+
configs: configs
63+
)
64+
end
65+
66+
new(throttle_time_ms: throttle_time_ms, resources: resources)
67+
end
68+
end
69+
70+
end
71+
end

0 commit comments

Comments
 (0)