upfluence-thrift 1.0.11 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/thrift.rb +6 -4
- data/lib/thrift/client.rb +31 -1
- data/lib/thrift/definition.rb +64 -0
- data/lib/thrift/exceptions.rb +5 -5
- data/lib/thrift/middleware.rb +50 -0
- data/lib/thrift/processor.rb +3 -3
- data/lib/thrift/protocol/json_protocol.rb +6 -6
- data/lib/thrift/server/rack_application.rb +30 -19
- data/lib/thrift/struct.rb +10 -10
- data/lib/thrift/transport/base_transport.rb +9 -7
- data/lib/thrift/transport/server_socket.rb +6 -6
- data/lib/thrift/types.rb +4 -4
- data/lib/thrift/types/known/any.rb +179 -0
- data/lib/thrift/types/known/any_constants.rb +17 -0
- data/lib/thrift/types/known/any_types.rb +43 -0
- data/lib/thrift/types/known/duration.rb +27 -0
- data/lib/thrift/types/known/duration_constants.rb +17 -0
- data/lib/thrift/types/known/duration_types.rb +43 -0
- data/lib/thrift/types/known/timestamp.rb +31 -0
- data/lib/thrift/types/known/timestamp_constants.rb +17 -0
- data/lib/thrift/types/known/timestamp_types.rb +43 -0
- data/lib/thrift/types/value.rb +114 -0
- data/lib/thrift/types/value_constants.rb +15 -0
- data/lib/thrift/types/value_types.rb +213 -0
- data/spec/binary_protocol_spec_shared.rb +57 -60
- data/spec/client_spec.rb +2 -2
- data/spec/compact_protocol_spec.rb +26 -20
- data/spec/http_client_spec.rb +7 -20
- data/spec/nonblocking_server_spec.rb +1 -1
- data/spec/processor_spec.rb +1 -1
- data/spec/rack_application_spec.rb +1 -1
- data/spec/struct_spec.rb +2 -2
- data/spec/types/known/any_spec.rb +44 -0
- data/spec/types/known/duration_spec.rb +20 -0
- data/spec/types/known/timestamp_spec.rb +17 -0
- data/spec/types/value_spec.rb +43 -0
- data/spec/types_spec.rb +2 -2
- metadata +50 -87
- data/benchmark/gen-rb/benchmark_constants.rb +0 -11
- data/benchmark/gen-rb/benchmark_service.rb +0 -80
- data/benchmark/gen-rb/benchmark_types.rb +0 -10
- data/spec/gen-rb/base/base_service.rb +0 -80
- data/spec/gen-rb/base/base_service_constants.rb +0 -11
- data/spec/gen-rb/base/base_service_types.rb +0 -26
- data/spec/gen-rb/extended/extended_service.rb +0 -78
- data/spec/gen-rb/extended/extended_service_constants.rb +0 -11
- data/spec/gen-rb/extended/extended_service_types.rb +0 -12
- data/spec/gen-rb/flat/namespaced_nonblocking_service.rb +0 -272
- data/spec/gen-rb/flat/referenced_constants.rb +0 -11
- data/spec/gen-rb/flat/referenced_types.rb +0 -17
- data/spec/gen-rb/flat/thrift_namespaced_spec_constants.rb +0 -11
- data/spec/gen-rb/flat/thrift_namespaced_spec_types.rb +0 -28
- data/spec/gen-rb/namespaced_spec_namespace/namespaced_nonblocking_service.rb +0 -272
- data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_constants.rb +0 -11
- data/spec/gen-rb/namespaced_spec_namespace/thrift_namespaced_spec_types.rb +0 -28
- data/spec/gen-rb/nonblocking_service.rb +0 -272
- data/spec/gen-rb/other_namespace/referenced_constants.rb +0 -11
- data/spec/gen-rb/other_namespace/referenced_types.rb +0 -17
- data/spec/gen-rb/thrift_spec_constants.rb +0 -11
- data/spec/gen-rb/thrift_spec_types.rb +0 -538
- data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +0 -274
- data/test/debug_proto/gen-rb/debug_proto_test_types.rb +0 -761
- data/test/debug_proto/gen-rb/empty_service.rb +0 -24
- data/test/debug_proto/gen-rb/inherited.rb +0 -79
- data/test/debug_proto/gen-rb/reverse_order_service.rb +0 -82
- data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +0 -81
- data/test/debug_proto/gen-rb/srv.rb +0 -330
@@ -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
|
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
|
data/lib/thrift/types.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
|
|
@@ -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
|
@@ -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 'duration_types'
|
9
|
+
|
10
|
+
module Thrift
|
11
|
+
module Types
|
12
|
+
module Known
|
13
|
+
module Duration
|
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 Duration
|
13
|
+
class Duration; end
|
14
|
+
|
15
|
+
class Duration
|
16
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
17
|
+
|
18
|
+
NAME = 'Duration'.freeze
|
19
|
+
NAMESPACE = 'types.known.duration'.freeze
|
20
|
+
|
21
|
+
THRIFT_FIELD_INDEX_SECONDS = 1
|
22
|
+
THRIFT_FIELD_INDEX_NANOS = 2
|
23
|
+
|
24
|
+
FIELDS = {
|
25
|
+
THRIFT_FIELD_INDEX_SECONDS => {type: ::Thrift::Types::I64, name: 'seconds'},
|
26
|
+
THRIFT_FIELD_INDEX_NANOS => {type: ::Thrift::Types::I32, name: 'nanos'}
|
27
|
+
}
|
28
|
+
|
29
|
+
def struct_fields; FIELDS; end
|
30
|
+
|
31
|
+
def validate
|
32
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field seconds is unset!') unless @seconds
|
33
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field nanos is unset!') unless @nanos
|
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
|