slow_blink 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +9 -0
  3. data/ext/slow_blink/ext_schema_parser/parser.c +4 -4
  4. data/ext/slow_blink/message/ext_compact_encoder/compact_encoder.c +5 -5
  5. data/ext/slow_blink/message/ext_compact_encoder/ext_compact_encoder.c +31 -18
  6. data/lib/slow_blink/annotatable.rb +20 -17
  7. data/lib/slow_blink/annotation.rb +20 -18
  8. data/lib/slow_blink/binary.rb +20 -17
  9. data/lib/slow_blink/boolean.rb +20 -17
  10. data/lib/slow_blink/date.rb +20 -17
  11. data/lib/slow_blink/decimal.rb +20 -17
  12. data/lib/slow_blink/definition.rb +21 -19
  13. data/lib/slow_blink/enumeration.rb +30 -26
  14. data/lib/slow_blink/field.rb +20 -17
  15. data/lib/slow_blink/fixed.rb +20 -17
  16. data/lib/slow_blink/floating_point.rb +20 -17
  17. data/lib/slow_blink/group.rb +21 -18
  18. data/lib/slow_blink/incremental_annotation.rb +21 -18
  19. data/lib/slow_blink/integer.rb +20 -17
  20. data/lib/slow_blink/log.rb +20 -17
  21. data/lib/slow_blink/message/binary.rb +23 -18
  22. data/lib/slow_blink/message/boolean.rb +22 -17
  23. data/lib/slow_blink/message/date.rb +23 -18
  24. data/lib/slow_blink/message/decimal.rb +38 -21
  25. data/lib/slow_blink/message/enumeration.rb +31 -21
  26. data/lib/slow_blink/message/field.rb +23 -18
  27. data/lib/slow_blink/message/fixed.rb +23 -19
  28. data/lib/slow_blink/message/floating_point.rb +22 -17
  29. data/lib/slow_blink/message/group.rb +90 -55
  30. data/lib/slow_blink/message/integer.rb +51 -24
  31. data/lib/slow_blink/message/model.rb +197 -131
  32. data/lib/slow_blink/message/sequence.rb +31 -25
  33. data/lib/slow_blink/message/string.rb +23 -18
  34. data/lib/slow_blink/message/time.rb +31 -25
  35. data/lib/slow_blink/message/time_of_day.rb +24 -18
  36. data/lib/slow_blink/name_with_id.rb +20 -17
  37. data/lib/slow_blink/namespace.rb +22 -19
  38. data/lib/slow_blink/object.rb +20 -17
  39. data/lib/slow_blink/parse_error.rb +26 -0
  40. data/lib/slow_blink/ref.rb +20 -17
  41. data/lib/slow_blink/schema.rb +26 -24
  42. data/lib/slow_blink/schema_buffer.rb +20 -17
  43. data/lib/slow_blink/sequence.rb +20 -17
  44. data/lib/slow_blink/string.rb +20 -17
  45. data/lib/slow_blink/sym.rb +20 -17
  46. data/lib/slow_blink/time.rb +20 -17
  47. data/lib/slow_blink/time_of_day.rb +20 -17
  48. data/lib/slow_blink/type.rb +20 -17
  49. data/lib/slow_blink/version.rb +21 -18
  50. data/lib/slow_blink.rb +19 -17
  51. data/test/tc_compact_encoder.rb +64 -30
  52. data/test/tc_group.rb +0 -19
  53. data/test/tc_incr_annote.rb +0 -21
  54. data/test/tc_model_decimal.rb +94 -0
  55. data/test/tc_model_dynamic_group.rb +0 -19
  56. data/test/tc_model_extension.rb +0 -19
  57. data/test/tc_model_sequence_of_string.rb +29 -0
  58. data/test/tc_model_static_group.rb +0 -19
  59. data/test/tc_model_think_blink.rb +0 -19
  60. data/test/tc_types.rb +0 -19
  61. metadata +8 -4
  62. data/lib/slow_blink/compact_encoder.rb +0 -72
  63. data/lib/slow_blink/error.rb +0 -23
@@ -1,43 +1,108 @@
1
- # Copyright (c) 2016 Cameron Harper
1
+ # @license
2
+ #
3
+ # Copyright (c) 2016 Cameron Harper
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ # this software and associated documentation files (the "Software"), to deal in
7
+ # the Software without restriction, including without limitation the rights to
8
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ # the Software, and to permit persons to whom the Software is furnished to do so,
10
+ # subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
2
14
  #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- # this software and associated documentation files (the "Software"), to deal in
5
- # the Software without restriction, including without limitation the rights to
6
- # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
- # the Software, and to permit persons to whom the Software is furnished to do so,
8
- # subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
- # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
- # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
- # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
- # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
21
 
20
22
  module SlowBlink
21
23
 
22
24
  # This module is concerned with generating models from Schema that are optimised for encoding/decoding and enforcing constraints
23
25
  module Message
24
26
 
25
- class Error < StandardError
27
+ # Trying to encode a group which has one or more uninitialised non-optional fields
28
+ class IncompleteGroup < EncodingError
29
+ end
30
+
31
+ # Trying to encode a group which does not have an ID
32
+ class UntaggedGroup < EncodingError
33
+ end
34
+
35
+ # Trying decode a message that has more than {Model#maxRecursion} levels of nesting
36
+ class RecursionLimit < EncodingError
37
+ end
38
+
39
+ # extra bytes exist after sequence of extension groups but before end of container group
40
+ class ExtensionPadding < EncodingError
41
+ end
42
+
43
+ # exponent is not null but mantissa is
44
+ class NullMantissa < EncodingError
45
+ end
46
+
47
+ # Blink Specification: strong (encoding) errors are caused by constraints that *must* be checked
48
+ class StrongError < EncodingError
49
+ end
50
+
51
+ # Blink Specification: weak (encoding) errors are caused by constraints that *may* be checked
52
+ class WeakError < EncodingError
53
+ end
54
+
55
+ class StrongError1 < StrongError
56
+ end
57
+
58
+ class WeakError1 < WeakError
59
+ end
60
+ class WeakError2 < WeakError
61
+ end
62
+ class WeakError3 < WeakError
63
+ end
64
+ class WeakError4 < WeakError
65
+ end
66
+ class WeakError5 < WeakError
67
+ end
68
+ class WeakError6 < WeakError
69
+ end
70
+ class WeakError7 < WeakError
71
+ end
72
+ class WeakError8 < WeakError
73
+ end
74
+ class WeakError9 < WeakError
75
+ end
76
+ class WeakError10 < WeakError
77
+ end
78
+ class WeakError11 < WeakError
79
+ end
80
+ class WeakError12 < WeakError
81
+ end
82
+ class WeakError13 < WeakError
83
+ end
84
+ class WeakError14 < WeakError
85
+ end
86
+ class WeakError15 < WeakError
26
87
  end
27
88
 
89
+ # Use Model to create message models from a {Schema}
28
90
  class Model
29
91
 
30
92
  # the maximum level of nesting in messages able to be decoded by models
31
93
  DEFAULT_MAX_RECURSION = 100
32
94
 
95
+ # @return [Integer]
96
+ attr_reader :maxRecursion
97
+
33
98
  # @api user
34
99
  #
35
- # Create a Model from a {Schema}
100
+ # Generate a Model from a {Schema}
36
101
  #
37
102
  # @param schema [SlowBlink::Schema]
38
- # @param opts [Hash]
103
+ # @param opts [Hash] options
39
104
  #
40
- # @option opts [Symbol] :maxRecursion
105
+ # @option opts [Integer] :maxRecursion
41
106
  #
42
107
  def initialize(schema, **opts)
43
108
 
@@ -62,16 +127,16 @@ module SlowBlink
62
127
  extensionObject = @extensionObject
63
128
 
64
129
  schema.groups.each do |name, g|
65
- this = self
130
+ fields = {}
131
+ g.fields.each do |f|
132
+ fields[f.nameWithID.name] = _model_field(f)
133
+ end
66
134
  @groups[name] = Class.new(Group) do
67
135
  @extensionObject = extensionObject
68
136
  @maxRecursion = maxRecursion
69
137
  @name = g.nameWithID.name
70
138
  @id = g.nameWithID.id
71
- @fields = {}
72
- g.fields.each do |f|
73
- @fields[f.nameWithID.name] = this._model_field(f)
74
- end
139
+ @fields = fields
75
140
  end
76
141
  if g.nameWithID.id
77
142
  @taggedGroups[g.nameWithID.id] = @groups[name]
@@ -83,137 +148,138 @@ module SlowBlink
83
148
 
84
149
  # @api user
85
150
  #
86
- # Initialise a message model instance with a compact form string
87
- #
88
- # @note return value will be an *anonymous* *subclass* *instance* of {Group}
89
- #
151
+ # Initialise a {Group} from a compact form string
90
152
  # @param input [String] Blink Protocol compact form
91
- # @return [Group] group instance
92
- #
153
+ # @return [Group] anonymous subclass instance of Group
154
+ # @raise [WeakError,StrongError]
155
+ # @raise [RecursionLimit]
156
+ # @raise []
93
157
  def decode_compact(input)
94
158
  stack = []
95
159
  inputSize = input.size
96
160
  buf = input.getBinary!
97
161
  if buf.size > 0
98
162
  id = buf.getU64!
99
- groupClass = @taggedGroups[id]
100
- begin
101
- if groupClass
102
- group = groupClass.from_compact!(buf, stack)
103
- else
104
- raise Error.new "W2: Group id #{group.id} is unknown"
105
- end
106
- rescue Error => ex
107
- puts ex
108
- puts "encountered at offset #{inputSize - input.size}"
109
- puts stack.last.name
110
- raise
111
- end
163
+ groupClass = @taggedGroups[id]
164
+ if groupClass
165
+ group = groupClass.from_compact!(buf, stack)
166
+ else
167
+ raise WeakError2.new "W2: Group id #{group.id} is unknown"
168
+ end
112
169
  else
113
- raise Error.new "W1: Top level group cannot be null "
170
+ raise WeakError1.new "W1: Top level group cannot be null"
114
171
  end
115
172
  end
116
173
 
117
174
  # @api user
118
175
  #
119
- # Get a group model
176
+ # Get a {Group} by name
120
177
  #
121
178
  # @param name [String] name of group (may be qualified)
122
- # @return [Class] {DynamicGroup} or {Group}
123
- # @return [nil] group not defined
124
- #
179
+ # @return [Group] anonymous subclass of Group
180
+ # @raise [RangeError] unknown group
125
181
  def group(name)
126
- @groups[name]
127
- end
128
-
129
- # @api private
130
- #
131
- # Create a model for a Field
132
- #
133
- # @param field [SlowBlink::Field] field definition
134
- # @return [Class] anonymous subclass of {Field}
135
- def _model_field(field)
136
- this = self
137
- Class.new(Field) do
138
- @opt = field.opt?
139
- @name = field.nameWithID.name
140
- @id = field.nameWithID.id
141
- @type = this._model_type(field.type, field.opt?)
182
+ group = @groups[name]
183
+ if group
184
+ group
185
+ else
186
+ raise RangeError.new "group '#{name}' is unknown"
142
187
  end
143
188
  end
144
189
 
145
- # @api private
146
- #
147
- # Create a model for a type
148
- #
149
- # @param type [SlowBlink::Type] type definition
150
- # @param opt [true,false] parent definition may allow this type to be optional
151
- #
152
- #
153
- def _model_type(type, opt)
154
- this = self
155
- extensionObject = @extensionObject
156
- maxRecursion = @maxRecursion
157
- case type.class
158
- when SlowBlink::OBJECT
159
- groups = @groups
160
- taggedGroups = @taggedGroups
161
- permitted = @taggedGroups.keys
162
- Class.new(DynamicGroup) do
163
- @extensionObject = extensionObject
164
- @maxRecursion = maxRecursion
165
- @opt = opt
166
- @groups = groups
167
- @taggedGroups = taggedGroups
168
- @permitted = permitted
169
- end
170
- when SlowBlink::REF
171
- if type.ref.kind_of? SlowBlink::Group
172
- if type.dynamic?
173
- taggedGroups = @taggedGroups
174
- groups = @groups
175
- permitted = @taggedGroups.keys
176
- @schema.tagged.each do |id, g|
177
- if g.group_kind_of?(type)
178
- permitted << id
190
+ private
191
+
192
+ # Create a model for a Field
193
+ #
194
+ # @param field [SlowBlink::Field] field definition
195
+ # @return [Class] anonymous subclass of {Field}
196
+ def _model_field(field)
197
+ type = _model_type(field.type, field.opt?)
198
+ Class.new(Field) do
199
+ @opt = field.opt?
200
+ @name = field.nameWithID.name
201
+ @id = field.nameWithID.id
202
+ @type = type
203
+ end
204
+ end
205
+
206
+ # Create a model for a type
207
+ #
208
+ # @param type [SlowBlink::Type] type definition
209
+ # @param opt [true,false] parent definition may allow this type to be optional
210
+ def _model_type(type, opt)
211
+ extensionObject = @extensionObject
212
+ maxRecursion = @maxRecursion
213
+ case type.class
214
+ when SlowBlink::OBJECT
215
+ groups = @groups
216
+ taggedGroups = @taggedGroups
217
+ permitted = @taggedGroups.keys
218
+ Class.new(DynamicGroup) do
219
+ @extensionObject = extensionObject
220
+ @maxRecursion = maxRecursion
221
+ @opt = opt
222
+ @groups = groups
223
+ @taggedGroups = taggedGroups
224
+ @permitted = permitted
225
+ end
226
+ when SlowBlink::REF
227
+ if type.ref.kind_of? SlowBlink::Group
228
+ if type.dynamic?
229
+ taggedGroups = @taggedGroups
230
+ groups = @groups
231
+ permitted = @taggedGroups.keys
232
+ @schema.tagged.each do |id, g|
233
+ if g.group_kind_of?(type)
234
+ permitted << id
235
+ end
179
236
  end
180
- end
181
- Class.new(DynamicGroup) do
182
- @extensionObject = extensionObject
183
- @maxRecursion = maxRecursion
184
- @opt = opt
185
- @taggedGroups = taggedGroups
186
- @groups = groups
187
- @permitted = permitted
188
- end
189
- else
190
- Class.new(StaticGroup) do
191
- @extensionObject = extensionObject
192
- @maxRecursion = maxRecursion
193
- @name = type.ref.nameWithID.name
194
- @id = nil
195
- @opt = opt
196
- @fields = {}
237
+ Class.new(DynamicGroup) do
238
+ @extensionObject = extensionObject
239
+ @maxRecursion = maxRecursion
240
+ @opt = opt
241
+ @taggedGroups = taggedGroups
242
+ @groups = groups
243
+ @permitted = permitted
244
+ end
245
+ else
246
+ fields = {}
197
247
  type.ref.fields.each do |f|
198
- @fields[f.nameWithID.name] = this._model_field(f)
248
+ fields[f.nameWithID.name] = _model_field(f)
199
249
  end
200
- end
250
+ Class.new(StaticGroup) do
251
+ @extensionObject = extensionObject
252
+ @maxRecursion = maxRecursion
253
+ @name = type.ref.nameWithID.name
254
+ @id = nil
255
+ @opt = opt
256
+ @fields = fields
257
+ end
258
+ end
259
+ else
260
+ _model_type(type.ref, false)
261
+ end
262
+ when SlowBlink::SEQUENCE
263
+ t = _model_type(type.type, false)
264
+ Class.new(SEQUENCE) do
265
+ @maxRecursion = maxRecursion
266
+ @type = t
201
267
  end
268
+ when SlowBlink::ENUMERATION
269
+ symbols = {}
270
+ type.symbols.each do |n,v|
271
+ symbols[n] = v.val
272
+ end
273
+ Class.new(ENUMERATION) do
274
+ @symbols = symbols
275
+ end
202
276
  else
203
- _model_type(type.ref)
277
+ Class.new(SlowBlink::Message.const_get(type.class.name.split('::').last)) do
278
+ @opt = opt
279
+ @type = type
280
+ end
204
281
  end
205
- when SlowBlink::SEQUENCE
206
- Class.new(SEQUENCE) do
207
- @maxRecursion = maxRecursion
208
- @type = this._model_type(type.type, false)
209
- end
210
- else
211
- Class.new(SlowBlink::Message.const_get(type.class.name.split('::').last)) do
212
- @opt = opt
213
- @type = type
214
- end
215
282
  end
216
- end
217
283
 
218
284
  end
219
285
 
@@ -1,57 +1,63 @@
1
- # Copyright (c) 2016 Cameron Harper
1
+ # @license
2
+ #
3
+ # Copyright (c) 2016 Cameron Harper
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ # this software and associated documentation files (the "Software"), to deal in
7
+ # the Software without restriction, including without limitation the rights to
8
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ # the Software, and to permit persons to whom the Software is furnished to do so,
10
+ # subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
2
14
  #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- # this software and associated documentation files (the "Software"), to deal in
5
- # the Software without restriction, including without limitation the rights to
6
- # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
- # the Software, and to permit persons to whom the Software is furnished to do so,
8
- # subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
- # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
- # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
- # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
- # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
21
 
20
22
  module SlowBlink::Message
21
23
 
24
+ # @abstract
22
25
  class SEQUENCE
23
26
 
24
27
  # @return the type that repeats in this SEQUENCE
25
28
  def self.type
26
29
  @type
27
30
  end
28
-
31
+
32
+ # @private
29
33
  def self.from_compact!(input, stack)
30
34
 
31
35
  if stack.size < @maxRecursion
32
36
  stack << self
33
37
  else
34
- raise Error.new "stack limit"
38
+ raise RecursionLimit
35
39
  end
36
40
 
37
41
  value = []
38
42
  size = input.getU32!
39
43
  if size
40
- while out.size < size do
44
+ while value.size < size do
41
45
  value << @type.from_compact!(input, stack)
42
46
  end
43
- self.new(value)
47
+ result = self.new(value)
44
48
  else
45
- nil
49
+ result = nil
46
50
  end
47
51
 
48
52
  stack.pop
49
-
53
+
54
+ result
55
+
50
56
  end
51
57
 
52
58
  # @return [Array]
53
59
  def get
54
- @value
60
+ @value.map{|v|v.get}
55
61
  end
56
62
 
57
63
  # Set value of a SEQUENCE
@@ -59,7 +65,6 @@ module SlowBlink::Message
59
65
  # @param value [Array]
60
66
  # @raise [TypeError]
61
67
  # @raise [RangeError]
62
- #
63
68
  def set(value)
64
69
  @value = []
65
70
  if value.kind_of? Array
@@ -80,6 +85,7 @@ module SlowBlink::Message
80
85
  set(value)
81
86
  end
82
87
 
88
+ # @private
83
89
  def to_compact(out)
84
90
  out.putU32(@value.size)
85
91
  @value.each do |value|
@@ -1,33 +1,37 @@
1
- # Copyright (c) 2016 Cameron Harper
1
+ # @license
2
+ #
3
+ # Copyright (c) 2016 Cameron Harper
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ # this software and associated documentation files (the "Software"), to deal in
7
+ # the Software without restriction, including without limitation the rights to
8
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ # the Software, and to permit persons to whom the Software is furnished to do so,
10
+ # subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
2
14
  #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- # this software and associated documentation files (the "Software"), to deal in
5
- # the Software without restriction, including without limitation the rights to
6
- # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
- # the Software, and to permit persons to whom the Software is furnished to do so,
8
- # subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
- # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
- # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
- # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
- # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
21
 
20
22
  module SlowBlink::Message
21
23
 
24
+ # @abstract
22
25
  class STRING
23
26
 
27
+ # @private
24
28
  def self.from_compact!(input, stack)
25
29
  value = input.getString!
26
30
  if value
27
31
  if !@type.size or value.size <= @type.size
28
32
  self.new(value)
29
33
  else
30
- raise Error.new "W7: String value exceeds maximum size"
34
+ raise WeakError7.new "W7: String value exceeds maximum size"
31
35
  end
32
36
  else
33
37
  value
@@ -65,6 +69,7 @@ module SlowBlink::Message
65
69
  set(value)
66
70
  end
67
71
 
72
+ # @private
68
73
  def to_compact(out)
69
74
  out.putString(@value)
70
75
  end
@@ -1,28 +1,31 @@
1
- # Copyright (c) 2016 Cameron Harper
1
+ # @license
2
+ #
3
+ # Copyright (c) 2016 Cameron Harper
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ # this software and associated documentation files (the "Software"), to deal in
7
+ # the Software without restriction, including without limitation the rights to
8
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ # the Software, and to permit persons to whom the Software is furnished to do so,
10
+ # subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
2
14
  #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- # this software and associated documentation files (the "Software"), to deal in
5
- # the Software without restriction, including without limitation the rights to
6
- # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
- # the Software, and to permit persons to whom the Software is furnished to do so,
8
- # subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
- # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
- # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
- # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
- # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
-
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21
  require 'time'
21
22
 
22
23
  module SlowBlink::Message
23
24
 
25
+ # @abstract
24
26
  class MILLI_TIME
25
27
 
28
+ # @private
26
29
  def self.from_compact!(input, stack)
27
30
  value = input.getI64!
28
31
  if value
@@ -52,7 +55,7 @@ module SlowBlink::Message
52
55
  elsif value.kind_of? String
53
56
  @value = DateTime.parse(value)
54
57
  elsif value.kind_of? Integer
55
- @value = DateTime.new(value)
58
+ @value = DateTime.strptime(value.to_s, '%Q')
56
59
  else
57
60
  raise TypeError
58
61
  end
@@ -63,17 +66,15 @@ module SlowBlink::Message
63
66
  set(value)
64
67
  end
65
68
 
69
+ # @private
66
70
  def to_compact(out)
67
- out.putI64(@value.strftime('%Q'))
71
+ out.putI64(@value.strftime('%Q').to_i)
68
72
  end
69
73
 
70
74
  end
71
75
 
76
+ # @abstract
72
77
  class NANO_TIME < MILLI_TIME
73
-
74
- def to_compact(out)
75
- out.putI64(@value.strftime('%N'))
76
- end
77
78
 
78
79
  # @overload set(value)
79
80
  # Set a nanosecond resolution time value
@@ -90,11 +91,16 @@ module SlowBlink::Message
90
91
  elsif value.kind_of? String
91
92
  @value = DateTime.parse(value)
92
93
  elsif value.kind_of? Integer
93
- @value = DateTime.new(value)
94
+ @value = DateTime.strptime(value.to_s, '%N')
94
95
  else
95
96
  raise TypeError
96
97
  end
97
98
  end
99
+
100
+ # @private
101
+ def to_compact(out)
102
+ out.putI64(@value.strftime('%N').to_i)
103
+ end
98
104
 
99
105
  end
100
106