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,17 +22,17 @@ module SlowBlink
|
|
22
22
|
# Blink Specification 7.3
|
23
23
|
class IncrementalAnnotation
|
24
24
|
|
25
|
-
attr_reader :
|
25
|
+
attr_reader :componentReference
|
26
26
|
attr_reader :annotes
|
27
27
|
attr_reader :location
|
28
28
|
|
29
29
|
# @private
|
30
30
|
#
|
31
|
-
# @param
|
31
|
+
# @param componentReference [SchemaRef, DefinitionRef, DefinitionTypeRef, FieldRef, FieldTypeRef] annotation target
|
32
32
|
# @param annotations [Array<Integer,Annotation>]
|
33
33
|
# @param location [String]
|
34
|
-
def initialize(
|
35
|
-
@
|
34
|
+
def initialize(componentReference, annotes, location)
|
35
|
+
@componentReference = componentReference
|
36
36
|
@annotes = annotes
|
37
37
|
@location = location
|
38
38
|
@schema = nil
|
@@ -42,50 +42,104 @@ module SlowBlink
|
|
42
42
|
#
|
43
43
|
# Apply annotes to targets
|
44
44
|
#
|
45
|
-
# @
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
45
|
+
# @param schema [Schema]
|
46
|
+
# @param namespace [Namespace] the namespace this annotation was defined in
|
47
|
+
#
|
48
|
+
def apply(schema, namespace)
|
49
|
+
if @schema.nil?
|
50
|
+
case @componentReference.class
|
51
|
+
when SchemaRef # this actually refers to the Namespace
|
52
|
+
namespace.annote(@annotes)
|
52
53
|
@schema = schema
|
53
54
|
when DefinitionRef
|
54
|
-
object = schema.
|
55
|
+
object = schema.resolve(@componentReference.namespace, @componentReference.name)
|
55
56
|
if object
|
56
|
-
object.
|
57
|
+
object.annote(@annotes)
|
57
58
|
@schema = schema
|
58
59
|
end
|
59
60
|
when DefinitionTypeRef
|
60
|
-
object = schema.
|
61
|
+
object = schema.resolve(@componentReference.namespace, @componentReference.name)
|
61
62
|
if object
|
62
|
-
object.
|
63
|
+
object.type.annote(@annotes)
|
63
64
|
@schema = schema
|
64
65
|
end
|
65
66
|
when FieldRef
|
66
|
-
object = schema.
|
67
|
+
object = schema.resolve(@componentReference.namespace, @componentReference.name)
|
67
68
|
if object
|
68
|
-
field = object.field(
|
69
|
+
field = object.field(@componentReference.subname)
|
69
70
|
if field
|
70
|
-
field.
|
71
|
+
field.annote(@annotes)
|
71
72
|
@schema = schema
|
72
73
|
end
|
73
74
|
end
|
74
75
|
when FieldTypeRef
|
75
|
-
object = schema.
|
76
|
+
object = schema.resolve(@componentReference.namespace, @componentReference.name)
|
76
77
|
if object
|
77
|
-
field = object.field(
|
78
|
+
field = object.field(@componentReference.subname)
|
78
79
|
if field
|
79
80
|
field.type.annote(@annotes)
|
80
81
|
@schema = schema
|
81
82
|
end
|
82
83
|
end
|
83
84
|
else
|
84
|
-
raise "unknown component reference".freeze
|
85
|
+
raise "unknown component reference #{@componentReference.class}".freeze
|
85
86
|
end
|
86
87
|
end
|
87
88
|
@schema
|
88
89
|
end
|
89
90
|
|
90
91
|
end
|
92
|
+
|
93
|
+
# SCHEMA
|
94
|
+
class SchemaRef
|
95
|
+
def self.===(other)
|
96
|
+
self == other
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# qName
|
101
|
+
class DefinitionRef < SchemaRef
|
102
|
+
attr_reader :namespace
|
103
|
+
attr_reader :name
|
104
|
+
attr_reader :qname
|
105
|
+
# @param qName [String] name of the definition to annotate
|
106
|
+
def initialize(qname)
|
107
|
+
@qname = qname
|
108
|
+
if qname.split(":").size == 1
|
109
|
+
@namespace = nil
|
110
|
+
@name = qname
|
111
|
+
else
|
112
|
+
@namespace = qname.split(":").first
|
113
|
+
@name = qName.split(":").last
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# qName.TYPE
|
119
|
+
class DefinitionTypeRef < DefinitionRef
|
120
|
+
end
|
121
|
+
|
122
|
+
# qName.name
|
123
|
+
class FieldRef < SchemaRef
|
124
|
+
attr_reader :namespace
|
125
|
+
attr_reader :name
|
126
|
+
attr_reader :qname
|
127
|
+
attr_reader :subname
|
128
|
+
def initialize(qname, name)
|
129
|
+
@qname = qname
|
130
|
+
if qname.split(":").size == 1
|
131
|
+
@namespace = nil
|
132
|
+
@name = qname
|
133
|
+
else
|
134
|
+
@namespace = qname.split(":").first
|
135
|
+
@name = qName.split(":").last
|
136
|
+
end
|
137
|
+
@subname = name
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
# qName.name.TYPE
|
142
|
+
class FieldTypeRef < FieldRef
|
143
|
+
end
|
144
|
+
|
91
145
|
end
|
@@ -0,0 +1,65 @@
|
|
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 INTEGER < Type
|
23
|
+
end
|
24
|
+
|
25
|
+
# Blink Specification 3.1
|
26
|
+
class I8 < INTEGER
|
27
|
+
RANGE = Range.new(-128, 127)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Blink Specification 3.1
|
31
|
+
class I16 < INTEGER
|
32
|
+
RANGE = Range.new(-32768, 32767)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Blink Specification 3.1
|
36
|
+
class I32 < INTEGER
|
37
|
+
RANGE = Range.new(-2147483648, 2147483647)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Blink Specification 3.1
|
41
|
+
class I64 < INTEGER
|
42
|
+
RANGE = Range.new(-9223372036854775808, 9223372036854775807)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Blink Specification 3.1
|
46
|
+
class U8 < INTEGER
|
47
|
+
RANGE = Range.new(0, 0xff)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Blink Specification 3.1
|
51
|
+
class U16 < INTEGER
|
52
|
+
RANGE = Range.new(0, 0xffff)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Blink Specification 3.1
|
56
|
+
class U32 < INTEGER
|
57
|
+
RANGE = Range.new(0, 0xffffffff)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Blink Specification 3.1
|
61
|
+
class U64 < INTEGER
|
62
|
+
RANGE = Range.new(0, 0xffffffffffffffff)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,87 @@
|
|
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 BINARY
|
23
|
+
|
24
|
+
module CLASS
|
25
|
+
|
26
|
+
def opt?
|
27
|
+
@opt
|
28
|
+
end
|
29
|
+
|
30
|
+
def from_compact!(input)
|
31
|
+
value = input.getBinary!
|
32
|
+
if value
|
33
|
+
if !@size or value.size <= @size
|
34
|
+
self.new(value)
|
35
|
+
else
|
36
|
+
raise Error.new "W8: Binary value exceeds maximum size"
|
37
|
+
end
|
38
|
+
elsif @opt
|
39
|
+
self.new(nil)
|
40
|
+
else
|
41
|
+
raise Error.new "W5: Value cannot be null"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def size
|
46
|
+
@type.size
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
module INSTANCE
|
52
|
+
|
53
|
+
def set(value)
|
54
|
+
if value
|
55
|
+
if value.kind_of? String
|
56
|
+
if !self.class.size or value.size <= self.class.size
|
57
|
+
@value = value
|
58
|
+
else
|
59
|
+
raise Error.new "string cannot be larger than #{self.class.size} bytes"
|
60
|
+
end
|
61
|
+
else
|
62
|
+
raise Error.new "expecting a string type"
|
63
|
+
end
|
64
|
+
elsif self.class.opt?
|
65
|
+
@value = nil
|
66
|
+
else
|
67
|
+
raise Error.new "string cannot be null"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def get
|
72
|
+
@value
|
73
|
+
end
|
74
|
+
|
75
|
+
def initialize(value)
|
76
|
+
set(value)
|
77
|
+
end
|
78
|
+
|
79
|
+
def to_compact(out)
|
80
|
+
out.putBinary(@value)
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -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 BOOLEAN
|
23
|
+
|
24
|
+
module CLASS
|
25
|
+
|
26
|
+
def from_compact!(input)
|
27
|
+
self.new(input.getBool!)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
module INSTANCE
|
33
|
+
|
34
|
+
def set(value)
|
35
|
+
if value
|
36
|
+
if value.kind_of? TrueClass or value.kind_of? FalseClass
|
37
|
+
@value = value
|
38
|
+
else
|
39
|
+
raise "expecting true/false"
|
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.putBool(@value)
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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 DATE
|
23
|
+
|
24
|
+
module CLASS
|
25
|
+
end
|
26
|
+
|
27
|
+
module INSTANCE
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
@@ -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::Message
|
21
|
+
|
22
|
+
module DECIMAL
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,69 @@
|
|
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 ENUMERATION
|
23
|
+
|
24
|
+
module CLASS
|
25
|
+
|
26
|
+
def from_compact!(input)
|
27
|
+
self.new(input.getU32!)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
module INSTANCE
|
33
|
+
|
34
|
+
# @param v [String]
|
35
|
+
def set(value)
|
36
|
+
if value
|
37
|
+
if self.symbols[value]
|
38
|
+
@value = self.class.symbols[value]
|
39
|
+
else
|
40
|
+
raise Error.new "symbol '#{value}' not defined in enumeration"
|
41
|
+
end
|
42
|
+
elsif self.class.opt?
|
43
|
+
@value = nil
|
44
|
+
else
|
45
|
+
raise Error.new "field may not be null"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def get
|
50
|
+
@value
|
51
|
+
end
|
52
|
+
|
53
|
+
def initialize(value)
|
54
|
+
if value
|
55
|
+
set(value)
|
56
|
+
else
|
57
|
+
@value = nil
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_compact(out)
|
62
|
+
out.putU32(@value ? self.class.symbols[@value] : nil)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,73 @@
|
|
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 Field
|
23
|
+
|
24
|
+
module CLASS
|
25
|
+
|
26
|
+
# @return [true,false] field is optional?
|
27
|
+
def opt?
|
28
|
+
@opt
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [String] field name
|
32
|
+
def name
|
33
|
+
@name
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Integer,nil] field ID
|
37
|
+
def id
|
38
|
+
@id
|
39
|
+
end
|
40
|
+
|
41
|
+
def type
|
42
|
+
@type
|
43
|
+
end
|
44
|
+
|
45
|
+
def from_compact!(input)
|
46
|
+
@type.from_compact!(input)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
module INSTANCE
|
52
|
+
|
53
|
+
def initialize(value)
|
54
|
+
@value = self.class.type.new(value)
|
55
|
+
end
|
56
|
+
|
57
|
+
def set(value)
|
58
|
+
@value.set(value)
|
59
|
+
end
|
60
|
+
|
61
|
+
def get
|
62
|
+
@value.get
|
63
|
+
end
|
64
|
+
|
65
|
+
def to_compact(out)
|
66
|
+
@value.to_compact(out)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,84 @@
|
|
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 FIXED
|
23
|
+
|
24
|
+
module CLASS
|
25
|
+
|
26
|
+
def from_compact!(input)
|
27
|
+
if opt?
|
28
|
+
self.new(input.getFixedOptional!)
|
29
|
+
else
|
30
|
+
self.new(input.getFixed!)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def size
|
35
|
+
@type.size
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
module INSTANCE
|
41
|
+
|
42
|
+
def set(value)
|
43
|
+
if value
|
44
|
+
if value.kind_of? String
|
45
|
+
if value.size == self.class.size
|
46
|
+
@value = value
|
47
|
+
else
|
48
|
+
raise Error.new "must be #{@size} bytes"
|
49
|
+
end
|
50
|
+
else
|
51
|
+
raise "expecting string"
|
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
|
+
def initialize(value)
|
65
|
+
if value
|
66
|
+
set(value)
|
67
|
+
else
|
68
|
+
@value = nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def to_compact(out)
|
73
|
+
if self.opt?
|
74
|
+
out.putFixedOptional(@value)
|
75
|
+
else
|
76
|
+
out.putFixed(@value)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|