slow_blink 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/ext/slow_blink/ext_schema_parser/lexer.c +2793 -839
  3. data/ext/slow_blink/ext_schema_parser/lexer.h +14 -137
  4. data/ext/slow_blink/ext_schema_parser/parser.c +616 -670
  5. data/ext/slow_blink/ext_schema_parser/parser.h +6 -4
  6. data/ext/slow_blink/message/ext_compact_encoder/blink_compact.c +642 -0
  7. data/ext/slow_blink/message/ext_compact_encoder/blink_compact.h +411 -0
  8. data/ext/slow_blink/message/ext_compact_encoder/blink_debug.h +46 -0
  9. data/ext/slow_blink/message/ext_compact_encoder/blink_stream.c +314 -0
  10. data/ext/slow_blink/message/ext_compact_encoder/blink_stream.h +185 -0
  11. data/ext/slow_blink/message/ext_compact_encoder/ext_compact_encoder.c +382 -269
  12. data/lib/slow_blink/definition.rb +18 -53
  13. data/lib/slow_blink/dynamic_group.rb +8 -0
  14. data/lib/slow_blink/enum.rb +101 -0
  15. data/lib/slow_blink/field.rb +63 -33
  16. data/lib/slow_blink/generate_c/model.rb +89 -0
  17. data/lib/slow_blink/group.rb +119 -100
  18. data/lib/slow_blink/message/binary.rb +3 -4
  19. data/lib/slow_blink/message/boolean.rb +3 -4
  20. data/lib/slow_blink/message/date.rb +3 -4
  21. data/lib/slow_blink/message/decimal.rb +3 -5
  22. data/lib/slow_blink/message/{enumeration.rb → enum.rb} +17 -17
  23. data/lib/slow_blink/message/field.rb +77 -27
  24. data/lib/slow_blink/message/fixed.rb +5 -21
  25. data/lib/slow_blink/message/floating_point.rb +3 -4
  26. data/lib/slow_blink/message/group.rb +90 -161
  27. data/lib/slow_blink/message/integer.rb +24 -32
  28. data/lib/slow_blink/message/model.rb +50 -110
  29. data/lib/slow_blink/message/string.rb +3 -4
  30. data/lib/slow_blink/message/time.rb +5 -5
  31. data/lib/slow_blink/message/time_of_day.rb +5 -12
  32. data/lib/slow_blink/ref.rb +22 -71
  33. data/lib/slow_blink/schema.rb +64 -85
  34. data/lib/slow_blink/schema_buffer.rb +1 -4
  35. data/lib/slow_blink/static_group.rb +37 -0
  36. data/lib/slow_blink/string.rb +4 -5
  37. data/lib/slow_blink/sym.rb +8 -28
  38. data/lib/slow_blink/type.rb +10 -19
  39. data/lib/slow_blink/version.rb +1 -1
  40. data/lib/slow_blink.rb +1 -0
  41. data/test/tc_compact_encoder.rb +114 -147
  42. data/test/tc_inputs.rb +2 -4
  43. data/test/tc_model_string.rb +29 -0
  44. data/test/tc_schema_new.rb +212 -0
  45. metadata +17 -26
  46. data/ext/slow_blink/ext_schema_parser/common.h +0 -27
  47. data/ext/slow_blink/message/ext_compact_encoder/compact_encoder.c +0 -258
  48. data/ext/slow_blink/message/ext_compact_encoder/compact_encoder.h +0 -92
  49. data/lib/slow_blink/annotatable.rb +0 -48
  50. data/lib/slow_blink/annotation.rb +0 -47
  51. data/lib/slow_blink/enumeration.rb +0 -90
  52. data/lib/slow_blink/incremental_annotation.rb +0 -151
  53. data/lib/slow_blink/log.rb +0 -51
  54. data/lib/slow_blink/message/sequence.rb +0 -98
  55. data/lib/slow_blink/name_with_id.rb +0 -49
  56. data/lib/slow_blink/namespace.rb +0 -143
  57. data/lib/slow_blink/sequence.rb +0 -57
  58. data/test/tc_field.rb +0 -94
  59. data/test/tc_group.rb +0 -114
  60. data/test/tc_incr_annote.rb +0 -22
  61. data/test/tc_namespace.rb +0 -8
  62. data/test/tc_types.rb +0 -218
@@ -25,12 +25,11 @@ module SlowBlink::Message
25
25
  class BOOLEAN
26
26
 
27
27
  # @private
28
- def self.from_compact!(input, stack)
29
- value = input.getBool!
30
- if value
28
+ def self.from_compact(input, stack)
29
+ if value = input.getBool
31
30
  self.new(value)
32
31
  else
33
- value
32
+ nil
34
33
  end
35
34
  end
36
35
 
@@ -25,12 +25,11 @@ module SlowBlink::Message
25
25
  class DATE
26
26
 
27
27
  # @private
28
- def self.from_compact!(input, stack)
29
- value = input.getI32!
30
- if value
28
+ def self.from_compact(input, stack)
29
+ if value = input.getI32
31
30
  self.new(value)
32
31
  else
33
- value
32
+ nil
34
33
  end
35
34
  end
36
35
 
@@ -27,11 +27,9 @@ module SlowBlink::Message
27
27
  class DECIMAL
28
28
 
29
29
  # @private
30
- def self.from_compact!(input, stack)
31
- e = input.getI8!
32
- if e
33
- m = input.getI64!
34
- if m
30
+ def self.from_compact(input, stack)
31
+ if e = input.getI8
32
+ if m = input.getI64
35
33
  self.new("#{m}E#{e}")
36
34
  else
37
35
  raise NullMantissa
@@ -22,25 +22,22 @@
22
22
  module SlowBlink::Message
23
23
 
24
24
  # @abstract
25
- class ENUMERATION
25
+ class ENUM
26
26
 
27
- # @return [Hash] symbol => value table
28
- def self.symbols
29
- @symbols
27
+ def self.type
28
+ @type
30
29
  end
31
30
 
32
31
  # @private
33
- def self.from_compact!(input, stack)
34
- value = input.getI32!
35
- if value
36
- symbol = @symbols.key(value)
37
- if symbol
38
- self.new(symbol)
32
+ def self.from_compact(input, stack)
33
+ if value = input.getI32
34
+ if symbol = type.symbol(value)
35
+ self.new(symbol.name)
39
36
  else
40
37
  raise WeakError10.new "W10: value '#{value}' does not correspond to any symbol in enumeration"
41
38
  end
42
39
  else
43
- value
40
+ nil
44
41
  end
45
42
  end
46
43
 
@@ -53,22 +50,25 @@ module SlowBlink::Message
53
50
  # @param value [String] symbol in enumeration
54
51
  # @raise [RangeError] value is not valid symbol
55
52
  def set(value)
56
- if @symbols[value]
57
- @value = value.to_s
53
+ if value.kind_of? String
54
+ if self.class.type.symbol(value)
55
+ @value = value.to_s
56
+ else
57
+ raise RangeError.new "symbol '#{value}' not defined in enumeration"
58
+ end
58
59
  else
59
- raise RangeError.new "symbol '#{value}' not defined in enumeration"
60
- end
60
+ raise TypeError.new "value must be a String"
61
+ end
61
62
  end
62
63
 
63
64
  # @note calls {#set}(value)
64
65
  def initialize(value)
65
- @symbols = self.class.symbols
66
66
  set(value)
67
67
  end
68
68
 
69
69
  # @private
70
70
  def to_compact(out)
71
- out.putI32(@symbols[@value])
71
+ out.putI32(self.class.type.symbol(@value).value)
72
72
  end
73
73
 
74
74
  end
@@ -25,13 +25,13 @@ module SlowBlink::Message
25
25
  class Field
26
26
 
27
27
  # @return [true,false] field is optional?
28
- def self.opt?
29
- @opt
28
+ def self.optional?
29
+ @optional
30
30
  end
31
31
 
32
32
  # @return [String] field name
33
33
  def self.name
34
- @name
34
+ @name.to_s
35
35
  end
36
36
 
37
37
  # @return [Integer,nil] field ID
@@ -44,66 +44,116 @@ module SlowBlink::Message
44
44
  @type
45
45
  end
46
46
 
47
+ # @return [true,false] true if this field contains a sequence type
48
+ def self.sequence?
49
+ @sequence
50
+ end
51
+
47
52
  # @private
48
53
  # @param input [String] Blink compact form
49
54
  # @param stack [Array]
50
55
  # @return [Field] instance of anonymous subclass of Field
51
- def self.from_compact!(input, stack)
52
- self.new(@type.from_compact!(input, stack))
56
+ def self.from_compact(input, stack)
57
+ if sequence?
58
+ if size = input.getU32
59
+ value = []
60
+ while value.size < size do
61
+ value << @type.from_compact(input, stack).get
62
+ end
63
+ self.new(value)
64
+ else
65
+ nil
66
+ end
67
+ elsif optional? and (type.kind_of? StaticGroup or type.kind_of? FIXED)
68
+ if input.get_present(input)
69
+ self.new(@type.from_compact(input, stack).get)
70
+ else
71
+ nil
72
+ end
73
+ else
74
+ self.new(@type.from_compact(input, stack).get)
75
+ end
53
76
  end
54
77
 
55
78
  # @note calls {#set}(value)
56
79
  def initialize(value)
57
- @opt = self.class.opt?
80
+
81
+ @optional = self.class.optional?
82
+ @sequence = self.class.sequence?
58
83
  @type = self.class.type
59
- if value.is_a? self.class.type
60
- @value = value
61
- elsif value
62
- @value = self.class.type.new(value)
84
+
85
+ if value
86
+ set(value)
63
87
  else
64
88
  @value = nil
65
89
  end
90
+
66
91
  end
67
-
68
92
 
69
93
  def set(value)
70
- if value
71
- if value.is_a? self.class.type
72
- @value = value
73
- elsif @value
74
- @value.set(value)
94
+ if value.nil?
95
+ if optional?
96
+ @value = nil
97
+ else
98
+ raise ArgumentError.new "field is not optional, value cannot be nil"
99
+ end
100
+ elsif self.class.sequence?
101
+ if value.kind_of? Array
102
+ @value = []
103
+ value.each do |v|
104
+ @value << @type.new(v)
105
+ end
75
106
  else
76
- @value = self.class.type.new(value)
107
+ raise ArgumentError.new "field value must be an array of type"
77
108
  end
78
- elsif @opt
79
- @value = nil
80
109
  else
81
- raise TypeError.new "field can not be set to null"
82
- end
110
+ @value = @type.new(value)
111
+ end
83
112
  end
84
113
 
85
114
  # @return field value or nil
86
115
  def get
87
116
  if @value
88
- @value.get
117
+ if self.class.sequence?
118
+ @value.map{|v|v.get}
119
+ else
120
+ @value.get
121
+ end
89
122
  else
90
123
  nil
91
124
  end
92
125
  end
93
126
 
94
127
  # @private
95
- # @param out [String] output appended to this string
96
- # @return [String]
128
+ # @param out [StringIO]
129
+ # @return [StringIO]
97
130
  def to_compact(out)
98
131
  if @value
99
- @value.to_compact(out)
100
- elsif @opt
132
+ if self.class.sequence?
133
+ out.putU32(@value.size)
134
+ @value.each do |v|
135
+ v.to_compact(out)
136
+ end
137
+ else
138
+ if self.class.optional? and (self.type.kind_of? StaticGroup or self.type.kind_of? FIXED)
139
+ out.putPresent
140
+ end
141
+ @value.to_compact(out)
142
+ end
143
+ elsif @optional
101
144
  out.putNull
102
145
  else
103
- raise IncompleteGroup.new "field '#{self.name}' must not be null"
146
+ raise IncompleteGroup.new "'#{self.name}' must not be null"
104
147
  end
105
148
  end
106
149
 
150
+ private
151
+
152
+ def sequenceOfSameType(value)
153
+ value.each do ||
154
+ end
155
+ end
156
+
107
157
  end
108
158
 
109
159
  end
@@ -24,27 +24,16 @@ module SlowBlink::Message
24
24
  # @abstract
25
25
  class FIXED
26
26
 
27
- # @note optionality affects how instances of this type are encoded
28
- # @return [true,false] is optional
29
- def self.opt?
30
- @opt
31
- end
32
-
33
27
  # @private
34
- def self.from_compact!(input, stack)
35
- if @opt
36
- value = input.getFixedOptional!
37
- else
38
- value = input.getFixed!
39
- end
40
- if value
28
+ def self.from_compact(input, stack)
29
+ if value = input.getFixed(size)
41
30
  self.new(value)
42
31
  else
43
- value
32
+ nil
44
33
  end
45
34
  end
46
35
 
47
- # @return [Integer,nil] size of fixed type in bytes
36
+ # @return [Integer] size of fixed type in bytes
48
37
  def self.size
49
38
  @type.size
50
39
  end
@@ -72,17 +61,12 @@ module SlowBlink::Message
72
61
 
73
62
  # @note calls {#set}(value)
74
63
  def initialize(value)
75
- @opt = self.class.opt?
76
64
  set(value)
77
65
  end
78
66
 
79
67
  # @private
80
68
  def to_compact(out)
81
- if @opt
82
- out.putFixedOptional(@value)
83
- else
84
- out.putFixed(@value)
85
- end
69
+ out.putFixed(@value)
86
70
  end
87
71
 
88
72
  end
@@ -25,12 +25,11 @@ module SlowBlink::Message
25
25
  class FLOATING_POINT
26
26
 
27
27
  # @private
28
- def self.from_compact!(input, stack)
29
- value = input.getF64!
30
- if value
28
+ def self.from_compact(input, stack)
29
+ if value = input.getF64
31
30
  self.new(value)
32
31
  else
33
- value
32
+ nil
34
33
  end
35
34
  end
36
35