Class: MaxCube::Messages::UDP::Parser

Inherits:
Object
  • Object
show all
Includes:
Parser, Handler
Defined in:
lib/maxcube/messages/udp/parser.rb,
lib/maxcube/messages/udp/type/h.rb,
lib/maxcube/messages/udp/type/i.rb,
lib/maxcube/messages/udp/type/n.rb

Overview

Extends Parser and Handler of routines connected to UDP Cube messages parsing.

Defined Under Namespace

Modules: MessageH, MessageI, MessageN

Constant Summary collapse

KEYS =

Mandatory hash keys common for all UDP Cube messages.

%i[prefix serial_number id].freeze
MSG_TYPES =

Known message types in the direction Cube -> client.

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

MSG_PREFIX with a suffix.

(UDP::MSG_PREFIX + 'Ap').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 Parser

#parse_msg_body, #read

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

#parse_udp_msg(msg) ⇒ Hash

Parses single message. Subsequently calls Handler#check_udp_msg, #parse_udp_msg_head, Parser#parse_msg_body and Handler#check_udp_hash.

Parameters:

  • msg (String)

    input message.

Returns:

  • (Hash)

    particular message contents separated into hash.



33
34
35
36
37
38
# File 'lib/maxcube/messages/udp/parser.rb', line 33

def parse_udp_msg(msg)
  check_udp_msg(msg)
  hash = parse_udp_msg_head(msg)
  return hash unless parse_msg_body(@io.string, hash, 'udp')
  check_udp_hash(hash)
end