class MaxCube::Messages::TCP::Serializer

Extends {Messages::Serializer} and {TCP::Handler} of routines connected to TCP Cube messages serializing.

Constants

MSG_TYPES

Known message types in the direction client -> Cube.

Public Instance Methods

serialize_tcp_hash(hash) click to toggle source

Serializes data from a single hash into TCP Cube message with +\r\n+ at the end. Subsequently calls {#check_tcp_hash}, {#serialize_hash_body} and {#check_tcp_msg}. @param hash [Hash] particular message contents separated into hash. @return [String] output message (with +\r\n+).

# File lib/maxcube/messages/tcp/serializer.rb, line 38
def serialize_tcp_hash(hash)
  check_tcp_hash(hash)
  msg = "#{@msg_type}:" << serialize_hash_body(hash, 'tcp')
  check_tcp_msg(msg) << "\r\n"
end
serialize_tcp_hashes(hashes) click to toggle source

Generates set of messages separated by +\r\n+. Calls {#check_tcp_data} and maps {#serialize_tcp_hash} on each hash. @param hashes [Array<Hash>] particular message contents. @return [String] raw data for a Cube.

# File lib/maxcube/messages/tcp/serializer.rb, line 26
def serialize_tcp_hashes(hashes)
  raw_data = hashes.map(&method(:serialize_tcp_hash)).join
  check_tcp_data(raw_data)
end