Class: RSMP::Protocol

Inherits:
Object
  • Object
show all
Defined in:
lib/rsmp/node/protocol.rb

Overview

Simple protocol wrapper for reading/writing RSMP framed messages.

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ Protocol

Returns a new instance of Protocol.



4
5
6
7
# File 'lib/rsmp/node/protocol.rb', line 4

def initialize(stream)
  @stream = stream
  @peeked = nil
end

Instance Method Details

#peek_lineObject



19
20
21
22
# File 'lib/rsmp/node/protocol.rb', line 19

def peek_line
  @peeked ||= read
  @peeked
end

#read_lineObject



9
10
11
12
13
14
15
16
17
# File 'lib/rsmp/node/protocol.rb', line 9

def read_line
  if @peeked
    line = @peeked
    @peeked = nil
    line
  else
    read
  end
end

#write_lines(data) ⇒ Object



24
25
26
27
# File 'lib/rsmp/node/protocol.rb', line 24

def write_lines(data)
  @stream.write(data + RSMP::Proxy::WRAPPING_DELIMITER)
  @stream.flush unless @stream.closed?
end