Class: KafkaSyrup::Protocol::MetadataResponse

Inherits:
Response
  • Object
show all
Defined in:
lib/kafka_syrup/protocol/metadata_response.rb

Defined Under Namespace

Classes: Broker, Partition, Topic

Instance Attribute Summary collapse

Attributes inherited from Response

#correlation_id

Instance Method Summary collapse

Methods inherited from Base

#==, #config, #initialize

Methods included from Utils

#load_args, #log

Constructor Details

This class inherits a constructor from KafkaSyrup::Protocol::Base

Instance Attribute Details

#brokersObject

Returns the value of attribute brokers.



4
5
6
# File 'lib/kafka_syrup/protocol/metadata_response.rb', line 4

def brokers
  @brokers
end

#topicsObject

Returns the value of attribute topics.



4
5
6
# File 'lib/kafka_syrup/protocol/metadata_response.rb', line 4

def topics
  @topics
end

Instance Method Details

#add_broker(node, host, port) ⇒ Object



10
11
12
13
14
# File 'lib/kafka_syrup/protocol/metadata_response.rb', line 10

def add_broker(node, host, port)
  broker = Broker.new(node, host, port)
  brokers << broker
  broker
end

#add_topic(code, name) ⇒ Object



16
17
18
19
20
# File 'lib/kafka_syrup/protocol/metadata_response.rb', line 16

def add_topic(code, name)
  topic = Topic.new(code, name, [])
  topics << topic
  topic
end

#decode(io) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/kafka_syrup/protocol/metadata_response.rb', line 31

def decode(io)
  super
  self.brokers = E.read_array(io, &Broker.method(:decode))
  self.topics = E.read_array(io, &Topic.method(:decode))

  topics.map(&:code).each(&KafkaResponseErrors.method(:raise_from_code))
  topics.flat_map(&:partitions).map(&:code).each(&KafkaResponseErrors.method(:raise_from_code))
end

#defaultsObject



6
7
8
# File 'lib/kafka_syrup/protocol/metadata_response.rb', line 6

def defaults
  { brokers: [], topics: [] }
end

#encodeObject



22
23
24
25
26
27
28
29
# File 'lib/kafka_syrup/protocol/metadata_response.rb', line 22

def encode
  super do
    [
      E.write_array(brokers),
      E.write_array(topics)
    ].join
  end
end