Class: EventMachine::Kafka::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/em-kafka/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(offset = 0, &block) ⇒ Parser

Returns a new instance of Parser.



6
7
8
9
10
# File 'lib/em-kafka/parser.rb', line 6

def initialize(offset = 0, &block)
  self.offset = offset
  @block = block
  reset
end

Instance Attribute Details

#offsetObject

Returns the value of attribute offset.



4
5
6
# File 'lib/em-kafka/parser.rb', line 4

def offset
  @offset
end

Instance Method Details

#on_data(binary) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/em-kafka/parser.rb', line 12

def on_data(binary)
  if @complete
    parsed_size = binary[0, 4].unpack("N").shift

    if (parsed_size - 2) > 0
      @size = parsed_size
    else
      # empty response
      return
    end
  end

  @buffer << binary

  received_data = @buffer.size + binary.size
  if received_data >= @size
    parse(@buffer[6, @size]) # account for 4 byte size and 2 byte junk
  else
    @complete = false
  end
end

#on_offset_update(&callback) ⇒ Object



34
35
36
# File 'lib/em-kafka/parser.rb', line 34

def on_offset_update(&callback)
  @on_offset_update_callback = callback
end