Class: PacketIO::LineBasedProtocol

Inherits:
Base
  • Object
show all
Defined in:
lib/packet_io/io_listener.rb

Instance Method Summary collapse

Methods inherited from Base

#<<, #initialize, #on_data

Constructor Details

This class inherits a constructor from PacketIO::Base

Instance Method Details

#receive(data) ⇒ Object

strip newlines from received data and pass on complete lines

Parameters:

  • data (String)


86
87
88
89
90
91
92
93
94
# File 'lib/packet_io/io_listener.rb', line 86

def receive(data)
  @memo ||= ""
  scanner = StringScanner.new(@memo + data)
  while s = scanner.scan(/.*?\n/)
    forward(s.strip)
  end
  @memo = scanner.rest
  nil
end

#write(data) ⇒ Object

add a newline to data and pass it on

Parameters:

  • data (String)


99
100
101
# File 'lib/packet_io/io_listener.rb', line 99

def write(data)
  super(data + "\n")
end