slow_blink 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/ext/slow_blink/ext_compact_encoder/compact_encoder.c +258 -0
  3. data/ext/slow_blink/ext_compact_encoder/compact_encoder.h +92 -0
  4. data/ext/slow_blink/ext_compact_encoder/ext_compact_encoder.c +555 -0
  5. data/ext/slow_blink/ext_compact_encoder/extconf.rb +4 -0
  6. data/ext/slow_blink/ext_schema_parser/lexer.c +59 -59
  7. data/ext/slow_blink/ext_schema_parser/lexer.h +2 -2
  8. data/ext/slow_blink/ext_schema_parser/parser.c +380 -367
  9. data/ext/slow_blink/ext_schema_parser/parser.h +1 -1
  10. data/lib/slow_blink/annotatable.rb +1 -1
  11. data/lib/slow_blink/annotation.rb +5 -5
  12. data/lib/slow_blink/binary.rb +26 -0
  13. data/lib/slow_blink/boolean.rb +26 -0
  14. data/lib/slow_blink/compact_encoder.rb +45 -71
  15. data/lib/slow_blink/date.rb +25 -0
  16. data/lib/slow_blink/decimal.rb +26 -0
  17. data/lib/slow_blink/definition.rb +19 -10
  18. data/lib/slow_blink/enumeration.rb +14 -36
  19. data/lib/slow_blink/error.rb +19 -0
  20. data/lib/slow_blink/field.rb +3 -16
  21. data/lib/slow_blink/fixed.rb +26 -0
  22. data/lib/slow_blink/floating_point.rb +27 -0
  23. data/lib/slow_blink/group.rb +30 -43
  24. data/lib/slow_blink/incremental_annotation.rb +75 -21
  25. data/lib/slow_blink/integer.rb +65 -0
  26. data/lib/slow_blink/message/binary.rb +87 -0
  27. data/lib/slow_blink/message/boolean.rb +68 -0
  28. data/lib/slow_blink/message/date.rb +33 -0
  29. data/lib/slow_blink/message/decimal.rb +25 -0
  30. data/lib/slow_blink/message/enumeration.rb +69 -0
  31. data/lib/slow_blink/message/field.rb +73 -0
  32. data/lib/slow_blink/message/fixed.rb +84 -0
  33. data/lib/slow_blink/message/floating_point.rb +68 -0
  34. data/lib/slow_blink/message/group.rb +260 -0
  35. data/lib/slow_blink/message/integer.rb +217 -0
  36. data/lib/slow_blink/message/model.rb +202 -0
  37. data/lib/slow_blink/message/sequence.rb +85 -0
  38. data/lib/slow_blink/message/string.rb +95 -0
  39. data/lib/slow_blink/message/time.rb +78 -0
  40. data/lib/slow_blink/message/time_of_day.rb +132 -0
  41. data/lib/slow_blink/name_with_id.rb +2 -1
  42. data/lib/slow_blink/namespace.rb +140 -0
  43. data/lib/slow_blink/object.rb +29 -0
  44. data/lib/slow_blink/ref.rb +93 -0
  45. data/lib/slow_blink/schema.rb +94 -68
  46. data/lib/slow_blink/{component_reference.rb → schema_buffer.rb} +11 -22
  47. data/lib/slow_blink/sequence.rb +58 -0
  48. data/lib/slow_blink/string.rb +40 -0
  49. data/lib/slow_blink/sym.rb +4 -0
  50. data/lib/slow_blink/time.rb +30 -0
  51. data/lib/slow_blink/time_of_day.rb +30 -0
  52. data/lib/slow_blink/type.rb +7 -402
  53. data/lib/slow_blink/version.rb +1 -1
  54. data/lib/slow_blink.rb +1 -0
  55. data/rakefile +14 -3
  56. data/test/{integration/capture_stderr.rb → capture_stderr.rb} +0 -0
  57. data/test/tc_compact_encoder.rb +341 -0
  58. data/test/tc_field.rb +53 -0
  59. data/test/tc_group.rb +122 -0
  60. data/test/tc_incr_annote.rb +27 -0
  61. data/test/{integration/tc_inputs.rb → tc_inputs.rb} +7 -11
  62. data/test/tc_model.rb +65 -0
  63. data/test/tc_model_encode.rb +63 -0
  64. data/test/tc_namespace.rb +8 -0
  65. data/test/tc_types.rb +198 -0
  66. metadata +58 -11
  67. data/ext/slow_blink/ext_schema_parser/parser.l +0 -139
  68. data/ext/slow_blink/ext_schema_parser/parser.y +0 -932
  69. data/lib/slow_blink/message.rb +0 -43
@@ -34,7 +34,7 @@
34
34
  # define YY_YY_EXT_SLOW_BLINK_EXT_SCHEMA_PARSER_PARSER_H_INCLUDED
35
35
  /* Debug traces. */
36
36
  #ifndef YYDEBUG
37
- # define YYDEBUG 0
37
+ # define YYDEBUG 1
38
38
  #endif
39
39
  #if YYDEBUG
40
40
  extern int yydebug;
@@ -37,7 +37,7 @@ module SlowBlink
37
37
  if @nameWithID.id
38
38
  puts "#{a.location}: warning: overriding previous id"
39
39
  end
40
- @nameWithID.id = a
40
+ @nameWithID.id = a.to_i
41
41
  end
42
42
  end
43
43
  end
@@ -22,15 +22,15 @@ module SlowBlink
22
22
 
23
23
  attr_reader :location
24
24
  attr_reader :id
25
- attr_reader :literal
25
+ attr_reader :value
26
26
 
27
27
  # @param id [String] any string
28
- # @param literal [String] any string
28
+ # @param value [String] any string
29
29
  # @param location [String]
30
- def initialize(id,literal,location)
30
+ def initialize(id,value,location)
31
31
  @id = id
32
- @literal = literal
33
- @location = 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
- # @return [String]
26
- def self.putNull
27
- "\x40"
28
- end
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
- def self.putBool(value)
36
- (value) ? "\x01" : "\x00"
37
- end
38
-
39
- # @param value [Float]
40
- # @return [String]
41
- def self.putF64(value)
42
- putVLC([value].pack("G").unpack("Q<").first)
43
- end
44
-
45
- def self.putString(value)
46
- putVLC(value.size) + value
47
- end
48
-
49
- def self.putBinary(value)
50
- putVLC(value.size) + value.to_s
51
- end
52
-
53
- def self.putFixed(value)
54
- value.to_s
55
- end
56
-
57
-
58
-
59
-
60
-
61
- # @private
62
- #
63
- # @param value [Integer] unsigned integer
64
- # @return [Integer] bytes to encode as VLC
65
- def self.getSizeUnsigned(value)
66
- end
67
-
68
- # @private
69
- #
70
- # @param value [Integer] signed integer
71
- # @return [Integer] bytes to encode as VLC
72
- def self.getSizeSigned(value)
73
- end
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
- extend CompactEncoder
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 [Enumeration]
35
+ # @return [ENUMERATION]
33
36
  # @return [Type]
34
- attr_reader :enumOrType
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 enumOrType [Enumeration, Type]
47
+ # @param type [ENUMERATION, Type]
40
48
  # @param location [String]
41
- def initialize(nameWithID, enumOrType, location)
49
+ def initialize(nameWithID, type, location)
42
50
  @annotes = {}
43
51
  @schema = nil
44
- @enumOrType = enumOrType
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 = @enumOrType.link(schema, stack << self)
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 Enumeration
22
+ class ENUMERATION
23
23
 
24
24
  include Annotatable
25
- extend CompactEncoder
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 ===(other)
38
- self.class == other.class
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
- @syms[s.name] = value
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 sym(nameOrVal)
79
- if key.kind_of? String
80
- @syms[key.to_s]
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
- putVLC(value)
78
+ @syms.values.detect{|s|s.val == nameOrVal.to_i}
101
79
  end
102
80
  end
103
81
 
@@ -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
@@ -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 != schema
62
- @schema = nil
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
@@ -22,7 +22,10 @@ module SlowBlink
22
22
  class Group
23
23
 
24
24
  include Annotatable
25
- extend CompactEncoder
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 != 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.value.is_a?(Group)
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
- @fields.merge(@superGroup.value.fields)
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 with duplicate name '#{f.nameWithID.name}'"
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 be a group"
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
- def fields
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 value [Hash] Blink JSON format
113
- # @param opts [Hash] options
114
- # @option opts [Symbol] :dynamic encode as dynamic group
115
- # @return [String] compact format
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