Sha256: a2dd48b7c5bc303614a6f6862a1f22e9805c495a65463d503c2ff3a01e684a47
Contents?: true
Size: 1.41 KB
Versions: 2
Compression:
Stored size: 1.41 KB
Contents
require_relative 'handler' require 'maxcube/messages/serializer' module MaxCube module Messages module UDP # Extends {Messages::Serializer} and {UDP::Handler} of routines # connected to UDP Cube messages serializing. class Serializer include UDP::Handler include Messages::Serializer # Known message types in the direction client -> Cube. MSG_TYPES = %w[I N h c R].freeze # {UDP::MSG_PREFIX} with a suffix. MSG_PREFIX = (UDP::MSG_PREFIX + "*\x00").freeze # 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. 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 # Tells how to get message type from a message. # @param msg [String] input message. # @return [String] message type. def msg_msg_type(msg) msg[18] end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
maxcube-client-0.5.1 | lib/maxcube/messages/udp/serializer.rb |
maxcube-client-0.5.0 | lib/maxcube/messages/udp/serializer.rb |