Class: EventMachine::Kafka::Parser
- Inherits:
-
Object
- Object
- EventMachine::Kafka::Parser
- Defined in:
- lib/em-kafka/parser.rb
Instance Attribute Summary collapse
-
#offset ⇒ Object
Returns the value of attribute offset.
Instance Method Summary collapse
-
#initialize(offset = 0, &block) ⇒ Parser
constructor
A new instance of Parser.
- #on_data(binary) ⇒ Object
- #on_offset_update(&callback) ⇒ Object
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
#offset ⇒ Object
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 |