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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/ext/slow_blink/ext_schema_parser/parser.c +245 -245
  3. data/lib/slow_blink/annotatable.rb +1 -2
  4. data/lib/slow_blink/annotation.rb +8 -1
  5. data/lib/slow_blink/compact_encoder.rb +1 -0
  6. data/lib/slow_blink/definition.rb +34 -10
  7. data/lib/slow_blink/enumeration.rb +15 -12
  8. data/lib/slow_blink/field.rb +9 -8
  9. data/lib/slow_blink/group.rb +61 -24
  10. data/lib/slow_blink/incremental_annotation.rb +7 -4
  11. data/lib/slow_blink/integer.rb +1 -1
  12. data/{test/tc_model.rb → lib/slow_blink/log.rb} +23 -40
  13. data/lib/slow_blink/message/binary.rb +39 -45
  14. data/lib/slow_blink/message/boolean.rb +25 -33
  15. data/lib/slow_blink/message/date.rb +2 -7
  16. data/lib/slow_blink/message/decimal.rb +1 -1
  17. data/lib/slow_blink/message/enumeration.rb +29 -33
  18. data/lib/slow_blink/message/field.rb +29 -37
  19. data/lib/slow_blink/message/fixed.rb +37 -45
  20. data/lib/slow_blink/message/floating_point.rb +24 -32
  21. data/lib/slow_blink/message/group.rb +172 -187
  22. data/lib/slow_blink/message/integer.rb +83 -132
  23. data/lib/slow_blink/message/model.rb +64 -63
  24. data/lib/slow_blink/message/sequence.rb +40 -48
  25. data/lib/slow_blink/message/string.rb +44 -51
  26. data/lib/slow_blink/message/time.rb +25 -40
  27. data/lib/slow_blink/message/time_of_day.rb +73 -86
  28. data/lib/slow_blink/name_with_id.rb +2 -6
  29. data/lib/slow_blink/namespace.rb +36 -36
  30. data/lib/slow_blink/ref.rb +29 -13
  31. data/lib/slow_blink/schema.rb +26 -10
  32. data/lib/slow_blink/schema_buffer.rb +14 -0
  33. data/lib/slow_blink/sequence.rb +16 -20
  34. data/lib/slow_blink/string.rb +0 -2
  35. data/lib/slow_blink/sym.rb +7 -5
  36. data/lib/slow_blink/type.rb +8 -5
  37. data/lib/slow_blink/version.rb +1 -1
  38. data/test/tc_field.rb +41 -0
  39. data/test/tc_group.rb +11 -0
  40. data/test/tc_model_static_group.rb +114 -0
  41. data/test/{tc_model_encode.rb → tc_model_think_blink.rb} +58 -13
  42. data/test/tc_types.rb +39 -0
  43. metadata +7 -6
@@ -19,242 +19,227 @@
19
19
 
20
20
  module SlowBlink::Message
21
21
 
22
- TYPE_KEY = "$type".freeze
23
-
24
- module StaticGroup
25
-
26
- module CLASS
22
+ class StaticGroup
23
+
24
+ def self.implements
25
+ @implements
26
+ end
27
27
 
28
- def fields
29
- @fields
30
- end
28
+ def self.fields
29
+ @fields
30
+ end
31
31
 
32
- def opt?
33
- @opt
34
- end
32
+ def self.opt?
33
+ @opt
34
+ end
35
35
 
36
- def id
37
- @id
38
- end
36
+ def self.id
37
+ @id
38
+ end
39
39
 
40
- def name
41
- @name
42
- end
40
+ def self.name
41
+ @name
42
+ end
43
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
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
- end
62
- end
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
- 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
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
- def [](name)
77
- if @value[name]
78
- @value[name].get
79
- else
80
- raise "field #{name} is not defined in this group"
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
- 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
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
- def get
98
- @value
99
- end
93
+ def get
94
+ @value
95
+ end
100
96
 
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
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
- def fields
113
- @value
114
- end
107
+ def fields
108
+ @value
109
+ end
115
110
 
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
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
- out.putPresent(false)
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
- module DynamicGroup
140
-
141
- module CLASS
142
-
143
- def groups
144
- @groups
145
- end
136
+ class DynamicGroup
137
+
138
+ def self.groups
139
+ @groups
140
+ end
146
141
 
147
- def permitted
148
- @permitted
149
- end
142
+ def self.permitted
143
+ @permitted
144
+ end
150
145
 
151
- def opt?
152
- @opt
153
- end
146
+ def self.opt?
147
+ @opt
148
+ end
154
149
 
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
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 "W2: Group id #{group.id} is unknown"
159
+ raise Error.new "W15: Group is known but unexpected"
168
160
  end
169
161
  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
162
+ raise Error.new "W2: Group id #{group.id} is unknown"
177
163
  end
178
- end
179
-
180
- end
181
-
182
- module INSTANCE
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 "undefined dynamic group"
189
- end
170
+ raise Error.new "W5: Value cannot be null"
171
+ end
190
172
  end
173
+ end
191
174
 
192
- def [](name)
193
- if @value
194
- @value[name]
195
- else
196
- raise "undefined dynamic group"
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
- 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
183
+ def [](name)
184
+ if @value
185
+ @value[name]
186
+ else
187
+ raise "undefined dynamic group"
214
188
  end
189
+ end
215
190
 
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
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 "value is not a group instance"
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
- @value = nil
200
+ raise "value is not a group instance"
243
201
  end
244
- end
202
+ elsif self.class.opt?
203
+ @value = nil
204
+ else
205
+ raise
206
+ end
207
+ end
245
208
 
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
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