maxcube-client 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -0
  3. data/.rubocop.yml +0 -3
  4. data/.yardopts +1 -0
  5. data/README.md +17 -2
  6. data/bin/maxcube-client +2 -27
  7. data/doc/MaxCube.html +502 -0
  8. data/doc/MaxCube/Messages.html +1927 -0
  9. data/doc/MaxCube/Messages/Handler.html +2912 -0
  10. data/doc/MaxCube/Messages/InvalidMessage.html +140 -0
  11. data/doc/MaxCube/Messages/InvalidMessageBody.html +264 -0
  12. data/doc/MaxCube/Messages/InvalidMessageFormat.html +247 -0
  13. data/doc/MaxCube/Messages/InvalidMessageLength.html +247 -0
  14. data/doc/MaxCube/Messages/InvalidMessageType.html +263 -0
  15. data/doc/MaxCube/Messages/Parser.html +520 -0
  16. data/doc/MaxCube/Messages/Serializer.html +701 -0
  17. data/doc/MaxCube/Messages/TCP.html +172 -0
  18. data/doc/MaxCube/Messages/TCP/Handler.html +1396 -0
  19. data/doc/MaxCube/Messages/TCP/Parser.html +462 -0
  20. data/doc/MaxCube/Messages/TCP/Parser/MessageA.html +186 -0
  21. data/doc/MaxCube/Messages/TCP/Parser/MessageC.html +1077 -0
  22. data/doc/MaxCube/Messages/TCP/Parser/MessageF.html +206 -0
  23. data/doc/MaxCube/Messages/TCP/Parser/MessageH.html +338 -0
  24. data/doc/MaxCube/Messages/TCP/Parser/MessageL.html +535 -0
  25. data/doc/MaxCube/Messages/TCP/Parser/MessageM.html +510 -0
  26. data/doc/MaxCube/Messages/TCP/Parser/MessageN.html +226 -0
  27. data/doc/MaxCube/Messages/TCP/Parser/MessageS.html +225 -0
  28. data/doc/MaxCube/Messages/TCP/Serializer.html +460 -0
  29. data/doc/MaxCube/Messages/TCP/Serializer/MessageA.html +186 -0
  30. data/doc/MaxCube/Messages/TCP/Serializer/MessageC.html +185 -0
  31. data/doc/MaxCube/Messages/TCP/Serializer/MessageF.html +206 -0
  32. data/doc/MaxCube/Messages/TCP/Serializer/MessageL.html +185 -0
  33. data/doc/MaxCube/Messages/TCP/Serializer/MessageM.html +428 -0
  34. data/doc/MaxCube/Messages/TCP/Serializer/MessageN.html +209 -0
  35. data/doc/MaxCube/Messages/TCP/Serializer/MessageQ.html +185 -0
  36. data/doc/MaxCube/Messages/TCP/Serializer/MessageS.html +1168 -0
  37. data/doc/MaxCube/Messages/TCP/Serializer/MessageT.html +240 -0
  38. data/doc/MaxCube/Messages/TCP/Serializer/MessageU.html +206 -0
  39. data/doc/MaxCube/Messages/TCP/Serializer/MessageZ.html +252 -0
  40. data/doc/MaxCube/Messages/UDP.html +164 -0
  41. data/doc/MaxCube/Messages/UDP/Handler.html +832 -0
  42. data/doc/MaxCube/Messages/UDP/Parser.html +609 -0
  43. data/doc/MaxCube/Messages/UDP/Parser/MessageH.html +218 -0
  44. data/doc/MaxCube/Messages/UDP/Parser/MessageI.html +215 -0
  45. data/doc/MaxCube/Messages/UDP/Parser/MessageN.html +226 -0
  46. data/doc/MaxCube/Messages/UDP/Serializer.html +484 -0
  47. data/doc/MaxCube/Network.html +167 -0
  48. data/doc/MaxCube/Network/TCP.html +150 -0
  49. data/doc/MaxCube/Network/TCP/Client.html +1930 -0
  50. data/doc/MaxCube/Network/TCP/Client/Commands.html +2457 -0
  51. data/doc/MaxCube/Network/TCP/SampleServer.html +910 -0
  52. data/doc/MaxCube/Network/UDP.html +150 -0
  53. data/doc/MaxCube/Network/UDP/Client.html +518 -0
  54. data/doc/MaxCube/Network/UDP/SampleSocket.html +628 -0
  55. data/doc/MaxCube/Runner.html +355 -0
  56. data/doc/_index.html +518 -0
  57. data/doc/class_list.html +51 -0
  58. data/doc/css/common.css +1 -0
  59. data/doc/css/full_list.css +58 -0
  60. data/doc/css/style.css +499 -0
  61. data/doc/file.README.html +140 -0
  62. data/doc/file_list.html +56 -0
  63. data/doc/frames.html +17 -0
  64. data/doc/index.html +140 -0
  65. data/doc/js/app.js +248 -0
  66. data/doc/js/full_list.js +216 -0
  67. data/doc/js/jquery.js +4 -0
  68. data/doc/method_list.html +1699 -0
  69. data/doc/top-level-namespace.html +110 -0
  70. data/lib/maxcube.rb +11 -0
  71. data/lib/maxcube/messages.rb +85 -8
  72. data/lib/maxcube/messages/handler.rb +138 -4
  73. data/lib/maxcube/messages/parser.rb +33 -2
  74. data/lib/maxcube/messages/serializer.rb +64 -16
  75. data/lib/maxcube/messages/tcp.rb +11 -7
  76. data/lib/maxcube/messages/tcp/handler.rb +50 -2
  77. data/lib/maxcube/messages/tcp/parser.rb +18 -17
  78. data/lib/maxcube/messages/tcp/serializer.rb +20 -21
  79. data/lib/maxcube/messages/tcp/type/a.rb +6 -6
  80. data/lib/maxcube/messages/tcp/type/c.rb +5 -3
  81. data/lib/maxcube/messages/tcp/type/f.rb +5 -3
  82. data/lib/maxcube/messages/tcp/type/h.rb +3 -2
  83. data/lib/maxcube/messages/tcp/type/l.rb +8 -7
  84. data/lib/maxcube/messages/tcp/type/m.rb +11 -7
  85. data/lib/maxcube/messages/tcp/type/n.rb +5 -3
  86. data/lib/maxcube/messages/tcp/type/q.rb +2 -2
  87. data/lib/maxcube/messages/tcp/type/s.rb +5 -2
  88. data/lib/maxcube/messages/tcp/type/t.rb +5 -4
  89. data/lib/maxcube/messages/tcp/type/u.rb +2 -1
  90. data/lib/maxcube/messages/tcp/type/z.rb +4 -2
  91. data/lib/maxcube/messages/udp.rb +7 -0
  92. data/lib/maxcube/messages/udp/handler.rb +28 -0
  93. data/lib/maxcube/messages/udp/parser.rb +23 -6
  94. data/lib/maxcube/messages/udp/serializer.rb +17 -1
  95. data/lib/maxcube/messages/udp/type/h.rb +2 -0
  96. data/lib/maxcube/messages/udp/type/i.rb +3 -0
  97. data/lib/maxcube/messages/udp/type/n.rb +3 -0
  98. data/lib/maxcube/network.rb +5 -1
  99. data/lib/maxcube/network/tcp.rb +3 -0
  100. data/lib/maxcube/network/tcp/client.rb +117 -3
  101. data/lib/maxcube/network/tcp/client/commands.rb +306 -239
  102. data/lib/maxcube/network/tcp/sample_server.rb +1 -0
  103. data/lib/maxcube/network/udp.rb +3 -0
  104. data/lib/maxcube/network/udp/client.rb +2 -0
  105. data/lib/maxcube/network/udp/sample_socket.rb +1 -0
  106. data/lib/maxcube/runner.rb +45 -0
  107. data/lib/maxcube/version.rb +2 -1
  108. data/maxcube-client.gemspec +2 -0
  109. metadata +84 -3
@@ -2,9 +2,27 @@ require_relative 'handler'
2
2
 
3
3
  module MaxCube
4
4
  module Messages
5
+ # This module provides methods connected to message parsing only
6
+ # (i.e. direction Cube -> client).
5
7
  module Parser
6
8
  include Handler
7
9
 
10
+ # This method should be used each time any +IO+ is read,
11
+ # which is very useful for parsing purposes.
12
+ # It contains optional implicit conversion
13
+ # of binary string data of certain length into integers
14
+ # (using {PACK_FORMAT})
15
+ # or into any other explicit format that String#unpack understands.
16
+ # In addition, it checks whether the read operation succeeded
17
+ # and raises an exception if not
18
+ # (this is useful when parsing a message of a specified format).
19
+ # @param count [Integer] number of bytes to read.
20
+ # 0 causes to read until EOF.
21
+ # @param unpack [Boolean, String] if +true+
22
+ # it does implicit conversion to integer;
23
+ # if String, the format is passed to String#unpack as is.
24
+ # @return [String, Integer] read data; its type depends on +unpack+.
25
+ # @raise [IOError] if reading failed (incl. that nothing was read).
8
26
  def read(count = 0, unpack = false)
9
27
  str = if count.zero?
10
28
  @io.read
@@ -18,8 +36,21 @@ module MaxCube
18
36
  str.unpack1(unpack)
19
37
  end
20
38
 
21
- def parse_msg_body(body, hash, parser_type_str)
22
- method_str = "parse_#{parser_type_str}_#{@msg_type.downcase}"
39
+ # Parses message body, i.e. at least message type is already decoded.
40
+ # It dynamically calls method corresponding to message and parser type.
41
+ # If message type is not implemented yet, read data is stored as is.
42
+ # It transforms unhandled +IOError+ exceptions
43
+ # (probably raised from {#read}) to {InvalidMessageBody}.
44
+ # @param body [String] message body to be parsed.
45
+ # @param hash [Hash] hash to store parsed data into.
46
+ # It should already contain contents of message head.
47
+ # Hash will be modified.
48
+ # @param parser_type [String] parser type contained in method identifiers.
49
+ # @return [Hash, nil] resulting hash, or +nil+ in case
50
+ # the message type is not implemented yet.
51
+ # @raise [InvalidMessageBody] if +IOError+ catched.
52
+ def parse_msg_body(body, hash, parser_type)
53
+ method_str = "parse_#{parser_type}_#{@msg_type.downcase}"
23
54
  if respond_to?(method_str, true)
24
55
  return hash.merge!(send(method_str, body))
25
56
  end
@@ -2,19 +2,43 @@ require_relative 'handler'
2
2
 
3
3
  module MaxCube
4
4
  module Messages
5
+ # This module provides methods connected to message serializing only
6
+ # (i.e. direction client -> Cube).
5
7
  module Serializer
6
8
  include Handler
7
9
 
8
- def serialize(*args, esize: 0, size: 0, ocount: 0)
10
+ # Serializes input +args+ into String,
11
+ # with optional implicit conversion from integer into binary string
12
+ # (using {PACK_FORMAT}).
13
+ # In any case, String elements are serialized as they are.
14
+ # @param args [Array<String, Integer>] input arguments.
15
+ # @param esize [Integer] output size of binary string
16
+ # of each converted integer element.
17
+ # Nonzero value enables conversion of integers into binary strings.
18
+ # This value is sufficient alone, but it is not suitable in cases
19
+ # when more elements are to be grouped together -
20
+ # +esize+ is in interval (0,1) in this case.
21
+ # Output count (+count+) is assumed to be the same with input count.
22
+ # @param size [Integer] total output size of binary string
23
+ # of converted integer elements.
24
+ # Nonzero value enables conversion of integers into binary strings.
25
+ # This value is sufficient alone
26
+ # if output count is same with input count.
27
+ # @param count [Integer] output count of converted integer elements.
28
+ # +size+ must be specified. 0 means same count as input count.
29
+ # It is suitable for cases when input and output counts differ.
30
+ # @return [String] serialized +args+. If conversion was enabled,
31
+ # it may contain binary data.
32
+ def serialize(*args, esize: 0, size: 0, count: 0)
9
33
  return args.join if size.zero? && esize.zero?
10
34
 
11
- ocount, subcount, subsize = serialize_bounds(args,
12
- esize: esize,
13
- size: size,
14
- ocount: ocount)
35
+ count, subcount, subsize = serialize_bounds(args,
36
+ esize: esize,
37
+ size: size,
38
+ count: count)
15
39
  str = ''
16
40
  args.reverse!
17
- ocount.times do
41
+ count.times do
18
42
  str << args.pop while args.last.is_a?(String)
19
43
  substr = args.pop(subcount).pack(PACK_FORMAT[subsize])
20
44
  substr = substr[1..-1] if subsize == 3
@@ -25,12 +49,26 @@ module MaxCube
25
49
  str
26
50
  end
27
51
 
28
- def write(*args, esize: 0, size: 0, ocount: 0)
29
- @io.write(serialize(*args, esize: esize, size: size, ocount: ocount))
52
+ # It serializes +args+ with {#serialize}
53
+ # and writes it into internal +IO+ variable.
54
+ def write(*args, esize: 0, size: 0, count: 0)
55
+ @io.write(serialize(*args, esize: esize, size: size, count: count))
30
56
  end
31
57
 
32
- def serialize_hash_body(hash, serializer_type_str)
33
- method_str = "serialize_#{serializer_type_str}_#{@msg_type.downcase}"
58
+ # Serializes message body,
59
+ # i.e. message head has been already serialized.
60
+ # It dynamically calls method corresponding to message
61
+ # and serializer type.
62
+ # If message type is not implemented yet,
63
+ # it is unclear how to serialize the +hash+,
64
+ # so an exception is raised.
65
+ # @param hash [Hash] hash with message contents to serialize.
66
+ # @param serializer_type [String] serializer type
67
+ # contained in method identifiers.
68
+ # @return [String] resulting message string.
69
+ # @raise [InvalidMessageType] if the message type is not implemented yet.
70
+ def serialize_hash_body(hash, serializer_type)
71
+ method_str = "serialize_#{serializer_type}_#{@msg_type.downcase}"
34
72
  return send(method_str, hash) if respond_to?(method_str, true)
35
73
  raise InvalidMessageType
36
74
  .new(@msg_type, 'serialization of message type' \
@@ -39,20 +77,30 @@ module MaxCube
39
77
 
40
78
  private
41
79
 
42
- def serialize_bounds(args, esize: 0, size: 0, ocount: 0)
80
+ # Helper method called by {#serialize}
81
+ # that evaluates necessary counts and sizes
82
+ # for purposes of integer elements conversion in loop.
83
+ # @return [[count, subcount, subsize]]
84
+ # +count+ is output count of converted elements
85
+ # (0 if +args+ array is empty),
86
+ # +subcount+ is number of elements
87
+ # to be converted together in each step,
88
+ # +subsize+ is output size in bytes
89
+ # to which to convert elements in each step into.
90
+ def serialize_bounds(args, esize: 0, size: 0, count: 0)
43
91
  icount = args.size - args.count { |a| a.is_a?(String) }
44
92
  return 0 if icount.zero?
45
93
  if esize.zero?
46
- ocount = icount if ocount.zero?
47
- subsize = size / ocount
94
+ count = icount if count.zero?
95
+ subsize = size / count
48
96
  else
49
97
  size = icount * esize
50
- ocount = size / esize
98
+ count = size / esize
51
99
  subsize = esize
52
100
  end
53
- subcount = icount / ocount
101
+ subcount = icount / count
54
102
 
55
- [ocount, subcount, subsize]
103
+ [count, subcount, subsize]
56
104
  end
57
105
  end
58
106
  end
@@ -2,16 +2,20 @@ require 'maxcube/messages'
2
2
 
3
3
  module MaxCube
4
4
  module Messages
5
- # Structure of message:
6
- # * Starts with single letter followed by ':'
7
- # * Ends with "\r\n"
8
- # Example (unencoded):
9
- # X:message\r\n
10
- # As all messages are being split by "\r\n",
5
+ # This module contains classes aimed onto TCP messages of Cube protocol.
6
+ #
7
+ # Structure of every TCP Cube message:
8
+ # * Starts with single letter followed by +:+
9
+ # * Ends with +\\r\\n+
10
+ # * Except of the end, it contains only printable characters.
11
+ # As all messages are being split by +\\r\\n+,
11
12
  # it does not occur in single message processing,
12
13
  # only in raw data processing.
14
+ # @example
15
+ # X:message\r\n
13
16
  module TCP
14
- # Without "\r\n", with it it is 1900
17
+ # Maximum length of TCP Cube message
18
+ # without +\\r\\n+ (with it it would be 1900)
15
19
  MSG_MAX_LEN = 1898
16
20
  end
17
21
  end
@@ -4,34 +4,60 @@ require 'maxcube/messages/handler'
4
4
  module MaxCube
5
5
  module Messages
6
6
  module TCP
7
+ # Extends {Messages::Handler} of routines connected to TCP Cube messages.
7
8
  module Handler
8
9
  include Messages::Handler
9
10
 
11
+ # Validates whether message satisfies {MSG_MAX_LEN}.
12
+ # @param msg [String] input message.
13
+ # @return [Boolean] whether message length is valid.
10
14
  def valid_tcp_msg_length(msg)
11
15
  msg.length.between?(2, MSG_MAX_LEN)
12
16
  end
13
17
 
18
+ # As {#valid_tcp_msg_length}, but raises exception
19
+ # if message length is not valid.
20
+ # @param msg [String] input message.
21
+ # @return [Integer] message length.
22
+ # @raise [InvalidMessageLength] if message length is not valid.
14
23
  def check_tcp_msg_length(msg)
15
24
  raise InvalidMessageLength unless valid_tcp_msg_length(msg)
16
25
  msg.length
17
26
  end
18
27
 
28
+ # Validates whether message satisfies TCP Cube format (see {TCP}).
29
+ # @param msg [String] input message.
30
+ # @return [Boolean] whether message format is valid.
19
31
  def valid_tcp_msg_format(msg)
20
32
  msg =~ /\A[[:alpha:]]:[[:print:]]*\z/
21
33
  end
22
34
 
35
+ # As {#valid_tcp_msg_format}, but raises exception
36
+ # if message format is not valid.
37
+ # @param msg [String] input message.
38
+ # @return [String] input message.
39
+ # @raise [InvalidMessageFormat] if message format is not valid.
23
40
  def check_tcp_msg_format(msg)
24
41
  raise InvalidMessageFormat unless valid_tcp_msg_format(msg)
25
42
  msg
26
43
  end
27
44
 
28
- # Check single message validity, already without "\r\n" at the end
45
+ # Validates whether given message is a valid TCP Cube message.
46
+ # It calls {#valid_tcp_msg_length},
47
+ # {#valid_tcp_msg_format} and {#valid_msg}.
48
+ # @param msg [String] input message.
49
+ # @return [Boolean] whether message is valid.
29
50
  def valid_tcp_msg(msg)
30
51
  valid_tcp_msg_length(msg) &&
31
52
  valid_tcp_msg_format(msg) &&
32
53
  valid_msg(msg)
33
54
  end
34
55
 
56
+ # As {#valid_tcp_msg}, but raises exception if message is not valid.
57
+ # It calls {#check_tcp_msg_length},
58
+ # {#check_tcp_msg_format} and {#check_msg}.
59
+ # @param msg [String] input message.
60
+ # @return [String] input message.
35
61
  def check_tcp_msg(msg)
36
62
  check_tcp_msg_length(msg)
37
63
  check_tcp_msg_format(msg)
@@ -39,28 +65,50 @@ module MaxCube
39
65
  msg
40
66
  end
41
67
 
68
+ # Validates whether given hash with message contents
69
+ # is valid for TCP Cube messaging purposes.
70
+ # It only calls {#valid_hash}.
71
+ # @param hash [Hash] input hash.
72
+ # @return [Boolean] whether hash is valid.
42
73
  def valid_tcp_hash(hash)
43
74
  valid_hash(hash)
44
75
  end
45
76
 
77
+ # As {#valid_tcp_hash}, but raises exception if hash is not valid.
78
+ # It only calls {#check_hash}.
79
+ # @param hash [Hash] input hash.
80
+ # @return [Hash] input hash.
46
81
  def check_tcp_hash(hash)
47
82
  check_hash(hash)
48
83
  hash
49
84
  end
50
85
 
86
+ # Validates whether input raw data
87
+ # containing multiple separated TCP Cube messages is valid.
88
+ # It only checks +\\r\\\n+ stuff.
89
+ # It does not validate data type ({#valid_data_type}), yet?
90
+ # It does not validate particular messages.
91
+ # @param raw_data [String] input data with multiple separated messages.
92
+ # @return [Boolean] whether input data is valid.
51
93
  def valid_tcp_data(raw_data)
52
94
  return true if raw_data.empty?
53
95
  raw_data[0..1] != "\r\n" && raw_data.chars.last(2).join == "\r\n"
54
96
  end
55
97
 
98
+ # As {#valid_tcp_data}, but raises exception if raw data is not valid.
99
+ # @param raw_data [String] input data with multiple separated messages.
100
+ # @return [String] input data.
101
+ # @raise [InvalidMessageFormat] if input data is not valid.
56
102
  def check_tcp_data(raw_data)
57
- # check_data_type(raw_data)
58
103
  raise InvalidMessageFormat unless valid_tcp_data(raw_data)
59
104
  raw_data
60
105
  end
61
106
 
62
107
  private
63
108
 
109
+ # Tells how to get message type from a message.
110
+ # @param msg [String] input message.
111
+ # @return [String] message type.
64
112
  def msg_msg_type(msg)
65
113
  msg.chr
66
114
  end
@@ -4,35 +4,36 @@ require 'maxcube/messages/parser'
4
4
  module MaxCube
5
5
  module Messages
6
6
  module TCP
7
+ # Extends {Messages::Parser} and {TCP::Handler} of routines
8
+ # connected to TCP Cube messages parsing.
7
9
  class Parser
8
- include Handler
10
+ include TCP::Handler
9
11
  include Messages::Parser
10
12
 
11
- %w[a c f h l m n s].each { |f| require_relative 'type/' << f }
13
+ %w[a c f h l m n s].each do |f|
14
+ require_relative 'type/' << f
15
+ include const_get('Message' << f.upcase)
16
+ end
12
17
 
18
+ # Known message types in the direction Cube -> client.
13
19
  MSG_TYPES = %w[H F L C M N A E D b g j p o v w S].freeze
14
20
 
15
- include MessageA
16
- include MessageC
17
- include MessageF
18
- include MessageH
19
- include MessageL
20
- include MessageM
21
- include MessageN
22
- include MessageS
23
-
24
- # Process set of messages - raw data separated by "\r\n"
25
- # @param [String, #read] raw data from a Cube
21
+ # Processes set of messages - raw data separated by +\\r\\n+.
22
+ # Calls {#check_tcp_data}
23
+ # and maps {#parse_tcp_msg} on each message.
24
+ # @param raw_data [String] raw data from a Cube
26
25
  # @return [Array<Hash>] particular message contents
27
26
  def parse_tcp_data(raw_data)
28
27
  check_tcp_data(raw_data)
29
28
  raw_data.split("\r\n").map(&method(:parse_tcp_msg))
30
29
  end
31
30
 
32
- # Parse single message already without "\r\n"
33
- # @param [String, #read] single message data without "\r\n"
34
- # @return [Hash] particular message parts separated into hash,
35
- # which should be human readable
31
+ # Parses single message already without +\\r\\n+.
32
+ # Subsequently calls {#check_tcp_msg},
33
+ # {#parse_msg_body}
34
+ # and {#check_tcp_hash}.
35
+ # @param msg [String] input message (without +\\r\\n+).
36
+ # @return [Hash] particular message contents separated into hash.
36
37
  def parse_tcp_msg(msg)
37
38
  check_tcp_msg(msg)
38
39
  body = msg.split(':')[1] || ''
@@ -4,38 +4,37 @@ require 'maxcube/messages/serializer'
4
4
  module MaxCube
5
5
  module Messages
6
6
  module TCP
7
+ # Extends {Messages::Serializer} and {TCP::Handler} of routines
8
+ # connected to TCP Cube messages serializing.
7
9
  class Serializer
8
- include Handler
10
+ include TCP::Handler
9
11
  include Messages::Serializer
10
12
 
11
- %w[a c f l m n q s t u z].each { |f| require_relative 'type/' << f }
13
+ %w[a c f l m n q s t u z].each do |f|
14
+ require_relative 'type/' << f
15
+ include const_get('Message' << f.upcase)
16
+ end
12
17
 
18
+ # Known message types in the direction client -> Cube.
13
19
  MSG_TYPES = %w[u i s m n x g q e d B G J P O V W a r t l c v f z].freeze
14
20
 
15
- include MessageA
16
- include MessageC
17
- include MessageF
18
- include MessageL
19
- include MessageM
20
- include MessageN
21
- include MessageQ
22
- include MessageS
23
- include MessageT
24
- include MessageU
25
- include MessageZ
26
-
27
- # Send set of messages separated by "\r\n"
28
- # @param [Array<Hash>] particular message contents
29
- # @return [String] raw data for a Cube
21
+ # Generates set of messages separated by +\\r\\n+.
22
+ # Calls {#check_tcp_data}
23
+ # and maps {#serialize_tcp_hash} on each hash.
24
+ # @param hashes [Array<Hash>] particular message contents.
25
+ # @return [String] raw data for a Cube.
30
26
  def serialize_tcp_hashes(hashes)
31
27
  raw_data = hashes.map(&method(:serialize_tcp_hash)).join
32
28
  check_tcp_data(raw_data)
33
29
  end
34
30
 
35
- # Serialize data from hash into message with "\r\n" at the end
36
- # @param [Hash, #read] particular human readable message parts
37
- # (it is assumed to contain valid data)
38
- # @return [String] single message data with "\r\n" at the end
31
+ # Serializes data from a single hash
32
+ # into TCP Cube message with +\\r\\n+ at the end.
33
+ # Subsequently calls {#check_tcp_hash},
34
+ # {#serialize_hash_body}
35
+ # and {#check_tcp_msg}.
36
+ # @param hash [Hash] particular message contents separated into hash.
37
+ # @return [String] output message (with +\\r\\n+).
39
38
  def serialize_tcp_hash(hash)
40
39
  check_tcp_hash(hash)
41
40
  msg = "#{@msg_type}:" << serialize_hash_body(hash, 'tcp')
@@ -3,12 +3,12 @@ module MaxCube
3
3
  module Messages
4
4
  module TCP
5
5
  class Parser
6
+ # Acknowledgement message to previous command
7
+ # e.g. factory reset (a), delete a device (t), wake up (z).
8
+ # Does not contain any data.
6
9
  module MessageA
7
10
  private
8
11
 
9
- # Acknowledgement message to previous command
10
- # e.g. factory reset (a), delete a device (t), wake up (z)
11
- # Ignore all contents of the message
12
12
  def parse_tcp_a(_body)
13
13
  {}
14
14
  end
@@ -16,12 +16,12 @@ module MaxCube
16
16
  end
17
17
 
18
18
  class Serializer
19
+ # Factory reset command.
20
+ # Does not contain any data.
21
+ # Acknowledgement (A) follows.
19
22
  module MessageA
20
23
  private
21
24
 
22
- # Factory reset command
23
- # Does not contain any data
24
- # Acknowledgement (A) follows
25
25
  def serialize_tcp_a(_hash)
26
26
  ''
27
27
  end