Module: MaxCube::Messages::UDP::Handler

Includes:
Handler
Included in:
Parser, Serializer
Defined in:
lib/maxcube/messages/udp/handler.rb

Overview

Extends Handler of routines connected to UDP Cube messages.

Constant Summary

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 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

Instance Method Details

#check_udp_hash(hash) ⇒ Hash

As #valid_udp_hash, but raises exception if hash is not valid. It only calls Handler#check_hash.

Parameters:

  • hash (Hash)

    input hash.

Returns:

  • (Hash)

    input hash.



61
62
63
64
# File 'lib/maxcube/messages/udp/handler.rb', line 61

def check_udp_hash(hash)
  check_hash(hash)
  hash
end

#check_udp_msg(msg) ⇒ String

As #valid_udp_msg, but raises exception if message is not valid. It calls #check_udp_msg_prefix and Handler#check_msg.

Parameters:

  • msg (String)

    input message.

Returns:

  • (String)

    input message.



42
43
44
45
46
# File 'lib/maxcube/messages/udp/handler.rb', line 42

def check_udp_msg(msg)
  check_udp_msg_prefix(msg)
  check_msg(msg)
  msg
end

#check_udp_msg_prefix(msg) ⇒ String

As #valid_udp_msg_prefix, but it raises exception if the prefix is not valid.

Parameters:

  • msg (String)

    input message.

Returns:

  • (String)

    input message.

Raises:



24
25
26
27
# File 'lib/maxcube/messages/udp/handler.rb', line 24

def check_udp_msg_prefix(msg)
  raise InvalidMessageFormat unless valid_udp_msg_prefix(msg)
  msg
end

#valid_udp_hash(hash) ⇒ Boolean

Validates whether given hash with message contents is valid for UDP Cube messaging purposes. It only calls Handler#valid_hash.

Parameters:

  • hash (Hash)

    input hash.

Returns:

  • (Boolean)

    whether hash is valid.



53
54
55
# File 'lib/maxcube/messages/udp/handler.rb', line 53

def valid_udp_hash(hash)
  valid_hash(hash)
end

#valid_udp_msg(msg) ⇒ Boolean

Validates whether given message is a valid UDP Cube message. It calls #valid_udp_msg_prefix and Handler#valid_msg.

Parameters:

  • msg (String)

    input message.

Returns:

  • (Boolean)

    whether message is valid.



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

def valid_udp_msg(msg)
  valid_udp_msg_prefix(msg) &&
    valid_msg(msg)
end

#valid_udp_msg_prefix(msg) ⇒ Boolean

Validates whether message contains correct MSG_PREFIX (suffix of the prefix differs for parser and serializer).

Parameters:

  • msg (String)

    input message.

Returns:

  • (Boolean)

    whether message prefix is valid.



15
16
17
# File 'lib/maxcube/messages/udp/handler.rb', line 15

def valid_udp_msg_prefix(msg)
  msg.start_with?(self.class.const_get('MSG_PREFIX'))
end