Module: MaxCube::Messages::Serializer
Constant Summary
DAYS_OF_WEEK, DEVICE_MODE, DEVICE_TYPE, PACK_FORMAT
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
#serialize(*args, esize: 0, size: 0, ocount: 0) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/maxcube/messages/serializer.rb', line 8
def serialize(*args, esize: 0, size: 0, ocount: 0)
return args.join if size.zero? && esize.zero?
ocount, subcount, subsize = serialize_bounds(args,
esize: esize,
size: size,
ocount: ocount)
str = ''
args.reverse!
ocount.times do
str << args.pop while args.last.is_a?(String)
substr = args.pop(subcount).pack(PACK_FORMAT[subsize])
substr = substr[1..-1] if subsize == 3
str << substr
end
str << args.pop until args.empty?
str
end
|
#serialize_hash_body(hash, serializer_type_str) ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/maxcube/messages/serializer.rb', line 32
def serialize_hash_body(hash, serializer_type_str)
method_str = "serialize_#{serializer_type_str}_#{@msg_type.downcase}"
return send(method_str, hash) if respond_to?(method_str, true)
raise InvalidMessageType
.new(@msg_type, 'serialization of message type' \
' is not implemented (yet)')
end
|
#write(*args, esize: 0, size: 0, ocount: 0) ⇒ Object
28
29
30
|
# File 'lib/maxcube/messages/serializer.rb', line 28
def write(*args, esize: 0, size: 0, ocount: 0)
@io.write(serialize(*args, esize: esize, size: size, ocount: ocount))
end
|