Class: Kafka::Protocol::MemberAssignment

Inherits:
Object
  • Object
show all
Defined in:
lib/kafka/protocol/member_assignment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version: 0, topics: {}, user_data: nil) ⇒ MemberAssignment

Returns a new instance of MemberAssignment.


6
7
8
9
10
# File 'lib/kafka/protocol/member_assignment.rb', line 6

def initialize(version: 0, topics: {}, user_data: nil)
  @version = version
  @topics = topics
  @user_data = user_data
end

Instance Attribute Details

#topicsObject (readonly)

Returns the value of attribute topics


4
5
6
# File 'lib/kafka/protocol/member_assignment.rb', line 4

def topics
  @topics
end

Class Method Details

.decode(decoder) ⇒ Object


31
32
33
34
35
36
37
# File 'lib/kafka/protocol/member_assignment.rb', line 31

def self.decode(decoder)
  new(
    version: decoder.int16,
    topics: Hash[decoder.array { [decoder.string, decoder.array { decoder.int32 }] }],
    user_data: decoder.bytes,
  )
end

Instance Method Details

#assign(topic, partitions) ⇒ Object


12
13
14
15
# File 'lib/kafka/protocol/member_assignment.rb', line 12

def assign(topic, partitions)
  @topics[topic] ||= []
  @topics[topic].concat(partitions)
end

#encode(encoder) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/kafka/protocol/member_assignment.rb', line 17

def encode(encoder)
  encoder.write_int16(@version)

  encoder.write_array(@topics) do |topic, partitions|
    encoder.write_string(topic)

    encoder.write_array(partitions) do |partition|
      encoder.write_int32(partition)
    end
  end

  encoder.write_bytes(@user_data)
end