slow_blink 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/slow_blink/ext_compact_encoder/compact_encoder.c +258 -0
- data/ext/slow_blink/ext_compact_encoder/compact_encoder.h +92 -0
- data/ext/slow_blink/ext_compact_encoder/ext_compact_encoder.c +555 -0
- data/ext/slow_blink/ext_compact_encoder/extconf.rb +4 -0
- data/ext/slow_blink/ext_schema_parser/lexer.c +59 -59
- data/ext/slow_blink/ext_schema_parser/lexer.h +2 -2
- data/ext/slow_blink/ext_schema_parser/parser.c +380 -367
- data/ext/slow_blink/ext_schema_parser/parser.h +1 -1
- data/lib/slow_blink/annotatable.rb +1 -1
- data/lib/slow_blink/annotation.rb +5 -5
- data/lib/slow_blink/binary.rb +26 -0
- data/lib/slow_blink/boolean.rb +26 -0
- data/lib/slow_blink/compact_encoder.rb +45 -71
- data/lib/slow_blink/date.rb +25 -0
- data/lib/slow_blink/decimal.rb +26 -0
- data/lib/slow_blink/definition.rb +19 -10
- data/lib/slow_blink/enumeration.rb +14 -36
- data/lib/slow_blink/error.rb +19 -0
- data/lib/slow_blink/field.rb +3 -16
- data/lib/slow_blink/fixed.rb +26 -0
- data/lib/slow_blink/floating_point.rb +27 -0
- data/lib/slow_blink/group.rb +30 -43
- data/lib/slow_blink/incremental_annotation.rb +75 -21
- data/lib/slow_blink/integer.rb +65 -0
- data/lib/slow_blink/message/binary.rb +87 -0
- data/lib/slow_blink/message/boolean.rb +68 -0
- data/lib/slow_blink/message/date.rb +33 -0
- data/lib/slow_blink/message/decimal.rb +25 -0
- data/lib/slow_blink/message/enumeration.rb +69 -0
- data/lib/slow_blink/message/field.rb +73 -0
- data/lib/slow_blink/message/fixed.rb +84 -0
- data/lib/slow_blink/message/floating_point.rb +68 -0
- data/lib/slow_blink/message/group.rb +260 -0
- data/lib/slow_blink/message/integer.rb +217 -0
- data/lib/slow_blink/message/model.rb +202 -0
- data/lib/slow_blink/message/sequence.rb +85 -0
- data/lib/slow_blink/message/string.rb +95 -0
- data/lib/slow_blink/message/time.rb +78 -0
- data/lib/slow_blink/message/time_of_day.rb +132 -0
- data/lib/slow_blink/name_with_id.rb +2 -1
- data/lib/slow_blink/namespace.rb +140 -0
- data/lib/slow_blink/object.rb +29 -0
- data/lib/slow_blink/ref.rb +93 -0
- data/lib/slow_blink/schema.rb +94 -68
- data/lib/slow_blink/{component_reference.rb → schema_buffer.rb} +11 -22
- data/lib/slow_blink/sequence.rb +58 -0
- data/lib/slow_blink/string.rb +40 -0
- data/lib/slow_blink/sym.rb +4 -0
- data/lib/slow_blink/time.rb +30 -0
- data/lib/slow_blink/time_of_day.rb +30 -0
- data/lib/slow_blink/type.rb +7 -402
- data/lib/slow_blink/version.rb +1 -1
- data/lib/slow_blink.rb +1 -0
- data/rakefile +14 -3
- data/test/{integration/capture_stderr.rb → capture_stderr.rb} +0 -0
- data/test/tc_compact_encoder.rb +341 -0
- data/test/tc_field.rb +53 -0
- data/test/tc_group.rb +122 -0
- data/test/tc_incr_annote.rb +27 -0
- data/test/{integration/tc_inputs.rb → tc_inputs.rb} +7 -11
- data/test/tc_model.rb +65 -0
- data/test/tc_model_encode.rb +63 -0
- data/test/tc_namespace.rb +8 -0
- data/test/tc_types.rb +198 -0
- metadata +58 -11
- data/ext/slow_blink/ext_schema_parser/parser.l +0 -139
- data/ext/slow_blink/ext_schema_parser/parser.y +0 -932
- data/lib/slow_blink/message.rb +0 -43
@@ -0,0 +1,30 @@
|
|
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
|
21
|
+
|
22
|
+
# Blink Specification 3.11
|
23
|
+
class TIME_OF_DAY_MILLI < Type
|
24
|
+
end
|
25
|
+
|
26
|
+
# Blink Specification 3.11
|
27
|
+
class TIME_OF_DAY_NANO < Type
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/lib/slow_blink/type.rb
CHANGED
@@ -21,12 +21,15 @@ module SlowBlink
|
|
21
21
|
|
22
22
|
class Type
|
23
23
|
|
24
|
-
extend CompactEncoder
|
25
24
|
include Annotatable
|
26
25
|
|
27
26
|
# @param [String]
|
28
27
|
attr_reader :location
|
29
28
|
|
29
|
+
def self.===(other)
|
30
|
+
self == other
|
31
|
+
end
|
32
|
+
|
30
33
|
# @private
|
31
34
|
#
|
32
35
|
# @param location [String]
|
@@ -39,410 +42,12 @@ module SlowBlink
|
|
39
42
|
# @private
|
40
43
|
#
|
41
44
|
# @macro common_link
|
42
|
-
def link(schema, stack=[])
|
45
|
+
def link(schema, ns, stack=[])
|
43
46
|
@schema = schema
|
44
47
|
end
|
45
|
-
|
46
|
-
def ===(other)
|
47
|
-
self.class == other.class
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
# Blink Specification 3.2
|
53
|
-
class STRING < Type
|
54
|
-
|
55
|
-
# @return [Integer] maximum size
|
56
|
-
# @return [nil] no maximum size
|
57
|
-
attr_reader :size
|
58
|
-
|
59
|
-
# @private
|
60
|
-
#
|
61
|
-
# @param size [Integer] maximum size
|
62
|
-
# @param location [String]
|
63
|
-
def initialize(size, location)
|
64
|
-
@size = size
|
65
|
-
super(location)
|
66
|
-
end
|
67
|
-
|
68
|
-
# @private
|
69
|
-
def validate(value)
|
70
|
-
if @schema and value.kind_of? String and value.size < @size
|
71
|
-
true
|
72
|
-
else
|
73
|
-
raise
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# @private
|
78
|
-
def encode_compact(value)
|
79
|
-
putVLC(value.size) + value
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
# Blink Specification 3.4
|
85
|
-
class FIXED < STRING
|
86
|
-
# @private
|
87
|
-
def validate(value)
|
88
|
-
if @schema and value.kind_of? String and value.size == @size
|
89
|
-
true
|
90
|
-
else
|
91
|
-
raise
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
# @private
|
96
|
-
def encode_compact(value)
|
97
|
-
value
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
# Blink Specification 3.3
|
102
|
-
class BINARY < STRING
|
103
|
-
end
|
104
|
-
|
105
|
-
class INTEGER < Type
|
106
|
-
|
107
|
-
# @private
|
108
|
-
def validate(value)
|
109
|
-
if @schema and value.kind_of? Integer and self.class::RANGE.include? value
|
110
|
-
true
|
111
|
-
else
|
112
|
-
raise
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
# Blink Specification 3.1
|
119
|
-
class I8 < INTEGER
|
120
|
-
|
121
|
-
RANGE = Range.new(-128, 127)
|
122
|
-
|
123
|
-
# @private
|
124
|
-
def encode_compact(value)
|
125
|
-
putVLC(value, signed: true)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
# Blink Specification 3.1
|
130
|
-
class I16 < INTEGER
|
131
|
-
|
132
|
-
RANGE = Range.new(-32768, 32767)
|
133
|
-
|
134
|
-
# @private
|
135
|
-
def encode_compact(value)
|
136
|
-
putVLC(value, signed: true)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
# Blink Specification 3.1
|
141
|
-
class I32 < INTEGER
|
142
|
-
|
143
|
-
RANGE = Range.new(-2147483648, 2147483647)
|
144
|
-
|
145
|
-
# @private
|
146
|
-
def encode_compact(value)
|
147
|
-
putVLC(value, signed: true)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
# Blink Specification 3.1
|
152
|
-
class I64 < INTEGER
|
153
|
-
|
154
|
-
RANGE = Range.new(-9223372036854775808, 9223372036854775807)
|
155
|
-
|
156
|
-
# @private
|
157
|
-
def encode_compact(value)
|
158
|
-
putVLC(value, signed: true)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
# Blink Specification 3.1
|
163
|
-
class U8 < INTEGER
|
164
|
-
|
165
|
-
RANGE = Range.new(0, 0xff)
|
166
|
-
|
167
|
-
# @private
|
168
|
-
def encode_compact(value)
|
169
|
-
putVLC(value)
|
170
|
-
end
|
48
|
+
|
171
49
|
end
|
172
|
-
|
173
|
-
# Blink Specification 3.1
|
174
|
-
class U16 < INTEGER
|
175
|
-
|
176
|
-
RANGE = Range.new(0, 0xffff)
|
177
|
-
|
178
|
-
# @private
|
179
|
-
def encode_compact(value)
|
180
|
-
putVLC(value)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
# Blink Specification 3.1
|
185
|
-
class U32 < INTEGER
|
186
|
-
|
187
|
-
RANGE = Range.new(0, 0xffffffff)
|
188
|
-
|
189
|
-
# @private
|
190
|
-
def encode_compact(value)
|
191
|
-
putVLC(value)
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
# Blink Specification 3.1
|
196
|
-
class U64 < INTEGER
|
197
|
-
|
198
|
-
RANGE = Range.new(0, 0xffffffffffffffff)
|
199
|
-
|
200
|
-
# @private
|
201
|
-
def encode_compact(value)
|
202
|
-
putVLC(value)
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
# Blink Specification 3.1
|
207
|
-
class F64 < INTEGER
|
208
|
-
|
209
|
-
# @private
|
210
|
-
def encode_compact(value)
|
211
|
-
putF64(value)
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
# Blink Specification 3.6
|
216
|
-
class BOOLEAN < Type
|
217
|
-
|
218
|
-
# @private
|
219
|
-
def encode_compact(value)
|
220
|
-
putBool(value)
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
# Blink Specification 3.7
|
225
|
-
class DECIMAL < Type
|
226
|
-
end
|
227
|
-
|
228
|
-
# Blink Specification 3.10
|
229
|
-
class DATE < Type
|
230
|
-
end
|
231
|
-
|
232
|
-
# Blink Specification 3.9
|
233
|
-
class NANO_TIME < Type
|
234
|
-
|
235
|
-
# @private
|
236
|
-
def validate(value)
|
237
|
-
if value.kind_of? Time or value.kind_of? Integer
|
238
|
-
true
|
239
|
-
else
|
240
|
-
raise
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
end
|
245
|
-
|
246
|
-
# Blink Specification 3.9
|
247
|
-
class MILLI_TIME < Type
|
248
|
-
|
249
|
-
# @private
|
250
|
-
def validate(value)
|
251
|
-
if value.kind_of? Time or value.kind_of? Integer
|
252
|
-
true
|
253
|
-
else
|
254
|
-
raise
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
end
|
259
|
-
|
260
|
-
# Blink Specification 3.11
|
261
|
-
class TIME_OF_DAY_NANO < Type
|
262
|
-
|
263
|
-
# @private
|
264
|
-
def validate(value)
|
265
|
-
if value.kind_of? Time
|
266
|
-
true
|
267
|
-
elsif value.kind_of? Integer and value <= 86400000000000
|
268
|
-
true
|
269
|
-
else
|
270
|
-
raise
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
end
|
275
|
-
|
276
|
-
# Blink Specification 3.11
|
277
|
-
class TIME_OF_DAY_MILLI < Type
|
278
|
-
|
279
|
-
# @private
|
280
|
-
def validate(value)
|
281
|
-
if value.kind_of? Time
|
282
|
-
true
|
283
|
-
elsif value.kind_of? Integer and value <= 86400000
|
284
|
-
true
|
285
|
-
else
|
286
|
-
raise
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
end
|
291
|
-
|
292
|
-
# Blink Specification 3.12
|
293
|
-
class SEQUENCE < Type
|
294
|
-
|
295
|
-
# @return [Type]
|
296
|
-
attr_reader :type
|
297
|
-
|
298
|
-
# @private
|
299
|
-
#
|
300
|
-
# @param type [Type] repeating type
|
301
|
-
# @param location [String]
|
302
|
-
def initialize(type, location)
|
303
|
-
@type = nil
|
304
|
-
@rawType = type
|
305
|
-
super(location)
|
306
|
-
end
|
307
|
-
|
308
|
-
# @private
|
309
|
-
#
|
310
|
-
# @macro common_link
|
311
|
-
def link(schema, stack=[])
|
312
|
-
if @schema != schema
|
313
|
-
@schema = nil
|
314
|
-
case @rawType.class
|
315
|
-
when REF
|
316
|
-
schema.symbol(@rawType)
|
317
|
-
when SEQUENCE
|
318
|
-
puts "error: sequence of sequence is not permitted"
|
319
|
-
else
|
320
|
-
@type = @rawType
|
321
|
-
@schema = schema
|
322
|
-
end
|
323
|
-
end
|
324
|
-
@schema
|
325
|
-
end
|
326
|
-
|
327
|
-
# @private
|
328
|
-
def validate(value)
|
329
|
-
if @schema and value.kind_of? Array
|
330
|
-
value.each do |v|
|
331
|
-
@type.validate(v)
|
332
|
-
end
|
333
|
-
else
|
334
|
-
raise
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
|
-
# @private
|
339
|
-
def encode_compact(value)
|
340
|
-
out = putVLC(value.size)
|
341
|
-
value.each do |v|
|
342
|
-
out << @type.encode_compact(v)
|
343
|
-
end
|
344
|
-
out
|
345
|
-
end
|
346
|
-
|
347
|
-
end
|
348
|
-
|
349
|
-
class REF < Type
|
350
|
-
|
351
|
-
# @return [true] dynamic reference
|
352
|
-
# @return [false] static reference
|
353
|
-
def dynamic?
|
354
|
-
@dynamic
|
355
|
-
end
|
356
|
-
|
357
|
-
# @private
|
358
|
-
#
|
359
|
-
# @param ref [String]
|
360
|
-
# @param dynamic [true,false]
|
361
|
-
# @param location [String]
|
362
|
-
def initialize(ref, dynamic, location)
|
363
|
-
@ref = ref
|
364
|
-
@dynamic = dynamic
|
365
|
-
@object = nil
|
366
|
-
super(location)
|
367
|
-
end
|
368
|
-
|
369
|
-
def value
|
370
|
-
if @schema
|
371
|
-
@object
|
372
|
-
else
|
373
|
-
raise "must be linked"
|
374
|
-
end
|
375
|
-
end
|
376
|
-
|
377
|
-
# @private
|
378
|
-
#
|
379
|
-
# @macro common_link
|
380
|
-
def link(schema, stack=[])
|
381
|
-
if @schema != schema
|
382
|
-
@schema = nil
|
383
|
-
ref = @ref
|
384
|
-
object = schema.symbol(ref)
|
385
|
-
if object and object.link(schema, stack << self)
|
386
|
-
# walk through all references until object
|
387
|
-
# refers to an actual type
|
388
|
-
loop do
|
389
|
-
if object.is_a? REF
|
390
|
-
object = object.object
|
391
|
-
else
|
392
|
-
break
|
393
|
-
end
|
394
|
-
end
|
395
|
-
if @dynamic and @object.class != Group
|
396
|
-
puts "#{@location}: error: '#{@ref} *' must resolve to a Group"
|
397
|
-
else
|
398
|
-
@object = object
|
399
|
-
@schema = schema
|
400
|
-
end
|
401
|
-
else
|
402
|
-
puts "#{@location}: error: '#{@ref}' is not defined in schema"
|
403
|
-
end
|
404
|
-
end
|
405
|
-
@schema
|
406
|
-
end
|
407
|
-
|
408
|
-
# @private
|
409
|
-
def validate(value)
|
410
|
-
@object.validate(input)
|
411
|
-
end
|
412
|
-
|
413
|
-
# @private
|
414
|
-
def encode_compact(value)
|
415
|
-
@object.encode_compact(value, dynamic: @dynamic)
|
416
|
-
end
|
417
|
-
end
|
418
|
-
|
419
|
-
# any group
|
420
|
-
#
|
421
|
-
# Blink Specification 3.9
|
422
|
-
class OBJECT < Type
|
423
|
-
|
424
|
-
# @private
|
425
|
-
def validate(value)
|
426
|
-
if value.kind_of? Hash and value["$type"]
|
427
|
-
|
428
|
-
group = @schema.group(value["$type"])
|
429
|
-
if group
|
430
|
-
group.validate(value)
|
431
|
-
else
|
432
|
-
raise
|
433
|
-
end
|
434
|
-
|
435
|
-
else
|
436
|
-
raise
|
437
|
-
end
|
438
|
-
end
|
439
|
-
|
440
|
-
# @private
|
441
|
-
def encode_compact(value, **opts)
|
442
|
-
@object.encode_compact(value, dynamic: true)
|
443
|
-
end
|
444
|
-
end
|
445
|
-
|
50
|
+
|
446
51
|
end
|
447
52
|
|
448
53
|
|
data/lib/slow_blink/version.rb
CHANGED
data/lib/slow_blink.rb
CHANGED
data/rakefile
CHANGED
@@ -2,6 +2,7 @@ require 'rake/testtask'
|
|
2
2
|
require 'rake/extensiontask'
|
3
3
|
|
4
4
|
DIR_SRC = "ext/slow_blink/ext_schema_parser"
|
5
|
+
DIR_ETC = "etc/slow_blink/ext_schema_parser"
|
5
6
|
|
6
7
|
Rake::ExtensionTask.new do |ext|
|
7
8
|
ext.name = "ext_schema_parser"
|
@@ -9,21 +10,31 @@ Rake::ExtensionTask.new do |ext|
|
|
9
10
|
ext.lib_dir = "lib/slow_blink"
|
10
11
|
end
|
11
12
|
|
13
|
+
Rake::ExtensionTask.new do |ext|
|
14
|
+
ext.name = "ext_compact_encoder"
|
15
|
+
ext.ext_dir = "ext/slow_blink/ext_compact_encoder"
|
16
|
+
ext.lib_dir = "lib/slow_blink"
|
17
|
+
end
|
18
|
+
|
12
19
|
desc "parser tests"
|
13
20
|
Rake::TestTask.new do |t|
|
14
21
|
t.name = :test
|
15
22
|
t.libs << "lib"
|
16
|
-
t.test_files = FileList["test
|
23
|
+
t.test_files = FileList["test/**/tc_*.rb"]
|
17
24
|
end
|
18
25
|
|
19
26
|
desc "run flex-bison"
|
20
27
|
task :flexbison do
|
21
|
-
system "flex --outfile=#{DIR_SRC}/lexer.c --header-file=#{DIR_SRC}/lexer.h #{
|
22
|
-
system "bison -d #{
|
28
|
+
system "flex --outfile=#{DIR_SRC}/lexer.c --header-file=#{DIR_SRC}/lexer.h #{DIR_ETC}/parser.l"
|
29
|
+
system "bison -d #{DIR_ETC}/parser.y --output=#{DIR_SRC}/parser.c --report=all --report-file=#{DIR_SRC}/report.txt"
|
23
30
|
end
|
24
31
|
|
25
32
|
task :local => [:flexbison, :compile, :test] do
|
26
33
|
end
|
27
34
|
|
35
|
+
task :benchmark do
|
36
|
+
system "ruby -Ilib -- bench/think_blink_example.rb"
|
37
|
+
end
|
38
|
+
|
28
39
|
task :default => :test
|
29
40
|
|
File without changes
|