Class: MaxCube::Messages::UDP::Serializer

Inherits:
Object
  • Object
show all
Includes:
Serializer, Handler
Defined in:
lib/maxcube/messages/udp/serializer.rb

Overview

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

Constant Summary collapse

MSG_TYPES =

Known message types in the direction client -> Cube.

%w[I N h c R].freeze
MSG_PREFIX =

MSG_PREFIX with a suffix.

(UDP::MSG_PREFIX + "*\x00").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_udp_hash, #check_udp_msg, #check_udp_msg_prefix, #valid_udp_hash, #valid_udp_msg, #valid_udp_msg_prefix

Instance Method Details

#serialize_udp_hash(hash) ⇒ String

Serializes data from a single hash into UDP Cube message. Calls Handler#check_udp_hash at the begin and Handler#check_udp_msg at the end.

Parameters:

  • hash (Hash)

    particular message contents separated into hash.

Options Hash (hash):

  • :serial_number (String)

    if not specified, it is set to universal value. It is used for broadcast messages.

Returns:

  • (String)

    output message.



28
29
30
31
32
33
# File 'lib/maxcube/messages/udp/serializer.rb', line 28

def serialize_udp_hash(hash)
  check_udp_hash(hash)
  serial_number = hash[:serial_number] || '*' * 10
  msg = MSG_PREFIX + serial_number << @msg_type
  check_udp_msg(msg)
end