Class: MaxCube::Messages::TCP::Serializer

Inherits:
Object
  • Object
show all
Includes:
Serializer, Handler
Defined in:
lib/maxcube/messages/tcp/serializer.rb,
lib/maxcube/messages/tcp/type/a.rb,
lib/maxcube/messages/tcp/type/c.rb,
lib/maxcube/messages/tcp/type/f.rb,
lib/maxcube/messages/tcp/type/l.rb,
lib/maxcube/messages/tcp/type/m.rb,
lib/maxcube/messages/tcp/type/n.rb,
lib/maxcube/messages/tcp/type/q.rb,
lib/maxcube/messages/tcp/type/s.rb,
lib/maxcube/messages/tcp/type/t.rb,
lib/maxcube/messages/tcp/type/u.rb,
lib/maxcube/messages/tcp/type/z.rb

Overview

Extends Serializer and Handler of routines connected to TCP Cube messages serializing.

Defined Under Namespace

Modules: MessageA, MessageC, MessageF, MessageL, MessageM, MessageN, MessageQ, MessageS, MessageT, MessageU, MessageZ

Constant Summary collapse

MSG_TYPES =

Known message types in the direction client -> Cube.

%w[u i s m n x g q e d B G J P O V W a r t l c v f z].freeze

Constants included from Handler

Handler::PACK_FORMAT

Constants included from MaxCube::Messages

DAYS_OF_WEEK, DEVICE_MODE, DEVICE_TYPE

Instance Method Summary collapse

Methods included from Serializer

#serialize, #serialize_hash_body, #write

Methods included from Handler

#check_data_type, #check_hash, #check_hash_keys, #check_hash_msg_type, #check_hash_values, #check_msg, #check_msg_msg_type, #check_msg_type, #msg_type_hash_keys, #msg_type_hash_opt_keys, #valid_data_type, #valid_hash, #valid_hash_keys, #valid_hash_msg_type, #valid_hash_values, #valid_msg, #valid_msg_msg_type, #valid_msg_type

Methods included from Handler

#check_tcp_data, #check_tcp_hash, #check_tcp_msg, #check_tcp_msg_format, #check_tcp_msg_length, #valid_tcp_data, #valid_tcp_hash, #valid_tcp_msg, #valid_tcp_msg_format, #valid_tcp_msg_length

Instance Method Details

#serialize_tcp_hash(hash) ⇒ String

Serializes data from a single hash into TCP Cube message with \r\n at the end. Subsequently calls Handler#check_tcp_hash, Serializer#serialize_hash_body and Handler#check_tcp_msg.

Parameters:

  • hash (Hash)

    particular message contents separated into hash.

Returns:

  • (String)

    output message (with \r\n).



38
39
40
41
42
# 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) ⇒ String

Generates set of messages separated by \r\n. Calls Handler#check_tcp_data and maps #serialize_tcp_hash on each hash.

Parameters:

  • hashes (Array<Hash>)

    particular message contents.

Returns:

  • (String)

    raw data for a Cube.



26
27
28
29
# 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