Class: Cod::LineSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/cod/line_serializer.rb

Overview

A serializer that implements a line by line wire protocol. Only strings can be sent. An instance of this class can be used when constructing any channel, turning it into a line oriented channel speaking a clear text protocol.

Instance Method Summary collapse

Instance Method Details

#de(io) ⇒ String

Deserializes a message from the wire.

Parameters:

  • io (IO)

    the wire

Returns:

  • (String)

Raises:

  • (EOFError)


23
24
25
26
27
# File 'lib/cod/line_serializer.rb', line 23

def de(io)
  msg = io.gets
  return msg.chomp if msg
  raise EOFError
end

#en(msg) ⇒ String

Turns a message into the wire format.

Parameters:

  • msg (#to_s)

    message to send

Returns:

  • (String)

    buffer to be written to the wire



14
15
16
# File 'lib/cod/line_serializer.rb', line 14

def en(msg)
  msg.to_s + "\n"
end