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.
- 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
@@ -22,15 +22,15 @@ module SlowBlink
|
|
22
22
|
|
23
23
|
attr_reader :location
|
24
24
|
attr_reader :id
|
25
|
-
attr_reader :
|
25
|
+
attr_reader :value
|
26
26
|
|
27
27
|
# @param id [String] any string
|
28
|
-
# @param
|
28
|
+
# @param value [String] any string
|
29
29
|
# @param location [String]
|
30
|
-
def initialize(id,
|
30
|
+
def initialize(id,value,location)
|
31
31
|
@id = id
|
32
|
-
@
|
33
|
-
@location =
|
32
|
+
@value = value
|
33
|
+
@location = value
|
34
34
|
end
|
35
35
|
|
36
36
|
end
|
@@ -0,0 +1,26 @@
|
|
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.3
|
23
|
+
class BINARY < STRING
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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.6
|
23
|
+
class BOOLEAN < Type
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -17,81 +17,55 @@
|
|
17
17
|
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
18
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
19
|
|
20
|
-
# SlowBlink
|
21
20
|
module SlowBlink
|
22
21
|
|
23
22
|
module CompactEncoder
|
24
23
|
|
25
|
-
#
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
# @return [String]
|
31
|
-
def self.putPresent
|
32
|
-
"\x01"
|
33
|
-
end
|
24
|
+
# @!method getU8(input)
|
25
|
+
# @param input [String]
|
26
|
+
# @return [nil, Integer]
|
27
|
+
# @raise [Error]
|
34
28
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
#
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
# @private
|
76
|
-
#
|
77
|
-
# @param value [Integer] signed or unsigned integer
|
78
|
-
# @param opts [Hash] option
|
79
|
-
# @option opts [Symbol] :signed value is a signed integer
|
80
|
-
def self.putVLC(value, **opts)
|
81
|
-
bytes = opts[:signed] ? getSizeSigned(value) : getSizeUnsigned(value)
|
82
|
-
case bytes
|
83
|
-
when 1
|
84
|
-
[value].pack("C")
|
85
|
-
when 2
|
86
|
-
[0x80 | value].pack("S<")
|
87
|
-
else
|
88
|
-
out = [0xc0 | bytes]
|
89
|
-
while out.size < (bytes - 1) do
|
90
|
-
out << (value >> 8)
|
91
|
-
end
|
92
|
-
out.pack("S<C#{bytes-2}")
|
93
|
-
end
|
94
|
-
end
|
29
|
+
# @!method getU16(input)
|
30
|
+
# @param input [String]
|
31
|
+
# @return [nil, Integer]
|
32
|
+
# @raise [Error]
|
33
|
+
|
34
|
+
# @!method getU32(input)
|
35
|
+
# @param input [String]
|
36
|
+
# @return [nil, Integer]
|
37
|
+
# @raise [Error]
|
38
|
+
|
39
|
+
# @!method getU64(input)
|
40
|
+
# @param input [String]
|
41
|
+
# @return [nil, Integer]
|
42
|
+
# @raise [Error]
|
43
|
+
|
44
|
+
# @!method getI8(input)
|
45
|
+
# @param input [String]
|
46
|
+
# @return [nil, Integer]
|
47
|
+
# @raise [Error]
|
48
|
+
|
49
|
+
# @!method getI16(input)
|
50
|
+
# @param input [String]
|
51
|
+
# @return [nil, Integer]
|
52
|
+
# @raise [Error]
|
53
|
+
|
54
|
+
# @!method getI32(input)
|
55
|
+
# @param input [String]
|
56
|
+
# @return [nil, Integer]
|
57
|
+
# @raise [Error]
|
58
|
+
|
59
|
+
# @!method getI64(input)
|
60
|
+
# @param input [String]
|
61
|
+
# @return [nil, Integer]
|
62
|
+
# @raise [Error]
|
63
|
+
|
64
|
+
# @!method getF64(input)
|
65
|
+
# @param input [String]
|
66
|
+
# @return [nil, Integer]
|
67
|
+
# @raise [Error]
|
68
|
+
|
95
69
|
end
|
96
|
-
|
70
|
+
|
97
71
|
end
|
@@ -0,0 +1,25 @@
|
|
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
|
+
class DATE < Type
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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.7
|
23
|
+
class DECIMAL < Type
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -21,7 +21,10 @@ module SlowBlink
|
|
21
21
|
class Definition
|
22
22
|
|
23
23
|
include Annotatable
|
24
|
-
|
24
|
+
|
25
|
+
def self.===(other)
|
26
|
+
self == other
|
27
|
+
end
|
25
28
|
|
26
29
|
# @return [String]
|
27
30
|
attr_reader :location
|
@@ -29,28 +32,34 @@ module SlowBlink
|
|
29
32
|
# @return [String]
|
30
33
|
attr_reader :nameWithID
|
31
34
|
|
32
|
-
# @return [
|
35
|
+
# @return [ENUMERATION]
|
33
36
|
# @return [Type]
|
34
|
-
attr_reader :
|
37
|
+
attr_reader :type
|
38
|
+
|
39
|
+
# @param namespace [Namespace]
|
40
|
+
def namespace=(namespace)
|
41
|
+
@ns = namespace
|
42
|
+
end
|
35
43
|
|
36
44
|
# @private
|
37
45
|
#
|
38
46
|
# @param nameWithID [NameWithID]
|
39
|
-
# @param
|
47
|
+
# @param type [ENUMERATION, Type]
|
40
48
|
# @param location [String]
|
41
|
-
def initialize(nameWithID,
|
49
|
+
def initialize(nameWithID, type, location)
|
42
50
|
@annotes = {}
|
43
51
|
@schema = nil
|
44
|
-
@
|
52
|
+
@type = type
|
45
53
|
@location = location
|
46
54
|
@nameWithID = nameWithID
|
55
|
+
@ns = nil
|
47
56
|
end
|
48
57
|
|
49
|
-
# @private
|
50
|
-
#
|
51
|
-
# @!macro common_link
|
52
58
|
def link(schema, stack=[])
|
53
|
-
@schema
|
59
|
+
if @schema.nil?
|
60
|
+
@schema = @type.link(schema, @ns, stack << self)
|
61
|
+
end
|
62
|
+
@schema
|
54
63
|
end
|
55
64
|
|
56
65
|
end
|
@@ -19,10 +19,13 @@
|
|
19
19
|
|
20
20
|
module SlowBlink
|
21
21
|
|
22
|
-
class
|
22
|
+
class ENUMERATION
|
23
23
|
|
24
24
|
include Annotatable
|
25
|
-
|
25
|
+
|
26
|
+
def self.===(other)
|
27
|
+
self == other
|
28
|
+
end
|
26
29
|
|
27
30
|
# @private
|
28
31
|
#
|
@@ -34,22 +37,14 @@ module SlowBlink
|
|
34
37
|
@schema = nil
|
35
38
|
end
|
36
39
|
|
37
|
-
def
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
# @private
|
42
|
-
#
|
43
|
-
# @macro common_link
|
44
|
-
def link(schema, stack=[])
|
45
|
-
if @schema != schema
|
46
|
-
@schema = nil
|
40
|
+
def link(schema, ns, stack=[])
|
41
|
+
if @schema.nil?
|
47
42
|
value = 0
|
48
43
|
errors = 0
|
49
44
|
@syms = {}
|
50
45
|
@rawSyms.each do |s|
|
51
46
|
if @syms[s.name]
|
52
|
-
puts "#{s.location}: error: duplicate name"
|
47
|
+
puts "#{s.location}: error: duplicate name '#{s.name}' (first defined at #{@syms[s.name].location})"
|
53
48
|
errors += 1
|
54
49
|
else
|
55
50
|
if s.val
|
@@ -60,9 +55,10 @@ module SlowBlink
|
|
60
55
|
value = s.val + 1
|
61
56
|
end
|
62
57
|
else
|
63
|
-
|
58
|
+
s.val = value
|
64
59
|
value += 1
|
65
60
|
end
|
61
|
+
@syms[s.name] = s
|
66
62
|
end
|
67
63
|
end
|
68
64
|
if errors == 0
|
@@ -75,29 +71,11 @@ module SlowBlink
|
|
75
71
|
# @param nameOrVal [String,Integer]
|
76
72
|
# @return [Sym]
|
77
73
|
# @return [nil]
|
78
|
-
def
|
79
|
-
if
|
80
|
-
@syms[
|
81
|
-
else
|
82
|
-
@syms.detect{|s|s.val == s.to_i}
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
# @private
|
87
|
-
def validate(input)
|
88
|
-
if sym(input)
|
89
|
-
true
|
90
|
-
else
|
91
|
-
raise
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
# @private
|
96
|
-
def encode_compact(value, **opts)
|
97
|
-
if opts[:opt]
|
98
|
-
putPresent + putVLC(value)
|
74
|
+
def symbol(nameOrVal)
|
75
|
+
if nameOrVal.kind_of? String
|
76
|
+
@syms[nameOrVal]
|
99
77
|
else
|
100
|
-
|
78
|
+
@syms.values.detect{|s|s.val == nameOrVal.to_i}
|
101
79
|
end
|
102
80
|
end
|
103
81
|
|
data/lib/slow_blink/error.rb
CHANGED
@@ -1,3 +1,22 @@
|
|
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
|
+
|
1
20
|
module SlowBlink
|
2
21
|
class Error < Exception
|
3
22
|
end
|
data/lib/slow_blink/field.rb
CHANGED
@@ -22,7 +22,6 @@ module SlowBlink
|
|
22
22
|
class Field
|
23
23
|
|
24
24
|
include Annotatable
|
25
|
-
extend CompactEncoder
|
26
25
|
|
27
26
|
# @return [String]
|
28
27
|
attr_reader :location
|
@@ -57,26 +56,14 @@ module SlowBlink
|
|
57
56
|
# @private
|
58
57
|
#
|
59
58
|
# @!macro common_link
|
60
|
-
def link(schema,stack=[])
|
61
|
-
if @schema
|
62
|
-
@schema
|
63
|
-
if @type.link(schema, stack << self)
|
59
|
+
def link(schema,ns, stack=[])
|
60
|
+
if @schema.nil?
|
61
|
+
if @type.link(schema, ns, stack << self)
|
64
62
|
@schema = schema
|
65
63
|
end
|
66
64
|
end
|
67
65
|
@schema
|
68
66
|
end
|
69
|
-
|
70
|
-
# @private
|
71
|
-
def encode_compact(value, **opts)
|
72
|
-
if value[name]
|
73
|
-
@type.encode_compact(value[:name], opt: @opt)
|
74
|
-
elsif @opt
|
75
|
-
putNull
|
76
|
-
else
|
77
|
-
raise
|
78
|
-
end
|
79
|
-
end
|
80
67
|
|
81
68
|
end
|
82
69
|
end
|
@@ -0,0 +1,26 @@
|
|
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.4
|
23
|
+
class FIXED < STRING
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,27 @@
|
|
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
|
+
|
21
|
+
module SlowBlink
|
22
|
+
|
23
|
+
# Blink Specification 3.1
|
24
|
+
class FLOATING_POINT < INTEGER
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/lib/slow_blink/group.rb
CHANGED
@@ -22,7 +22,10 @@ module SlowBlink
|
|
22
22
|
class Group
|
23
23
|
|
24
24
|
include Annotatable
|
25
|
-
|
25
|
+
|
26
|
+
def self.===(other)
|
27
|
+
self == other
|
28
|
+
end
|
26
29
|
|
27
30
|
# @return [String]
|
28
31
|
attr_reader :location
|
@@ -30,6 +33,16 @@ module SlowBlink
|
|
30
33
|
# @return [NameWithID]
|
31
34
|
attr_reader :nameWithID
|
32
35
|
|
36
|
+
# @return [Array<Field>]
|
37
|
+
def fields
|
38
|
+
@fields.values
|
39
|
+
end
|
40
|
+
|
41
|
+
# @param namespace [Namespace]
|
42
|
+
def namespace=(namespace)
|
43
|
+
@ns = namespace
|
44
|
+
end
|
45
|
+
|
33
46
|
# @private
|
34
47
|
#
|
35
48
|
# @param nameWithID [NameWithID]
|
@@ -44,27 +57,29 @@ module SlowBlink
|
|
44
57
|
@location = location
|
45
58
|
@fields = []
|
46
59
|
@nameWithID = nameWithID
|
60
|
+
@ns = nil
|
47
61
|
end
|
48
62
|
|
49
63
|
# @private
|
50
64
|
#
|
51
65
|
# @macro common_link
|
52
66
|
def link(schema,stack=[])
|
53
|
-
if @schema
|
67
|
+
if @schema.nil?
|
54
68
|
errors = 0
|
55
|
-
@schema = nil
|
56
69
|
@fields = {}
|
57
|
-
if !@superGroup or (@superGroup and @superGroup.link(schema, stack << self))
|
58
|
-
if !@superGroup or @superGroup.
|
70
|
+
if !@superGroup or (@superGroup and @superGroup.link(schema, @ns, stack << self))
|
71
|
+
if !@superGroup or @superGroup.ref.is_a?(Group)
|
59
72
|
if @superGroup
|
60
|
-
@
|
73
|
+
@superGroup.ref.fields.each do |f|
|
74
|
+
@fields[f.nameWithID.name] = f
|
75
|
+
end
|
61
76
|
end
|
62
77
|
@rawFields.each do |f|
|
63
78
|
if @fields[f.nameWithID.name]
|
64
|
-
puts "#{f.location}: error: field
|
79
|
+
puts "#{f.location}: error: duplicate field name '#{f.nameWithID.name}' (first defined at #{@fields[f.nameWithID.name].location})"
|
65
80
|
errors += 1
|
66
81
|
else
|
67
|
-
if f.link(schema, stack.dup << self)
|
82
|
+
if f.link(schema, @ns, stack.dup << self)
|
68
83
|
@fields[f.nameWithID.name] = f
|
69
84
|
else
|
70
85
|
errors += 1
|
@@ -75,7 +90,7 @@ module SlowBlink
|
|
75
90
|
@schema = schema
|
76
91
|
end
|
77
92
|
else
|
78
|
-
puts "#{@superGroup.location}: error: superGroup must
|
93
|
+
puts "#{@superGroup.location}: error: superGroup '#{@superGroup.qname}' must resolve to a group definition"
|
79
94
|
end
|
80
95
|
end
|
81
96
|
end
|
@@ -89,41 +104,13 @@ module SlowBlink
|
|
89
104
|
@fields[name]
|
90
105
|
end
|
91
106
|
|
92
|
-
|
93
|
-
@fields
|
94
|
-
end
|
95
|
-
|
96
|
-
# @private
|
97
|
-
def validate(value)
|
98
|
-
if value.kind_of? Hash
|
99
|
-
if value["$type"] == @nameWithID.name
|
100
|
-
@fields.each do |name,f|
|
101
|
-
f.validate(value[name])
|
102
|
-
end
|
103
|
-
true
|
104
|
-
else
|
105
|
-
raise
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
# @private
|
107
|
+
# Is this group a sub group of the super group?
|
111
108
|
#
|
112
|
-
# @param
|
113
|
-
# @
|
114
|
-
|
115
|
-
|
116
|
-
def encode_compact(value, **opts)
|
117
|
-
out = ""
|
118
|
-
@fields.each do |name, f|
|
119
|
-
out << f.encode_compact(value)
|
120
|
-
end
|
121
|
-
if opts[:dynamic]
|
122
|
-
putVLC(@nameWithID.id) + putVLC(out.size) + out
|
123
|
-
else
|
124
|
-
out
|
125
|
-
end
|
109
|
+
# @param superGroup [Group]
|
110
|
+
# @return [true,false]
|
111
|
+
def group_kind_of?(superGroup)
|
112
|
+
(self == superGroup) or (@superGroup and @superGroup.ref.group_kind_of?(superGroup))
|
126
113
|
end
|
127
|
-
|
114
|
+
|
128
115
|
end
|
129
116
|
end
|