Class: EM::Tycoon::Protocol::Parser

Inherits:
Object
  • Object
show all
Includes:
Deferrable
Defined in:
lib/em/tycoon/protocol/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timeout = 0) ⇒ Parser

Create a new Parser deferrable, using the specified initial data and optional timeout specified in seconds



12
13
14
15
16
# File 'lib/em/tycoon/protocol/parser.rb', line 12

def initialize(timeout=0)
  @bytes_parsed = 0
  timeout(timeout) if timeout > 0
  @message = nil
end

Instance Attribute Details

#bufferObject

Returns the value of attribute buffer.



9
10
11
# File 'lib/em/tycoon/protocol/parser.rb', line 9

def buffer
  @buffer
end

#bytes_parsedObject (readonly)

Returns the value of attribute bytes_parsed.



8
9
10
# File 'lib/em/tycoon/protocol/parser.rb', line 8

def bytes_parsed
  @bytes_parsed
end

#messageObject (readonly)

Returns the value of attribute message.



8
9
10
# File 'lib/em/tycoon/protocol/parser.rb', line 8

def message
  @message
end

#resultObject (readonly)

Returns the value of attribute result.



8
9
10
# File 'lib/em/tycoon/protocol/parser.rb', line 8

def result
  @result
end

Instance Method Details

#parse_chunk(data) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/em/tycoon/protocol/parser.rb', line 18

def parse_chunk(data)
  @message ||= Message.message_for(data)
  @bytes_parsed += @message.parse(data)
  @result = @message.data
  succeed(@message.data) if @message.parsed?
  return @bytes_parsed
end