class MaxCube::Messages::UDP::Parser

Extends {Messages::Parser} and {UDP::Handler} of routines connected to UDP Cube messages parsing.

Constants

KEYS

Mandatory hash keys common for all UDP Cube messages.

MSG_PREFIX

{UDP::MSG_PREFIX} with a suffix.

MSG_TYPES

Known message types in the direction Cube -> client.

Public Instance Methods

parse_udp_msg(msg) click to toggle source

Parses single message. Subsequently calls {#check_udp_msg}, {#parse_udp_msg_head}, {#parse_msg_body} and {#check_udp_hash}. @param msg [String] input message. @return [Hash] particular message contents separated into hash.

# 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

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/parser.rb, line 45
def msg_msg_type(msg)
  msg[19]
end
parse_udp_msg_head(msg) click to toggle source

Parses head of UDP Cube message, that is common to all of these. Internal IO variable contains message body string at the end. @param msg [String] input message. @return [Hash] particular message head contents separated into hash.

# File lib/maxcube/messages/udp/parser.rb, line 53
def parse_udp_msg_head(msg)
  @io = StringIO.new(msg, 'rb')
  hash = {
    prefix: read(8),
    serial_number: read(10),
    id: read(1, true),
    type: read(1),
  }
  @io.string = @io.read
  hash
end