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.



8
9
10
# File 'lib/kafka/protocol/message_set.rb', line 8

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

Instance Attribute Details

#messagesObject (readonly)

Returns the value of attribute messages.



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

def messages
  @messages
end

Class Method Details

.decode(decoder) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/kafka/protocol/message_set.rb', line 28

def self.decode(decoder)
  fetched_messages = []

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

      if message.compressed?
        fetched_messages.concat(message.decompress)
      else
        fetched_messages << message
      end
    rescue EOFError
      if fetched_messages.empty?
        # If the first message in the set is truncated, it's likely because the
        # message is larger than the maximum size that we have asked for.
        raise MessageTooLargeToRead
      else
        # We tried to decode a partial message at the end of the set; just skip it.
      end
    end
  end

  new(messages: fetched_messages)
end

Instance Method Details

#==(other) ⇒ Object



16
17
18
# File 'lib/kafka/protocol/message_set.rb', line 16

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

#encode(encoder) ⇒ Object



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

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



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

def size
  @messages.size
end