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,57 +1,74 @@
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
  require 'bigdecimal'
21
23
 
22
24
  module SlowBlink::Message
23
25
 
26
+ # @abstract
24
27
  class DECIMAL
25
28
 
29
+ # @private
26
30
  def self.from_compact!(input, stack)
27
31
  e = input.getI8!
28
32
  if e
29
33
  m = input.getI64!
30
34
  if m
31
- self.new("#{m}E#{e}")
35
+ self.new("#{m}E#{e}")
32
36
  else
33
- raise "a null mantissa is not defined"
37
+ raise NullMantissa
34
38
  end
35
39
  else
36
40
  nil
37
41
  end
38
42
  end
39
43
 
44
+ # @note calls {#set}(value)
40
45
  def initialize(value)
41
46
  set(value)
42
47
  end
43
48
 
49
+ # @return [BigDecimal]
44
50
  def get
45
51
  @value
46
52
  end
47
53
 
54
+ # Set a decimal value
55
+ # @param value [Numeric]
56
+ # @raise [TypeError]
48
57
  def set(value)
49
58
  @value = BigDecimal.new(value.to_s)
50
59
  end
51
60
 
61
+ # @private
52
62
  def to_compact(out)
53
- out.putI8(@value.exponent)
54
- out.putI64(0)
63
+
64
+ split = @value.split
65
+
66
+ exponent = - split[1].size + split[3]
67
+ mantissa = split[0]*split[1].to_i
68
+
69
+ out.putI8(exponent)
70
+ out.putI64(mantissa)
71
+
55
72
  end
56
73
 
57
74
  end
@@ -1,24 +1,27 @@
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 ENUMERATION
23
26
 
24
27
  # @return [Hash] symbol => value table
@@ -26,10 +29,16 @@ module SlowBlink::Message
26
29
  @symbols
27
30
  end
28
31
 
32
+ # @private
29
33
  def self.from_compact!(input, stack)
30
- value = input.getU32!
34
+ value = input.getI32!
31
35
  if value
32
- self.new(value)
36
+ symbol = @symbols.key(value)
37
+ if symbol
38
+ self.new(symbol)
39
+ else
40
+ raise WeakError10.new "W10: value '#{value}' does not correspond to any symbol in enumeration"
41
+ end
33
42
  else
34
43
  value
35
44
  end
@@ -56,9 +65,10 @@ module SlowBlink::Message
56
65
  @symbols = self.class.symbols
57
66
  set(value)
58
67
  end
59
-
68
+
69
+ # @private
60
70
  def to_compact(out)
61
- out.putU32(@symbols[@value])
71
+ out.putI32(@symbols[@value])
62
72
  end
63
73
 
64
74
  end
@@ -1,24 +1,27 @@
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 Field
23
26
 
24
27
  # @return [true,false] field is optional?
@@ -41,6 +44,7 @@ module SlowBlink::Message
41
44
  @type
42
45
  end
43
46
 
47
+ # @private
44
48
  # @param input [String] Blink compact form
45
49
  # @param stack [Array]
46
50
  # @return [Field] instance of anonymous subclass of Field
@@ -87,6 +91,7 @@ module SlowBlink::Message
87
91
  end
88
92
  end
89
93
 
94
+ # @private
90
95
  # @param out [String] output appended to this string
91
96
  # @return [String]
92
97
  def to_compact(out)
@@ -95,7 +100,7 @@ module SlowBlink::Message
95
100
  elsif @opt
96
101
  out.putNull
97
102
  else
98
- raise Error.new "field '#{self.name}' must not be null"
103
+ raise IncompleteGroup.new "field '#{self.name}' must not be null"
99
104
  end
100
105
  end
101
106
 
@@ -1,33 +1,36 @@
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 FIXED
23
26
 
24
27
  # @note optionality affects how instances of this type are encoded
25
- #
26
28
  # @return [true,false] is optional
27
29
  def self.opt?
28
30
  @opt
29
31
  end
30
-
32
+
33
+ # @private
31
34
  def self.from_compact!(input, stack)
32
35
  if @opt
33
36
  value = input.getFixedOptional!
@@ -73,6 +76,7 @@ module SlowBlink::Message
73
76
  set(value)
74
77
  end
75
78
 
79
+ # @private
76
80
  def to_compact(out)
77
81
  if @opt
78
82
  out.putFixedOptional(@value)
@@ -1,26 +1,30 @@
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 FLOATING_POINT
23
26
 
27
+ # @private
24
28
  def self.from_compact!(input, stack)
25
29
  value = input.getF64!
26
30
  if value
@@ -50,6 +54,7 @@ module SlowBlink::Message
50
54
  set(value)
51
55
  end
52
56
 
57
+ # @private
53
58
  def to_compact(out)
54
59
  out.putF64(@value)
55
60
  end