slow_blink 0.0.3 → 0.0.4
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_schema_parser/parser.c +245 -245
- data/lib/slow_blink/annotatable.rb +1 -2
- data/lib/slow_blink/annotation.rb +8 -1
- data/lib/slow_blink/compact_encoder.rb +1 -0
- data/lib/slow_blink/definition.rb +34 -10
- data/lib/slow_blink/enumeration.rb +15 -12
- data/lib/slow_blink/field.rb +9 -8
- data/lib/slow_blink/group.rb +61 -24
- data/lib/slow_blink/incremental_annotation.rb +7 -4
- data/lib/slow_blink/integer.rb +1 -1
- data/{test/tc_model.rb → lib/slow_blink/log.rb} +23 -40
- data/lib/slow_blink/message/binary.rb +39 -45
- data/lib/slow_blink/message/boolean.rb +25 -33
- data/lib/slow_blink/message/date.rb +2 -7
- data/lib/slow_blink/message/decimal.rb +1 -1
- data/lib/slow_blink/message/enumeration.rb +29 -33
- data/lib/slow_blink/message/field.rb +29 -37
- data/lib/slow_blink/message/fixed.rb +37 -45
- data/lib/slow_blink/message/floating_point.rb +24 -32
- data/lib/slow_blink/message/group.rb +172 -187
- data/lib/slow_blink/message/integer.rb +83 -132
- data/lib/slow_blink/message/model.rb +64 -63
- data/lib/slow_blink/message/sequence.rb +40 -48
- data/lib/slow_blink/message/string.rb +44 -51
- data/lib/slow_blink/message/time.rb +25 -40
- data/lib/slow_blink/message/time_of_day.rb +73 -86
- data/lib/slow_blink/name_with_id.rb +2 -6
- data/lib/slow_blink/namespace.rb +36 -36
- data/lib/slow_blink/ref.rb +29 -13
- data/lib/slow_blink/schema.rb +26 -10
- data/lib/slow_blink/schema_buffer.rb +14 -0
- data/lib/slow_blink/sequence.rb +16 -20
- data/lib/slow_blink/string.rb +0 -2
- data/lib/slow_blink/sym.rb +7 -5
- data/lib/slow_blink/type.rb +8 -5
- data/lib/slow_blink/version.rb +1 -1
- data/test/tc_field.rb +41 -0
- data/test/tc_group.rb +11 -0
- data/test/tc_model_static_group.rb +114 -0
- data/test/{tc_model_encode.rb → tc_model_think_blink.rb} +58 -13
- data/test/tc_types.rb +39 -0
- metadata +7 -6
@@ -19,242 +19,227 @@
|
|
19
19
|
|
20
20
|
module SlowBlink::Message
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
class StaticGroup
|
23
|
+
|
24
|
+
def self.implements
|
25
|
+
@implements
|
26
|
+
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
def self.fields
|
29
|
+
@fields
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
def self.opt?
|
33
|
+
@opt
|
34
|
+
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
def self.id
|
37
|
+
@id
|
38
|
+
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
def self.name
|
41
|
+
@name
|
42
|
+
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
44
|
+
def self.from_compact!(input)
|
45
|
+
if @opt
|
46
|
+
if input.getPresent!
|
56
47
|
fields = {}
|
57
|
-
@fields.each do |f|
|
58
|
-
fields[f.name] = f.from_compact!(input)
|
59
|
-
end
|
48
|
+
@fields.each do |f|
|
49
|
+
fields[f.name] = f.from_compact!(input)
|
50
|
+
end
|
60
51
|
self.new(fields)
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
64
62
|
end
|
65
63
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
74
|
-
end
|
64
|
+
def []=(name, value)
|
65
|
+
if @value[name]
|
66
|
+
@value[name].set(value)
|
67
|
+
else
|
68
|
+
raise "field #{name} is not defined in this group"
|
69
|
+
end
|
70
|
+
end
|
75
71
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
end
|
72
|
+
def [](name)
|
73
|
+
if @value[name]
|
74
|
+
@value[name].get
|
75
|
+
else
|
76
|
+
raise "field #{name} is not defined in this group"
|
82
77
|
end
|
78
|
+
end
|
83
79
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
end
|
80
|
+
def set(value)
|
81
|
+
if value
|
82
|
+
self.class.fields.each do |f|
|
83
|
+
@value[f.name].set(value[f.name])
|
84
|
+
@empty = false
|
85
|
+
end
|
86
|
+
elsif self.class.opt?
|
87
|
+
@empty = true
|
88
|
+
else
|
89
|
+
raise "this group cannot be NULL"
|
95
90
|
end
|
91
|
+
end
|
96
92
|
|
97
|
-
|
98
|
-
|
99
|
-
|
93
|
+
def get
|
94
|
+
@value
|
95
|
+
end
|
100
96
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
end
|
109
|
-
end
|
97
|
+
def initialize(fields)
|
98
|
+
empty = false
|
99
|
+
@value = self.class.fields.inject({}) do |value, f|
|
100
|
+
value[f.name] = f.new(nil)
|
101
|
+
end
|
102
|
+
if fields
|
103
|
+
set(fields.to_h)
|
110
104
|
end
|
105
|
+
end
|
111
106
|
|
112
|
-
|
113
|
-
|
114
|
-
|
107
|
+
def fields
|
108
|
+
@value
|
109
|
+
end
|
115
110
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
end
|
123
|
-
out
|
124
|
-
else
|
125
|
-
self.class.fields.each do |f|
|
126
|
-
@value[f.name].to_compact(out)
|
127
|
-
end
|
128
|
-
out
|
111
|
+
def to_compact(out)
|
112
|
+
if @value
|
113
|
+
if self.class.opt?
|
114
|
+
out.putPresent
|
115
|
+
self.class.fields.each do |f|
|
116
|
+
@value[f.name].to_compact(out)
|
129
117
|
end
|
118
|
+
out
|
130
119
|
else
|
131
|
-
|
120
|
+
self.class.fields.each do |f|
|
121
|
+
@value[f.name].to_compact(out)
|
122
|
+
end
|
123
|
+
out
|
132
124
|
end
|
125
|
+
else
|
126
|
+
out.putPresent(false)
|
133
127
|
end
|
128
|
+
end
|
134
129
|
|
130
|
+
def to_h
|
131
|
+
@value
|
135
132
|
end
|
136
133
|
|
137
134
|
end
|
138
135
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
@groups
|
145
|
-
end
|
136
|
+
class DynamicGroup
|
137
|
+
|
138
|
+
def self.groups
|
139
|
+
@groups
|
140
|
+
end
|
146
141
|
|
147
|
-
|
148
|
-
|
149
|
-
|
142
|
+
def self.permitted
|
143
|
+
@permitted
|
144
|
+
end
|
150
145
|
|
151
|
-
|
152
|
-
|
153
|
-
|
146
|
+
def self.opt?
|
147
|
+
@opt
|
148
|
+
end
|
154
149
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
else
|
164
|
-
raise Error.new "W15: Group is known but unexpected"
|
165
|
-
end
|
150
|
+
def self.from_compact!(input)
|
151
|
+
buf = input.getBinary!
|
152
|
+
if buf.size > 0
|
153
|
+
id = buf.getU64!
|
154
|
+
group = @groups[id]
|
155
|
+
if group
|
156
|
+
if @permitted.include? group.id
|
157
|
+
self.new(group.from_compact!(buf))
|
166
158
|
else
|
167
|
-
raise Error.new "
|
159
|
+
raise Error.new "W15: Group is known but unexpected"
|
168
160
|
end
|
169
161
|
else
|
170
|
-
|
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
|
162
|
+
raise Error.new "W2: Group id #{group.id} is unknown"
|
177
163
|
end
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
def []=(name, value)
|
185
|
-
if @value
|
186
|
-
@value[name] = value
|
164
|
+
else
|
165
|
+
if self == ModelInstance
|
166
|
+
raise Error.new "W1: Top level group cannot be null"
|
167
|
+
elsif @opt
|
168
|
+
self.new(nil)
|
187
169
|
else
|
188
|
-
raise "
|
189
|
-
end
|
170
|
+
raise Error.new "W5: Value cannot be null"
|
171
|
+
end
|
190
172
|
end
|
173
|
+
end
|
191
174
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
end
|
175
|
+
def []=(name, value)
|
176
|
+
if @value
|
177
|
+
@value[name] = value
|
178
|
+
else
|
179
|
+
raise "undefined dynamic group"
|
198
180
|
end
|
181
|
+
end
|
199
182
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
# g["field"] = "value"
|
206
|
-
# end
|
207
|
-
# group "name" do |g|
|
208
|
-
# g["field"] = "value"
|
209
|
-
# end
|
210
|
-
# ...
|
211
|
-
# end
|
212
|
-
#
|
213
|
-
raise
|
183
|
+
def [](name)
|
184
|
+
if @value
|
185
|
+
@value[name]
|
186
|
+
else
|
187
|
+
raise "undefined dynamic group"
|
214
188
|
end
|
189
|
+
end
|
215
190
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
else
|
222
|
-
raise "group is not a permitted group"
|
223
|
-
end
|
191
|
+
def set(value)
|
192
|
+
if value
|
193
|
+
if self.class.groups.values.include? value.class
|
194
|
+
if self.class.permitted.include? value.class.id
|
195
|
+
@value = value
|
224
196
|
else
|
225
|
-
raise "
|
197
|
+
raise "group is not a permitted group"
|
226
198
|
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
199
|
else
|
242
|
-
|
200
|
+
raise "value is not a group instance"
|
243
201
|
end
|
244
|
-
|
202
|
+
elsif self.class.opt?
|
203
|
+
@value = nil
|
204
|
+
else
|
205
|
+
raise
|
206
|
+
end
|
207
|
+
end
|
245
208
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
out.putU32(group.size)
|
250
|
-
out << group
|
251
|
-
else
|
252
|
-
out.putU32(nil)
|
253
|
-
end
|
254
|
-
end
|
209
|
+
def get
|
210
|
+
@value
|
211
|
+
end
|
255
212
|
|
213
|
+
def initialize(value)
|
214
|
+
if value
|
215
|
+
set(value)
|
216
|
+
else
|
217
|
+
@value = nil
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
def to_compact(out="")
|
222
|
+
if @value
|
223
|
+
group = @value.to_compact("".putU64(@value.class.id))
|
224
|
+
out.putU32(group.size)
|
225
|
+
out << group
|
226
|
+
else
|
227
|
+
out.putU32(nil)
|
228
|
+
end
|
256
229
|
end
|
257
230
|
|
231
|
+
# @api user
|
232
|
+
#
|
233
|
+
# Encode {Group} as Blink compact form
|
234
|
+
#
|
235
|
+
# @return [String]
|
236
|
+
#
|
237
|
+
def encode_compact
|
238
|
+
to_compact
|
239
|
+
end
|
240
|
+
|
258
241
|
end
|
259
242
|
|
243
|
+
|
244
|
+
|
260
245
|
end
|