Class: Kafka::Protocol::MessageSet

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(messages: []) ⇒ MessageSet

Returns a new instance of MessageSet.


6
7
8
# File 'lib/kafka/protocol/message_set.rb', line 6

def initialize(messages: [])
  @messages = messages
end

Instance Attribute Details

#messagesObject (readonly)

Returns the value of attribute messages


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

def messages
  @messages
end

Class Method Details

.decode(decoder) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/kafka/protocol/message_set.rb', line 26

def self.decode(decoder)
  fetched_messages = []

  until decoder.eof?
    begin
      message = Message.decode(decoder)

      if message.compressed?
        wrapped_message_set = message.decompress
        fetched_messages.concat(wrapped_message_set.messages)
      else
        fetched_messages << message
      end
    rescue EOFError      # We tried to decode a partial message; just skip it.

    end
  end

  new(messages: fetched_messages)
end

Instance Method Details

#==(other) ⇒ Object


14
15
16
# File 'lib/kafka/protocol/message_set.rb', line 14

def ==(other)
  messages == other.messages
end

#encode(encoder) ⇒ Object


18
19
20
21
22
23
24
# File 'lib/kafka/protocol/message_set.rb', line 18

def encode(encoder)
  # Messages in a message set are *not* encoded as an array. Rather,
  # they are written in sequence.
  @messages.each do |message|
    message.encode(encoder)
  end
end

#sizeObject


10
11
12
# File 'lib/kafka/protocol/message_set.rb', line 10

def size
  @messages.size
end