Module: Cognizant::Client::Transport

Defined in:
lib/cognizant/client.rb

Overview

Keep this in this file so client can be loaded entirely standalone by user code.

Class Method Summary collapse

Class Method Details

.deserialize_message(line) ⇒ Object


26
27
28
29
# File 'lib/cognizant/client.rb', line 26

def self.deserialize_message(line)
  serialized = URI.unescape(line)
  YAML.load(serialized)
end

.receive_message(socket) ⇒ Object


15
16
17
18
# File 'lib/cognizant/client.rb', line 15

def self.receive_message(socket)
  line = socket.readline
  deserialize_message(line)
end

.send_message(socket, message) ⇒ Object


10
11
12
13
# File 'lib/cognizant/client.rb', line 10

def self.send_message(socket, message)
  line = serialize_message(message)
  socket.write(line)
end

.serialize_message(message) ⇒ Object


20
21
22
23
24
# File 'lib/cognizant/client.rb', line 20

def self.serialize_message(message)
  serialized = YAML.dump(message)
  escaped = URI.escape(serialized, "%\n")
  escaped + "\n"
end