upfluence-thrift 1.1.0 → 2.3.1

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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/ext/extconf.rb +1 -4
  3. data/lib/thrift/client.rb +31 -1
  4. data/lib/thrift/definition.rb +64 -0
  5. data/lib/thrift/exceptions.rb +5 -5
  6. data/lib/thrift/middleware.rb +50 -0
  7. data/lib/thrift/processor.rb +3 -3
  8. data/lib/thrift/struct.rb +10 -10
  9. data/lib/thrift/transport/base_transport.rb +9 -7
  10. data/lib/thrift/transport/server_socket.rb +6 -6
  11. data/lib/thrift/types/known/any.rb +179 -0
  12. data/lib/thrift/types/known/any_constants.rb +17 -0
  13. data/lib/thrift/types/known/any_types.rb +43 -0
  14. data/lib/thrift/types/known/duration.rb +27 -0
  15. data/lib/thrift/types/known/duration_constants.rb +17 -0
  16. data/lib/thrift/types/known/duration_types.rb +43 -0
  17. data/lib/thrift/types/known/timestamp.rb +31 -0
  18. data/lib/thrift/types/known/timestamp_constants.rb +17 -0
  19. data/lib/thrift/types/known/timestamp_types.rb +43 -0
  20. data/lib/thrift/types/value.rb +114 -0
  21. data/lib/thrift/types/value_constants.rb +15 -0
  22. data/lib/thrift/types/value_types.rb +213 -0
  23. data/lib/thrift/types.rb +4 -4
  24. data/lib/thrift.rb +6 -4
  25. data/spec/binary_protocol_spec_shared.rb +57 -60
  26. data/spec/client_spec.rb +2 -2
  27. data/spec/compact_protocol_spec.rb +26 -20
  28. data/spec/http_client_spec.rb +7 -20
  29. data/spec/nonblocking_server_spec.rb +1 -1
  30. data/spec/processor_spec.rb +1 -1
  31. data/spec/struct_spec.rb +2 -2
  32. data/spec/types/known/any_spec.rb +44 -0
  33. data/spec/types/known/duration_spec.rb +20 -0
  34. data/spec/types/known/timestamp_spec.rb +17 -0
  35. data/spec/types/value_spec.rb +43 -0
  36. data/spec/types_spec.rb +2 -2
  37. metadata +114 -150
  38. data/benchmark/gen-rb/benchmark_constants.rb +0 -11
  39. data/benchmark/gen-rb/benchmark_service.rb +0 -91
  40. data/benchmark/gen-rb/benchmark_types.rb +0 -10
  41. data/spec/gen-rb/base/base_service.rb +0 -91
  42. data/spec/gen-rb/base/base_service_constants.rb +0 -11
  43. data/spec/gen-rb/base/base_service_types.rb +0 -26
  44. data/spec/gen-rb/extended/extended_service.rb +0 -89
  45. data/spec/gen-rb/extended/extended_service_constants.rb +0 -11
  46. data/spec/gen-rb/extended/extended_service_types.rb +0 -12
  47. data/spec/gen-rb/flat/namespaced_nonblocking_service.rb +0 -299
  48. data/spec/gen-rb/flat/referenced_constants.rb +0 -11
  49. data/spec/gen-rb/flat/referenced_types.rb +0 -17
  50. data/spec/gen-rb/flat/thrift_namespaced_spec_constants.rb +0 -11
  51. data/spec/gen-rb/flat/thrift_namespaced_spec_types.rb +0 -28
  52. data/spec/gen-rb/namespaced_spec_namespace/namespaced_nonblocking_service.rb +0 -299
  53. data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_constants.rb +0 -11
  54. data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_types.rb +0 -28
  55. data/spec/gen-rb/nonblocking_service.rb +0 -299
  56. data/spec/gen-rb/other_namespace/referenced_constants.rb +0 -11
  57. data/spec/gen-rb/other_namespace/referenced_types.rb +0 -17
  58. data/spec/gen-rb/thrift_spec_constants.rb +0 -11
  59. data/spec/gen-rb/thrift_spec_types.rb +0 -538
  60. data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +0 -274
  61. data/test/debug_proto/gen-rb/debug_proto_test_types.rb +0 -761
  62. data/test/debug_proto/gen-rb/empty_service.rb +0 -31
  63. data/test/debug_proto/gen-rb/inherited.rb +0 -90
  64. data/test/debug_proto/gen-rb/reverse_order_service.rb +0 -93
  65. data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +0 -92
  66. data/test/debug_proto/gen-rb/srv.rb +0 -361
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86be9e073b58c320330f5ac9f55b33d9886939785ae72282dc54d1682060352a
4
- data.tar.gz: 3f057f5442bc6e9faf3a35e276210ffd4789bf561f1e70a934cfbb747b8dfa29
3
+ metadata.gz: 65c3e787432bc70631ee206f1118e8da08d4c274d06c26fcc531ec2ebb03c26f
4
+ data.tar.gz: b906595d1faa44c761062d44baec1e4b4eb96cd5dfb0174ac4bbb68d5ff3d6f8
5
5
  SHA512:
6
- metadata.gz: 477fa6678b03f067306dc38d4041a505963666a4575c25a81b3fa4796239e21cb7c473fbc16413b9e90b0c17ba8a539685429274f851167bb6af88d1f1313891
7
- data.tar.gz: 5ae56c20604b78f69176f4b4e9b7ad8e7af0484f51b3ec1895220801c4bed08dcae3dc788b596479910d25e0ee3df884008d547d855da099e046b2184a0badae
6
+ metadata.gz: 6888cd0e99251cb5c67eb314620f00f449270e544b7593088c50fbedfcff06893595c167e13031502ed8134608c03fd6510eaa21c10945a5cb404c1e22fe72bc
7
+ data.tar.gz: 9df5b7919319e943cd76e8ed28a8c24111d859cbb895033357aacb5fc24930cad9bfcf1ab8fa540c405fd15eb7fe40023f4b0aca8d96dfb796f68f3fc780022b
data/ext/extconf.rb CHANGED
@@ -23,10 +23,7 @@ else
23
23
  require 'mkmf'
24
24
  require 'rbconfig'
25
25
 
26
- $ARCH_FLAGS = RbConfig::CONFIG['CFLAGS'].scan( /(-arch )(\S+)/ ).map{|x,y| x + y + ' ' }.join('')
27
-
28
-
29
- $CFLAGS = "-fsigned-char -g -O2 -Wall -Werror " + $ARCH_FLAGS
26
+ $CFLAGS += " -fsigned-char"
30
27
 
31
28
  have_func("strlcpy", "string.h")
32
29
 
data/lib/thrift/client.rb CHANGED
@@ -16,10 +16,11 @@
16
16
  # specific language governing permissions and limitations
17
17
  # under the License.
18
18
  #
19
+ #
19
20
 
20
21
  module Thrift
21
22
  module Client
22
- def initialize(iprot, oprot=nil)
23
+ def initialize(iprot, oprot = nil)
23
24
  @iprot = iprot
24
25
  @oprot = oprot || iprot
25
26
  @seqid = 0
@@ -39,9 +40,15 @@ module Thrift
39
40
 
40
41
  def send_message_args(args_class, args)
41
42
  data = args_class.new
43
+
42
44
  args.each do |k, v|
43
45
  data.send("#{k.to_s}=", v)
44
46
  end
47
+
48
+ send_message_instance(data)
49
+ end
50
+
51
+ def send_message_instance(data)
45
52
  begin
46
53
  data.write(@oprot)
47
54
  rescue StandardError => e
@@ -86,4 +93,27 @@ module Thrift
86
93
  raise x
87
94
  end
88
95
  end
96
+
97
+ class BaseClient
98
+ include Client
99
+
100
+ def call_unary(name, req)
101
+ @oprot.write_message_begin(name, Thrift::MessageTypes::ONEWAY, @seqid)
102
+ send_message_instance(req)
103
+ end
104
+
105
+ def call_binary(name, req, resp_klass)
106
+ @oprot.write_message_begin(name, Thrift::MessageTypes::CALL, @seqid)
107
+ send_message_instance(req)
108
+ receive_message(resp_klass)
109
+ end
110
+ end
111
+
112
+ class << self
113
+ def build_client(input)
114
+ return BaseClient.new(input) if input.is_a? BaseProtocol
115
+
116
+ input
117
+ end
118
+ end
89
119
  end
@@ -0,0 +1,64 @@
1
+ module Thrift
2
+ class StructDefinition
3
+ attr_reader :klass
4
+
5
+ def initialize(klass)
6
+ @klass = klass
7
+ end
8
+
9
+ def namespace
10
+ @klass::NAMESPACE
11
+ end
12
+
13
+ def name
14
+ @klass::NAME
15
+ end
16
+
17
+ def struct_type
18
+ "#{namespace}.#{name}"
19
+ end
20
+ end
21
+
22
+ class ServiceDefinition < StructDefinition
23
+ attr_reader :klass
24
+
25
+ def initialize(klass)
26
+ @klass = klass
27
+ end
28
+
29
+ def client_class
30
+ @klass::Client
31
+ end
32
+
33
+ def processor_class
34
+ @klass::Processor
35
+ end
36
+
37
+ def namespace
38
+ @klass::NAMESPACE
39
+ end
40
+
41
+ def service
42
+ @klass::SERVICE
43
+ end
44
+
45
+ def service_type
46
+ "#{namespace}.#{service}"
47
+ end
48
+ end
49
+
50
+ STRUCT_DEFINITIONS = {}
51
+ SERVICE_DEFINITIONS = {}
52
+
53
+ class << self
54
+ def register_struct_type(klass)
55
+ definition = StructDefinition.new(klass)
56
+ STRUCT_DEFINITIONS[definition.struct_type] = definition
57
+ end
58
+
59
+ def register_service_type(klass)
60
+ definition = ServiceDefinition.new(klass)
61
+ SERVICE_DEFINITIONS[definition.service_type] = definition
62
+ end
63
+ end
64
+ end
@@ -1,4 +1,4 @@
1
- #
1
+ #
2
2
  # Licensed to the Apache Software Foundation (ASF) under one
3
3
  # or more contributor license agreements. See the NOTICE file
4
4
  # distributed with this work for additional information
@@ -6,21 +6,21 @@
6
6
  # to you under the Apache License, Version 2.0 (the
7
7
  # "License"); you may not use this file except in compliance
8
8
  # with the License. You may obtain a copy of the License at
9
- #
9
+ #
10
10
  # http://www.apache.org/licenses/LICENSE-2.0
11
- #
11
+ #
12
12
  # Unless required by applicable law or agreed to in writing,
13
13
  # software distributed under the License is distributed on an
14
14
  # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
15
  # KIND, either express or implied. See the License for the
16
16
  # specific language governing permissions and limitations
17
17
  # under the License.
18
- #
18
+ #
19
19
 
20
20
  module Thrift
21
21
  class Exception < StandardError
22
22
  def initialize(message)
23
- super
23
+ super(message)
24
24
  @message = message
25
25
  end
26
26
 
@@ -0,0 +1,50 @@
1
+ module Thrift
2
+ module Middleware
3
+ class NopMiddleware
4
+ def handle_binary(_mth, args = {}, &block)
5
+ block.call(args)
6
+ end
7
+
8
+ def handle_unary(_mth, args = {}, &block)
9
+ block.call(args)
10
+ end
11
+ end
12
+
13
+ class MultiMiddleware
14
+ def initialize(middlewares)
15
+ @middlewares = middlewares
16
+ end
17
+
18
+ def handle_unary(mth, args = {}, &block)
19
+ @middlewares.reverse.reduce(block) do |acc, m|
20
+ Proc.new do |args|
21
+ m.handle_unary(mth, args) { |args| acc.call(args) }
22
+ end
23
+ end.call(args)
24
+ end
25
+
26
+ def handle_binary(mth, args = {}, &block)
27
+ @middlewares.reverse.reduce(block) do |acc, m|
28
+ Proc.new do |args|
29
+ m.handle_binary(mth, args) { |args| acc.call(args) }
30
+ end
31
+ end.call(args)
32
+ end
33
+ end
34
+
35
+ NOP_MIDDLEWARE = NopMiddleware.new
36
+
37
+ class << self
38
+ def wrap(middlewares)
39
+ case middlewares.length
40
+ when 0
41
+ NOP_MIDDLEWARE
42
+ when 1
43
+ middlewares.first
44
+ else
45
+ MultiMiddleware.new(middlewares)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -19,8 +19,9 @@
19
19
 
20
20
  module Thrift
21
21
  module Processor
22
- def initialize(handler)
22
+ def initialize(handler, middlewares = [])
23
23
  @handler = handler
24
+ @middleware = Middleware.wrap(middlewares)
24
25
  end
25
26
 
26
27
  def process(iprot, oprot)
@@ -31,7 +32,6 @@ module Thrift
31
32
  rescue => e
32
33
  write_exception(e, oprot, name, seqid)
33
34
  end
34
-
35
35
  true
36
36
  else
37
37
  iprot.skip(Types::STRUCT)
@@ -39,7 +39,7 @@ module Thrift
39
39
  write_exception(
40
40
  ApplicationException.new(
41
41
  ApplicationException::UNKNOWN_METHOD,
42
- 'Unknown function '+name,
42
+ 'Unknown function ' + name,
43
43
  ),
44
44
  oprot,
45
45
  name,
data/lib/thrift/struct.rb CHANGED
@@ -1,4 +1,4 @@
1
- #
1
+ #
2
2
  # Licensed to the Apache Software Foundation (ASF) under one
3
3
  # or more contributor license agreements. See the NOTICE file
4
4
  # distributed with this work for additional information
@@ -6,16 +6,16 @@
6
6
  # to you under the Apache License, Version 2.0 (the
7
7
  # "License"); you may not use this file except in compliance
8
8
  # with the License. You may obtain a copy of the License at
9
- #
9
+ #
10
10
  # http://www.apache.org/licenses/LICENSE-2.0
11
- #
11
+ #
12
12
  # Unless required by applicable law or agreed to in writing,
13
13
  # software distributed under the License is distributed on an
14
14
  # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
15
  # KIND, either express or implied. See the License for the
16
16
  # specific language governing permissions and limitations
17
17
  # under the License.
18
- #
18
+ #
19
19
 
20
20
  require 'set'
21
21
 
@@ -24,15 +24,15 @@ module Thrift
24
24
  def initialize(d={}, &block)
25
25
  # get a copy of the default values to work on, removing defaults in favor of arguments
26
26
  fields_with_defaults = fields_with_default_values.dup
27
-
28
- # check if the defaults is empty, or if there are no parameters for this
27
+
28
+ # check if the defaults is empty, or if there are no parameters for this
29
29
  # instantiation, and if so, don't bother overriding defaults.
30
30
  unless fields_with_defaults.empty? || d.empty?
31
31
  d.each_key do |name|
32
32
  fields_with_defaults.delete(name.to_s)
33
33
  end
34
34
  end
35
-
35
+
36
36
  # assign all the user-specified arguments
37
37
  unless d.empty?
38
38
  d.each do |name, value|
@@ -43,14 +43,14 @@ module Thrift
43
43
  instance_variable_set("@#{name}", value)
44
44
  end
45
45
  end
46
-
46
+
47
47
  # assign all the default values
48
48
  unless fields_with_defaults.empty?
49
49
  fields_with_defaults.each do |name, default_value|
50
50
  instance_variable_set("@#{name}", (default_value.dup rescue default_value))
51
51
  end
52
52
  end
53
-
53
+
54
54
  yield self if block_given?
55
55
  end
56
56
 
@@ -67,7 +67,7 @@ module Thrift
67
67
  end
68
68
  fields_with_default_values
69
69
  end
70
-
70
+
71
71
  def inspect(skip_optional_nulls = true)
72
72
  fields = []
73
73
  each_field do |fid, field_info|
@@ -1,5 +1,5 @@
1
1
  # encoding: ascii-8bit
2
- #
2
+ #
3
3
  # Licensed to the Apache Software Foundation (ASF) under one
4
4
  # or more contributor license agreements. See the NOTICE file
5
5
  # distributed with this work for additional information
@@ -7,16 +7,16 @@
7
7
  # to you under the Apache License, Version 2.0 (the
8
8
  # "License"); you may not use this file except in compliance
9
9
  # with the License. You may obtain a copy of the License at
10
- #
10
+ #
11
11
  # http://www.apache.org/licenses/LICENSE-2.0
12
- #
12
+ #
13
13
  # Unless required by applicable law or agreed to in writing,
14
14
  # software distributed under the License is distributed on an
15
15
  # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
16
  # KIND, either express or implied. See the License for the
17
17
  # specific language governing permissions and limitations
18
18
  # under the License.
19
- #
19
+ #
20
20
 
21
21
  module Thrift
22
22
  class TransportException < Exception
@@ -48,7 +48,7 @@ module Thrift
48
48
 
49
49
  class BaseTransport
50
50
  def open?; end
51
-
51
+
52
52
  def open; end
53
53
 
54
54
  def close; end
@@ -62,6 +62,8 @@ module Thrift
62
62
  raise NotImplementedError
63
63
  end
64
64
 
65
+ def set_context(ctx); end
66
+
65
67
  # Returns an unsigned byte as a Fixnum in the range (0..255).
66
68
  def read_byte
67
69
  buf = read_all(1)
@@ -86,7 +88,7 @@ module Thrift
86
88
  chunk = read(size - buf.length)
87
89
  buf << chunk
88
90
  end
89
-
91
+
90
92
  buf
91
93
  end
92
94
 
@@ -100,7 +102,7 @@ module Thrift
100
102
 
101
103
  def flush; end
102
104
  end
103
-
105
+
104
106
  class BaseTransportFactory
105
107
  def get_transport(trans)
106
108
  return trans
@@ -1,5 +1,5 @@
1
1
  # encoding: ascii-8bit
2
- #
2
+ #
3
3
  # Licensed to the Apache Software Foundation (ASF) under one
4
4
  # or more contributor license agreements. See the NOTICE file
5
5
  # distributed with this work for additional information
@@ -7,16 +7,16 @@
7
7
  # to you under the Apache License, Version 2.0 (the
8
8
  # "License"); you may not use this file except in compliance
9
9
  # with the License. You may obtain a copy of the License at
10
- #
10
+ #
11
11
  # http://www.apache.org/licenses/LICENSE-2.0
12
- #
12
+ #
13
13
  # Unless required by applicable law or agreed to in writing,
14
14
  # software distributed under the License is distributed on an
15
15
  # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
16
  # KIND, either express or implied. See the License for the
17
17
  # specific language governing permissions and limitations
18
18
  # under the License.
19
- #
19
+ #
20
20
 
21
21
  require 'socket'
22
22
 
@@ -37,7 +37,7 @@ module Thrift
37
37
  attr_reader :handle
38
38
 
39
39
  def listen
40
- @handle = TCPServer.new(@host, @port)
40
+ @handle ||= TCPServer.new(@host, @port)
41
41
  end
42
42
 
43
43
  def accept
@@ -60,4 +60,4 @@ module Thrift
60
60
 
61
61
  alias to_io handle
62
62
  end
63
- end
63
+ end
@@ -0,0 +1,179 @@
1
+ require 'thrift/types/known/any_types'
2
+ require 'json'
3
+ require 'yaml'
4
+
5
+ module Thrift
6
+ module Types
7
+ module Known
8
+ module Any
9
+ class CustomYAML
10
+ class << self
11
+ def dump(obj)
12
+ YAML.dump(obj)[4..-1]
13
+ end
14
+
15
+ def load(val)
16
+ YAML.safe_load(val)
17
+ end
18
+ end
19
+ end
20
+
21
+ class MetaCodec
22
+ def initialize(klass)
23
+ @klass = klass
24
+ end
25
+
26
+ def encode(obj)
27
+ @klass.dump(to_hash(obj))
28
+ end
29
+
30
+ def decode(buf, obj)
31
+ from_hash(obj, @klass.load(buf))
32
+ end
33
+
34
+ private
35
+
36
+ def to_hash(obj)
37
+ to_hash_field(obj, type: Thrift::Types::STRUCT)
38
+ end
39
+
40
+ def to_hash_field(value, field)
41
+ case field[:type]
42
+ when Thrift::Types::STRUCT
43
+ value.struct_fields.values.reduce({}) do |acc, sfield|
44
+ name = sfield[:name]
45
+ vv = value.send("#{name}?") ? to_hash_field(value.send(name), sfield) : nil
46
+ vv.nil? ? acc : acc.merge(name => vv)
47
+ end
48
+ when Thrift::Types::LIST
49
+ value.map { |vv| to_hash_field(vv, field[:element]) }
50
+ when Thrift::Types::MAP
51
+ value.reduce({}) do |acc, (k, v)|
52
+ kv = to_hash_field(k, field[:key])
53
+ vv = to_hash_field(v, field[:value])
54
+
55
+ acc.merge(kv => vv)
56
+ end
57
+ else
58
+ value
59
+ end
60
+ end
61
+
62
+ def from_hash(obj, hash)
63
+ return nil if hash.nil?
64
+
65
+ obj.struct_fields.values.each do |field|
66
+ name = field[:name]
67
+ value = hash[name]
68
+
69
+ obj.send("#{name}=", from_value_field(value, field)) if value
70
+ end
71
+
72
+ obj
73
+ end
74
+
75
+ def from_value_field(value, field)
76
+ case field[:type]
77
+ when Thrift::Types::STRUCT
78
+ from_hash(field[:class].new, value)
79
+ when Thrift::Types::LIST
80
+ value.map { |vv| from_value_field(vv, field[:element]) }
81
+ when Thrift::Types::MAP
82
+ value.reduce({}) do |acc, (k, v)|
83
+ kv = from_value_field(k, field[:key])
84
+ vv = from_value_field(v, field[:value])
85
+ acc.merge(kv => vv)
86
+ end
87
+ else
88
+ value
89
+ end
90
+ end
91
+ end
92
+
93
+ class ProtocolCodec
94
+ def initialize(protocol_factory)
95
+ @protocol_factory = protocol_factory
96
+ end
97
+
98
+ def encode(obj)
99
+ Serializer.new(@protocol_factory).serialize(obj)
100
+ end
101
+
102
+ def decode(buf, obj)
103
+ obj.read(
104
+ @protocol_factory.get_protocol(MemoryBufferTransport.new(buf))
105
+ )
106
+ end
107
+ end
108
+
109
+ DEFAULT_CODEC = ProtocolCodec.new(JsonProtocolFactory.new)
110
+ JSON_CODEC = MetaCodec.new(JSON)
111
+ YAML_CODEC = MetaCodec.new(CustomYAML)
112
+
113
+ CODECS = {
114
+ '' => DEFAULT_CODEC,
115
+ 'json' => JSON_CODEC,
116
+ 'yaml' => YAML_CODEC,
117
+ 'yml' => YAML_CODEC
118
+ }
119
+
120
+
121
+ class << self
122
+ def from_object(obj, codec_key = '')
123
+ Any.from_object(obj, codec_key)
124
+ end
125
+ end
126
+
127
+ class Any
128
+ class TypeNotHandled < StandardError; end
129
+ class CodecNotHandled < StandardError; end
130
+
131
+ class << self
132
+ def from_object(obj, codec_key = '')
133
+ struct_def = Thrift::STRUCT_DEFINITIONS.values.find do |v|
134
+ obj.is_a? v.klass
135
+ end
136
+
137
+ raise TypeNotHandled unless struct_def
138
+ raise CodecNotHandled unless CODECS[codec_key]
139
+
140
+ key = codec_key.eql?('') ? '' : "-#{codec_key}"
141
+
142
+ Any.new(
143
+ type: "thrift#{key}/#{struct_def.struct_type}",
144
+ value: CODECS[codec_key].encode(obj)
145
+ )
146
+ end
147
+ end
148
+
149
+ def to_object
150
+ codec_key, struct_type = parse_type
151
+
152
+ raise TypeNotHandled unless Thrift::STRUCT_DEFINITIONS[struct_type]
153
+ raise CodecNotHandled unless CODECS[codec_key]
154
+
155
+ res = Thrift::STRUCT_DEFINITIONS[struct_type].klass.new
156
+ CODECS[codec_key].decode(value, res)
157
+
158
+ res
159
+ end
160
+
161
+ private
162
+
163
+ def parse_type
164
+ ts = type.split('/')
165
+
166
+ if ts.length != 2 || (ts[0] =~ /^thrift-?/) != 0
167
+ raise TypeNotHandled.new
168
+ end
169
+
170
+ codec = ts[0][6..-1]
171
+ codec = codec[1..-1] if codec[0].eql?('-')
172
+
173
+ [codec, ts[1]]
174
+ end
175
+ end
176
+ end
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,17 @@
1
+ #
2
+ # Autogenerated by Thrift Compiler (2.3.0-upfluence)
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+
7
+ require 'thrift'
8
+ require 'any_types'
9
+
10
+ module Thrift
11
+ module Types
12
+ module Known
13
+ module Any
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,43 @@
1
+ #
2
+ # Autogenerated by Thrift Compiler (2.3.0-upfluence)
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+
7
+ require 'thrift'
8
+
9
+ module Thrift
10
+ module Types
11
+ module Known
12
+ module Any
13
+ class Any; end
14
+
15
+ class Any
16
+ include ::Thrift::Struct, ::Thrift::Struct_Union
17
+
18
+ NAME = 'Any'.freeze
19
+ NAMESPACE = 'types.known.any'.freeze
20
+
21
+ THRIFT_FIELD_INDEX_TYPE = 1
22
+ THRIFT_FIELD_INDEX_VALUE = 2
23
+
24
+ FIELDS = {
25
+ THRIFT_FIELD_INDEX_TYPE => {type: ::Thrift::Types::STRING, name: 'type'},
26
+ THRIFT_FIELD_INDEX_VALUE => {type: ::Thrift::Types::STRING, name: 'value', binary: true}
27
+ }
28
+
29
+ def struct_fields; FIELDS; end
30
+
31
+ def validate
32
+ raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field type is unset!') unless @type
33
+ raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field value is unset!') unless @value
34
+ end
35
+
36
+ ::Thrift::Struct.generate_accessors self
37
+ ::Thrift.register_struct_type self
38
+ end
39
+
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,27 @@
1
+ require 'thrift/types/known/duration_types'
2
+
3
+ module Thrift
4
+ module Types
5
+ module Known
6
+ module Duration
7
+ class << self
8
+ def from_number(v)
9
+ Duration.from_number(v)
10
+ end
11
+ end
12
+
13
+ class Duration
14
+ class << self
15
+ def from_number(v)
16
+ Duration.new(seconds: v.to_i, nanos: ((v % 1) * 1e9).to_i)
17
+ end
18
+ end
19
+
20
+ def to_number
21
+ seconds + nanos / 1e9
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end