upfluence-thrift 1.1.0 → 2.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86be9e073b58c320330f5ac9f55b33d9886939785ae72282dc54d1682060352a
4
- data.tar.gz: 3f057f5442bc6e9faf3a35e276210ffd4789bf561f1e70a934cfbb747b8dfa29
3
+ metadata.gz: 481691bbd3c9c8992c7f545a9abe7cc0107e20e40eab8440571b9c5d6c56755b
4
+ data.tar.gz: 2221fd56c4c25e33cdd4828462db6313f685c794307a13b59cb83342b2a62ef1
5
5
  SHA512:
6
- metadata.gz: 477fa6678b03f067306dc38d4041a505963666a4575c25a81b3fa4796239e21cb7c473fbc16413b9e90b0c17ba8a539685429274f851167bb6af88d1f1313891
7
- data.tar.gz: 5ae56c20604b78f69176f4b4e9b7ad8e7af0484f51b3ec1895220801c4bed08dcae3dc788b596479910d25e0ee3df884008d547d855da099e046b2184a0badae
6
+ metadata.gz: faf079e2e92bc4b3b7b9975d18e4f49259341e541e6805fed6951a2fd3ed9205c6bd9a9574e5c6ff2b610eef6aebdd97718da2dc4c009f9a372227d306546a5e
7
+ data.tar.gz: a964e13eb46f9c85fd945e25c562426bdb83ee2cb2f1378432fe777a530247476050e6ac2d01ae99e1d0ecbb4ad9f9bd1b2fbcfcf80ea3db443d9cf030db209f
data/lib/thrift.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,28 +6,30 @@
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
  # Contains some contributions under the Thrift Software License.
20
20
  # Please see doc/old-thrift-license.txt in the Thrift distribution for
21
21
  # details.
22
22
 
23
23
  $:.unshift File.dirname(__FILE__)
24
24
 
25
+ require 'thrift/definition'
25
26
  require 'thrift/bytes'
26
27
  require 'thrift/core_ext'
27
28
  require 'thrift/exceptions'
28
29
  require 'thrift/types'
29
30
  require 'thrift/processor'
30
31
  require 'thrift/multiplexed_processor'
32
+ require 'thrift/middleware'
31
33
  require 'thrift/client'
32
34
  require 'thrift/struct'
33
35
  require 'thrift/union'
data/lib/thrift/client.rb CHANGED
@@ -16,12 +16,21 @@
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, middlewares = [], oprot = nil)
23
24
  @iprot = iprot
24
25
  @oprot = oprot || iprot
26
+ @middleware = case middlewares.length
27
+ when 0
28
+ Middleware::NOP_MIDDLEWARE
29
+ when 1
30
+ middlewares.first
31
+ else
32
+ Middleware::MultiMiddleware.new(middlewares)
33
+ end
25
34
  @seqid = 0
26
35
  end
27
36
 
@@ -0,0 +1,24 @@
1
+ module Thrift
2
+ class StructDefinition
3
+ attr_reader :namespace, :name, :klass
4
+ def initialize(klass)
5
+ @namespace = klass::NAMESPACE
6
+ @name = klass::NAME
7
+ @klass = klass
8
+ end
9
+
10
+ def struct_type
11
+ "#{@namespace}.#{@name}"
12
+ end
13
+ end
14
+
15
+ STRUCT_DEFINITIONS = {}
16
+
17
+ class << self
18
+
19
+ def register_struct_type(klass)
20
+ definition = StructDefinition.new(klass)
21
+ STRUCT_DEFINITIONS[definition.struct_type] = definition
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,37 @@
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
+ end
37
+ end
@@ -19,8 +19,16 @@
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 = case middlewares.length
25
+ when 0
26
+ Middleware::NOP_MIDDLEWARE
27
+ when 1
28
+ middlewares.first
29
+ else
30
+ Middleware::MultiMiddleware.new(middlewares)
31
+ end
24
32
  end
25
33
 
26
34
  def process(iprot, oprot)
@@ -31,7 +39,6 @@ module Thrift
31
39
  rescue => e
32
40
  write_exception(e, oprot, name, seqid)
33
41
  end
34
-
35
42
  true
36
43
  else
37
44
  iprot.skip(Types::STRUCT)
@@ -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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upfluence-thrift
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thrift Developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-25 00:00:00.000000000 Z
11
+ date: 2020-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -138,6 +138,7 @@ extra_rdoc_files:
138
138
  - lib/thrift/core_ext.rb
139
139
  - lib/thrift/struct_union.rb
140
140
  - lib/thrift/struct.rb
141
+ - lib/thrift/middleware.rb
141
142
  - lib/thrift/union.rb
142
143
  - lib/thrift/serializer/serializer.rb
143
144
  - lib/thrift/serializer/deserializer.rb
@@ -154,6 +155,7 @@ extra_rdoc_files:
154
155
  - lib/thrift/transport/http_client_transport.rb
155
156
  - lib/thrift/bytes.rb
156
157
  - lib/thrift/core_ext/fixnum.rb
158
+ - lib/thrift/definition.rb
157
159
  - lib/thrift/multiplexed_processor.rb
158
160
  - lib/thrift/thrift_native.rb
159
161
  - lib/thrift/exceptions.rb
@@ -209,8 +211,10 @@ files:
209
211
  - lib/thrift/client.rb
210
212
  - lib/thrift/core_ext.rb
211
213
  - lib/thrift/core_ext/fixnum.rb
214
+ - lib/thrift/definition.rb
212
215
  - lib/thrift/exceptions.rb
213
216
  - lib/thrift/metrics.rb
217
+ - lib/thrift/middleware.rb
214
218
  - lib/thrift/multiplexed_processor.rb
215
219
  - lib/thrift/processor.rb
216
220
  - lib/thrift/protocol/base_protocol.rb