class MaxCube::Messages::UDP::Serializer

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

Constants

MSG_PREFIX

{UDP::MSG_PREFIX} with a suffix.

MSG_TYPES

Known message types in the direction client -> Cube.

Public Instance Methods

serialize_udp_hash(hash) click to toggle source

Serializes data from a single hash into UDP Cube message. Calls {#check_udp_hash} at the begin and {#check_udp_msg} at the end. @param hash [Hash] particular message contents separated into hash. @option hash [String] :serial_number if not specified,

it is set to universal value.
It is used for broadcast messages.

@return [String] output message.

# 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

Private Instance Methods

msg_msg_type(msg) click to toggle source

Tells how to get message type from a message. @param msg [String] input message. @return [String] message type.

# File lib/maxcube/messages/udp/serializer.rb, line 40
def msg_msg_type(msg)
  msg[18]
end