slow_blink 0.0.2 → 0.0.3

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 (69) hide show
  1. checksums.yaml +4 -4
  2. data/ext/slow_blink/ext_compact_encoder/compact_encoder.c +258 -0
  3. data/ext/slow_blink/ext_compact_encoder/compact_encoder.h +92 -0
  4. data/ext/slow_blink/ext_compact_encoder/ext_compact_encoder.c +555 -0
  5. data/ext/slow_blink/ext_compact_encoder/extconf.rb +4 -0
  6. data/ext/slow_blink/ext_schema_parser/lexer.c +59 -59
  7. data/ext/slow_blink/ext_schema_parser/lexer.h +2 -2
  8. data/ext/slow_blink/ext_schema_parser/parser.c +380 -367
  9. data/ext/slow_blink/ext_schema_parser/parser.h +1 -1
  10. data/lib/slow_blink/annotatable.rb +1 -1
  11. data/lib/slow_blink/annotation.rb +5 -5
  12. data/lib/slow_blink/binary.rb +26 -0
  13. data/lib/slow_blink/boolean.rb +26 -0
  14. data/lib/slow_blink/compact_encoder.rb +45 -71
  15. data/lib/slow_blink/date.rb +25 -0
  16. data/lib/slow_blink/decimal.rb +26 -0
  17. data/lib/slow_blink/definition.rb +19 -10
  18. data/lib/slow_blink/enumeration.rb +14 -36
  19. data/lib/slow_blink/error.rb +19 -0
  20. data/lib/slow_blink/field.rb +3 -16
  21. data/lib/slow_blink/fixed.rb +26 -0
  22. data/lib/slow_blink/floating_point.rb +27 -0
  23. data/lib/slow_blink/group.rb +30 -43
  24. data/lib/slow_blink/incremental_annotation.rb +75 -21
  25. data/lib/slow_blink/integer.rb +65 -0
  26. data/lib/slow_blink/message/binary.rb +87 -0
  27. data/lib/slow_blink/message/boolean.rb +68 -0
  28. data/lib/slow_blink/message/date.rb +33 -0
  29. data/lib/slow_blink/message/decimal.rb +25 -0
  30. data/lib/slow_blink/message/enumeration.rb +69 -0
  31. data/lib/slow_blink/message/field.rb +73 -0
  32. data/lib/slow_blink/message/fixed.rb +84 -0
  33. data/lib/slow_blink/message/floating_point.rb +68 -0
  34. data/lib/slow_blink/message/group.rb +260 -0
  35. data/lib/slow_blink/message/integer.rb +217 -0
  36. data/lib/slow_blink/message/model.rb +202 -0
  37. data/lib/slow_blink/message/sequence.rb +85 -0
  38. data/lib/slow_blink/message/string.rb +95 -0
  39. data/lib/slow_blink/message/time.rb +78 -0
  40. data/lib/slow_blink/message/time_of_day.rb +132 -0
  41. data/lib/slow_blink/name_with_id.rb +2 -1
  42. data/lib/slow_blink/namespace.rb +140 -0
  43. data/lib/slow_blink/object.rb +29 -0
  44. data/lib/slow_blink/ref.rb +93 -0
  45. data/lib/slow_blink/schema.rb +94 -68
  46. data/lib/slow_blink/{component_reference.rb → schema_buffer.rb} +11 -22
  47. data/lib/slow_blink/sequence.rb +58 -0
  48. data/lib/slow_blink/string.rb +40 -0
  49. data/lib/slow_blink/sym.rb +4 -0
  50. data/lib/slow_blink/time.rb +30 -0
  51. data/lib/slow_blink/time_of_day.rb +30 -0
  52. data/lib/slow_blink/type.rb +7 -402
  53. data/lib/slow_blink/version.rb +1 -1
  54. data/lib/slow_blink.rb +1 -0
  55. data/rakefile +14 -3
  56. data/test/{integration/capture_stderr.rb → capture_stderr.rb} +0 -0
  57. data/test/tc_compact_encoder.rb +341 -0
  58. data/test/tc_field.rb +53 -0
  59. data/test/tc_group.rb +122 -0
  60. data/test/tc_incr_annote.rb +27 -0
  61. data/test/{integration/tc_inputs.rb → tc_inputs.rb} +7 -11
  62. data/test/tc_model.rb +65 -0
  63. data/test/tc_model_encode.rb +63 -0
  64. data/test/tc_namespace.rb +8 -0
  65. data/test/tc_types.rb +198 -0
  66. metadata +58 -11
  67. data/ext/slow_blink/ext_schema_parser/parser.l +0 -139
  68. data/ext/slow_blink/ext_schema_parser/parser.y +0 -932
  69. data/lib/slow_blink/message.rb +0 -43
@@ -0,0 +1,68 @@
1
+ # Copyright (c) 2016 Cameron Harper
2
+ #
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
+
20
+ module SlowBlink::Message
21
+
22
+ module FLOATING_POINT
23
+
24
+ module CLASS
25
+
26
+ def from_compact!(input)
27
+ self.new(input.getF64!)
28
+ end
29
+
30
+ end
31
+
32
+ module INSTANCE
33
+
34
+ def set(value)
35
+ if value
36
+ if value.kind_of? Numeric
37
+ @value = value
38
+ else
39
+ raise "expecting float"
40
+ end
41
+ elsif self.class.opt?
42
+ @value = nil
43
+ else
44
+ raise Error.new "value unacceptable"
45
+ end
46
+ end
47
+
48
+ def get
49
+ @value
50
+ end
51
+
52
+ def initialize(value)
53
+ if value
54
+ set(value)
55
+ else
56
+ @value = nil
57
+ end
58
+ end
59
+
60
+ def to_compact(out)
61
+ out.putF64(@value)
62
+ end
63
+
64
+ end
65
+
66
+ end
67
+
68
+ end
@@ -0,0 +1,260 @@
1
+ # Copyright (c) 2016 Cameron Harper
2
+ #
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
+
20
+ module SlowBlink::Message
21
+
22
+ TYPE_KEY = "$type".freeze
23
+
24
+ module StaticGroup
25
+
26
+ module CLASS
27
+
28
+ def fields
29
+ @fields
30
+ end
31
+
32
+ def opt?
33
+ @opt
34
+ end
35
+
36
+ def id
37
+ @id
38
+ end
39
+
40
+ def name
41
+ @name
42
+ end
43
+
44
+ def from_compact!(input)
45
+ if @opt
46
+ if input.getPresent!
47
+ fields = {}
48
+ @fields.each do |f|
49
+ fields[f.name] = f.from_compact!(input)
50
+ end
51
+ self.new(fields)
52
+ else
53
+ self.new(nil)
54
+ end
55
+ else
56
+ fields = {}
57
+ @fields.each do |f|
58
+ fields[f.name] = f.from_compact!(input)
59
+ end
60
+ self.new(fields)
61
+ end
62
+ end
63
+
64
+ end
65
+
66
+ module INSTANCE
67
+
68
+ def []=(name, value)
69
+ if @value[name]
70
+ @value[name].set(value)
71
+ else
72
+ raise "field #{name} is not defined in this group"
73
+ end
74
+ end
75
+
76
+ def [](name)
77
+ if @value[name]
78
+ @value[name].get
79
+ else
80
+ raise "field #{name} is not defined in this group"
81
+ end
82
+ end
83
+
84
+ def set(value)
85
+ if value
86
+ @value = {}
87
+ self.class.fields.each do |f|
88
+ @value[f.name] = value[f.name]
89
+ end
90
+ elsif self.class.opt?
91
+ @value = nil
92
+ else
93
+ raise "this group cannot be NULL"
94
+ end
95
+ end
96
+
97
+ def get
98
+ @value
99
+ end
100
+
101
+ def initialize(fields)
102
+ if fields
103
+ set(fields)
104
+ else
105
+ @value = {}
106
+ self.class.fields.each do |f|
107
+ @value[f.name] = f.new(nil)
108
+ end
109
+ end
110
+ end
111
+
112
+ def fields
113
+ @value
114
+ end
115
+
116
+ def to_compact(out)
117
+ if @value
118
+ if self.class.opt?
119
+ out.putPresent
120
+ self.class.fields.each do |f|
121
+ @value[f.name].to_compact(out)
122
+ end
123
+ out
124
+ else
125
+ self.class.fields.each do |f|
126
+ @value[f.name].to_compact(out)
127
+ end
128
+ out
129
+ end
130
+ else
131
+ out.putPresent(false)
132
+ end
133
+ end
134
+
135
+ end
136
+
137
+ end
138
+
139
+ module DynamicGroup
140
+
141
+ module CLASS
142
+
143
+ def groups
144
+ @groups
145
+ end
146
+
147
+ def permitted
148
+ @permitted
149
+ end
150
+
151
+ def opt?
152
+ @opt
153
+ end
154
+
155
+ def from_compact!(input)
156
+ buf = input.getBinary!
157
+ if buf.size > 0
158
+ id = buf.getU64!
159
+ group = @groups[id]
160
+ if group
161
+ if @permitted.include? group.id
162
+ self.new(group.from_compact!(buf))
163
+ else
164
+ raise Error.new "W15: Group is known but unexpected"
165
+ end
166
+ else
167
+ raise Error.new "W2: Group id #{group.id} is unknown"
168
+ end
169
+ else
170
+ if self == ModelInstance
171
+ raise Error.new "W1: Top level group cannot be null"
172
+ elsif @opt
173
+ self.new(nil)
174
+ else
175
+ raise Error.new "W5: Value cannot be null"
176
+ end
177
+ end
178
+ end
179
+
180
+ end
181
+
182
+ module INSTANCE
183
+
184
+ def []=(name, value)
185
+ if @value
186
+ @value[name] = value
187
+ else
188
+ raise "undefined dynamic group"
189
+ end
190
+ end
191
+
192
+ def [](name)
193
+ if @value
194
+ @value[name]
195
+ else
196
+ raise "undefined dynamic group"
197
+ end
198
+ end
199
+
200
+ def extension(&group)
201
+ # define extension
202
+ # this is an array of OBJECTs
203
+ # extension do
204
+ # group "name" do |g|
205
+ # g["field"] = "value"
206
+ # end
207
+ # group "name" do |g|
208
+ # g["field"] = "value"
209
+ # end
210
+ # ...
211
+ # end
212
+ #
213
+ raise
214
+ end
215
+
216
+ def set(value)
217
+ if value
218
+ if self.class.groups.values.include? value.class
219
+ if self.class.permitted.include? value.class.id
220
+ @value = value
221
+ else
222
+ raise "group is not a permitted group"
223
+ end
224
+ else
225
+ raise "value is not a group instance"
226
+ end
227
+ elsif self.class.opt?
228
+ @value = nil
229
+ else
230
+ raise
231
+ end
232
+ end
233
+
234
+ def get
235
+ @value
236
+ end
237
+
238
+ def initialize(value)
239
+ if value
240
+ set(value)
241
+ else
242
+ @value = nil
243
+ end
244
+ end
245
+
246
+ def to_compact(out="")
247
+ if @value
248
+ group = @value.to_compact("".putU64(@value.class.id))
249
+ out.putU32(group.size)
250
+ out << group
251
+ else
252
+ out.putU32(nil)
253
+ end
254
+ end
255
+
256
+ end
257
+
258
+ end
259
+
260
+ end
@@ -0,0 +1,217 @@
1
+ # Copyright (c) 2016 Cameron Harper
2
+ #
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
+
20
+ module SlowBlink::Message
21
+
22
+ module INTEGER
23
+
24
+ module CLASS
25
+
26
+ def name
27
+ @name
28
+ end
29
+
30
+ def opt?
31
+ @opt
32
+ end
33
+
34
+ def in_range?(value)
35
+ @type.class::RANGE.cover? value
36
+ end
37
+
38
+ end
39
+
40
+ module INSTANCE
41
+
42
+ def set(value)
43
+ if value
44
+ if value.kind_of? Integer
45
+ if self.class.in_range?(value)
46
+ @value = value.to_i
47
+ else
48
+ raise Error.new "value out of range"
49
+ end
50
+ else
51
+ raise Error.new "value must be an integer"
52
+ end
53
+ elsif self.class.opt?
54
+ @value = nil
55
+ else
56
+ raise Error.new "value unacceptable"
57
+ end
58
+ end
59
+
60
+ def get
61
+ @value
62
+ end
63
+
64
+ # @param value [Integer, nil]
65
+ def initialize(value)
66
+ if value
67
+ set(value)
68
+ else
69
+ @value = nil
70
+ end
71
+ end
72
+ end
73
+
74
+ end
75
+
76
+ module U8
77
+
78
+ module CLASS
79
+ include SlowBlink::Message::INTEGER::CLASS
80
+ def from_compact!(input)
81
+ self.new(input.getU8!)
82
+ end
83
+ end
84
+
85
+ module INSTANCE
86
+ include SlowBlink::Message::INTEGER::INSTANCE
87
+ def to_compact(out)
88
+ out.putU8(@value)
89
+ end
90
+ end
91
+
92
+ end
93
+
94
+ module U16
95
+
96
+ module CLASS
97
+ include SlowBlink::Message::INTEGER::CLASS
98
+ def from_compact!(input)
99
+ self.new(input.getU16!)
100
+ end
101
+ end
102
+
103
+ module INSTANCE
104
+ include SlowBlink::Message::INTEGER::INSTANCE
105
+ def to_compact(out)
106
+ out.putU16(@value)
107
+ end
108
+ end
109
+ end
110
+
111
+ module U32
112
+
113
+ module CLASS
114
+ include SlowBlink::Message::INTEGER::CLASS
115
+ def from_compact!(input)
116
+ self.new(input.getU32!)
117
+ end
118
+ end
119
+
120
+ module INSTANCE
121
+ include SlowBlink::Message::INTEGER::INSTANCE
122
+ def to_compact(out)
123
+ out.putU32(@value)
124
+ end
125
+ end
126
+
127
+ end
128
+
129
+ module U64
130
+
131
+ module CLASS
132
+ include SlowBlink::Message::INTEGER::CLASS
133
+ def from_compact!(input)
134
+ self.new(input.getU64!)
135
+ end
136
+ end
137
+
138
+ module INSTANCE
139
+ include SlowBlink::Message::INTEGER::INSTANCE
140
+ def to_compact(out)
141
+ out.putU64(@value)
142
+ end
143
+ end
144
+
145
+ end
146
+
147
+ module I8
148
+
149
+ module CLASS
150
+ include SlowBlink::Message::INTEGER::CLASS
151
+ def from_compact!(input)
152
+ self.new(input.getI8!)
153
+ end
154
+ end
155
+
156
+ module INSTANCE
157
+ include SlowBlink::Message::INTEGER::INSTANCE
158
+ def to_compact(out)
159
+ out.putI8(@value)
160
+ end
161
+ end
162
+
163
+ end
164
+
165
+ module I16
166
+ module CLASS
167
+ include SlowBlink::Message::INTEGER::CLASS
168
+ def from_compact!(input)
169
+ self.new(input.getI16!)
170
+ end
171
+ end
172
+
173
+ module INSTANCE
174
+ include SlowBlink::Message::INTEGER::INSTANCE
175
+ def to_compact(out)
176
+ out.putI16(@value)
177
+ end
178
+ end
179
+
180
+ end
181
+
182
+ module I32
183
+
184
+ module CLASS
185
+ include SlowBlink::Message::INTEGER::CLASS
186
+ def from_compact!(input)
187
+ self.new(input.getI32!)
188
+ end
189
+ end
190
+
191
+ module INSTANCE
192
+ include INTEGER::INSTANCE
193
+ def to_compact(out)
194
+ out.putI32(@value)
195
+ end
196
+ end
197
+
198
+ end
199
+
200
+ module I64
201
+
202
+ module CLASS
203
+ include SlowBlink::Message::INTEGER::CLASS
204
+ def from_compact!(input)
205
+ self.new(input.getI64!)
206
+ end
207
+ end
208
+
209
+ module INSTANCE
210
+ include SlowBlink::Message::INTEGER::INSTANCE
211
+ def to_compact(out)
212
+ out.putI64(@value)
213
+ end
214
+ end
215
+ end
216
+
217
+ end