Class: Kafka::Protocol::MemberAssignment
- Inherits:
-
Object
- Object
- Kafka::Protocol::MemberAssignment
- Defined in:
- lib/kafka/protocol/member_assignment.rb
Instance Attribute Summary collapse
-
#topics ⇒ Object
readonly
Returns the value of attribute topics.
Class Method Summary collapse
Instance Method Summary collapse
- #assign(topic, partitions) ⇒ Object
- #encode(encoder) ⇒ Object
-
#initialize(version: 0, topics: {}, user_data: nil) ⇒ MemberAssignment
constructor
A new instance of MemberAssignment.
Constructor Details
#initialize(version: 0, topics: {}, user_data: nil) ⇒ MemberAssignment
Returns a new instance of MemberAssignment.
8 9 10 11 12 |
# File 'lib/kafka/protocol/member_assignment.rb', line 8 def initialize(version: 0, topics: {}, user_data: nil) @version = version @topics = topics @user_data = user_data end |
Instance Attribute Details
#topics ⇒ Object (readonly)
Returns the value of attribute topics.
6 7 8 |
# File 'lib/kafka/protocol/member_assignment.rb', line 6 def topics @topics end |
Class Method Details
.decode(decoder) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/kafka/protocol/member_assignment.rb', line 33 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
14 15 16 17 |
# File 'lib/kafka/protocol/member_assignment.rb', line 14 def assign(topic, partitions) @topics[topic] ||= [] @topics[topic].concat(partitions) end |
#encode(encoder) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kafka/protocol/member_assignment.rb', line 19 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 |