thrift 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/InstalledFiles +1 -0
- data/Makefile +512 -0
- data/Makefile.am +3 -1
- data/Makefile.in +117 -45
- data/Manifest +17 -0
- data/Rakefile +6 -8
- data/benchmark/gen-rb/benchmark_constants.rb +10 -0
- data/benchmark/gen-rb/benchmark_service.rb +80 -0
- data/benchmark/gen-rb/benchmark_types.rb +9 -0
- data/debug_proto_test/gen-rb/debug_proto_test_constants.rb +273 -0
- data/debug_proto_test/gen-rb/debug_proto_test_types.rb +705 -0
- data/debug_proto_test/gen-rb/empty_service.rb +24 -0
- data/debug_proto_test/gen-rb/inherited.rb +79 -0
- data/debug_proto_test/gen-rb/reverse_order_service.rb +82 -0
- data/debug_proto_test/gen-rb/service_for_exception_with_a_map.rb +81 -0
- data/debug_proto_test/gen-rb/srv.rb +330 -0
- data/ext/binary_protocol_accelerated.c +24 -11
- data/ext/compact_protocol.c +14 -11
- data/ext/constants.h +1 -0
- data/ext/memory_buffer.c +56 -1
- data/ext/struct.c +76 -19
- data/ext/thrift_native.c +2 -0
- data/lib/thrift/exceptions.rb +3 -1
- data/lib/thrift/protocol/binary_protocol.rb +14 -10
- data/lib/thrift/protocol/compact_protocol.rb +7 -4
- data/lib/thrift/server/nonblocking_server.rb +15 -5
- data/lib/thrift/struct.rb +9 -6
- data/lib/thrift/struct_union.rb +47 -14
- data/lib/thrift/transport/base_transport.rb +39 -2
- data/lib/thrift/transport/buffered_transport.rb +31 -0
- data/lib/thrift/transport/framed_transport.rb +26 -0
- data/lib/thrift/transport/memory_buffer_transport.rb +29 -0
- data/spec/binary_protocol_spec.rb +2 -4
- data/spec/gen-rb/nonblocking_service.rb +272 -0
- data/spec/gen-rb/thrift_spec_constants.rb +10 -0
- data/spec/gen-rb/thrift_spec_types.rb +345 -0
- data/spec/spec_helper.rb +1 -3
- data/thrift.gemspec +10 -11
- data/tmp/thrift-0.7.0.gem +0 -0
- metadata +22 -8
@@ -52,6 +52,32 @@ module Thrift
|
|
52
52
|
@rbuf.slice(@index - sz, sz) || ''
|
53
53
|
end
|
54
54
|
|
55
|
+
def read_byte
|
56
|
+
return @transport.read_byte() unless @read
|
57
|
+
|
58
|
+
read_frame if @index >= @rbuf.length
|
59
|
+
|
60
|
+
# The read buffer has some data now, read a single byte. Using get_string_byte() avoids
|
61
|
+
# allocating a temp string of size 1 unnecessarily.
|
62
|
+
@index += 1
|
63
|
+
return ::Thrift::TransportUtils.get_string_byte(@rbuf, @index - 1)
|
64
|
+
end
|
65
|
+
|
66
|
+
def read_into_buffer(buffer, size)
|
67
|
+
i = 0
|
68
|
+
while i < size
|
69
|
+
read_frame if @index >= @rbuf.length
|
70
|
+
|
71
|
+
# The read buffer has some data now, so copy bytes over to the output buffer.
|
72
|
+
byte = ::Thrift::TransportUtils.get_string_byte(@rbuf, @index)
|
73
|
+
::Thrift::TransportUtils.set_string_byte(buffer, i, byte)
|
74
|
+
@index += 1
|
75
|
+
i += 1
|
76
|
+
end
|
77
|
+
i
|
78
|
+
end
|
79
|
+
|
80
|
+
|
55
81
|
def write(buf,sz=nil)
|
56
82
|
return @transport.write(buf) unless @write
|
57
83
|
|
@@ -70,6 +70,35 @@ module Thrift
|
|
70
70
|
data
|
71
71
|
end
|
72
72
|
|
73
|
+
def read_byte
|
74
|
+
raise EOFError.new("Not enough bytes remain in buffer") if @index >= @buf.size
|
75
|
+
val = ::Thrift::TransportUtils.get_string_byte(@buf, @index)
|
76
|
+
@index += 1
|
77
|
+
if @index >= GARBAGE_BUFFER_SIZE
|
78
|
+
@buf = @buf.slice(@index..-1)
|
79
|
+
@index = 0
|
80
|
+
end
|
81
|
+
val
|
82
|
+
end
|
83
|
+
|
84
|
+
def read_into_buffer(buffer, size)
|
85
|
+
i = 0
|
86
|
+
while i < size
|
87
|
+
raise EOFError.new("Not enough bytes remain in buffer") if @index >= @buf.size
|
88
|
+
|
89
|
+
# The read buffer has some data now, so copy bytes over to the output buffer.
|
90
|
+
byte = ::Thrift::TransportUtils.get_string_byte(@buf, @index)
|
91
|
+
::Thrift::TransportUtils.set_string_byte(buffer, i, byte)
|
92
|
+
@index += 1
|
93
|
+
i += 1
|
94
|
+
end
|
95
|
+
if @index >= GARBAGE_BUFFER_SIZE
|
96
|
+
@buf = @buf.slice(@index..-1)
|
97
|
+
@index = 0
|
98
|
+
end
|
99
|
+
i
|
100
|
+
end
|
101
|
+
|
73
102
|
def write(wbuf)
|
74
103
|
@buf << wbuf
|
75
104
|
end
|
@@ -31,10 +31,8 @@ class ThriftBinaryProtocolSpec < Spec::ExampleGroup
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should read a message header" do
|
34
|
-
@trans.
|
35
|
-
|
36
|
-
[42].pack('N')
|
37
|
-
)
|
34
|
+
@trans.write([protocol_class.const_get(:VERSION_1) | Thrift::MessageTypes::REPLY].pack('N'))
|
35
|
+
@trans.write([42].pack('N'))
|
38
36
|
@prot.should_receive(:read_string).and_return('testMessage')
|
39
37
|
@prot.read_message_begin.should == ['testMessage', Thrift::MessageTypes::REPLY, 42]
|
40
38
|
end
|
@@ -0,0 +1,272 @@
|
|
1
|
+
#
|
2
|
+
# Autogenerated by Thrift Compiler (0.7.0)
|
3
|
+
#
|
4
|
+
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'thrift'
|
8
|
+
require 'thrift_spec_types'
|
9
|
+
|
10
|
+
module SpecNamespace
|
11
|
+
module NonblockingService
|
12
|
+
class Client
|
13
|
+
include ::Thrift::Client
|
14
|
+
|
15
|
+
def greeting(english)
|
16
|
+
send_greeting(english)
|
17
|
+
return recv_greeting()
|
18
|
+
end
|
19
|
+
|
20
|
+
def send_greeting(english)
|
21
|
+
send_message('greeting', Greeting_args, :english => english)
|
22
|
+
end
|
23
|
+
|
24
|
+
def recv_greeting()
|
25
|
+
result = receive_message(Greeting_result)
|
26
|
+
return result.success unless result.success.nil?
|
27
|
+
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'greeting failed: unknown result')
|
28
|
+
end
|
29
|
+
|
30
|
+
def block()
|
31
|
+
send_block()
|
32
|
+
return recv_block()
|
33
|
+
end
|
34
|
+
|
35
|
+
def send_block()
|
36
|
+
send_message('block', Block_args)
|
37
|
+
end
|
38
|
+
|
39
|
+
def recv_block()
|
40
|
+
result = receive_message(Block_result)
|
41
|
+
return result.success unless result.success.nil?
|
42
|
+
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'block failed: unknown result')
|
43
|
+
end
|
44
|
+
|
45
|
+
def unblock(n)
|
46
|
+
send_unblock(n)
|
47
|
+
end
|
48
|
+
|
49
|
+
def send_unblock(n)
|
50
|
+
send_message('unblock', Unblock_args, :n => n)
|
51
|
+
end
|
52
|
+
def shutdown()
|
53
|
+
send_shutdown()
|
54
|
+
end
|
55
|
+
|
56
|
+
def send_shutdown()
|
57
|
+
send_message('shutdown', Shutdown_args)
|
58
|
+
end
|
59
|
+
def sleep(seconds)
|
60
|
+
send_sleep(seconds)
|
61
|
+
recv_sleep()
|
62
|
+
end
|
63
|
+
|
64
|
+
def send_sleep(seconds)
|
65
|
+
send_message('sleep', Sleep_args, :seconds => seconds)
|
66
|
+
end
|
67
|
+
|
68
|
+
def recv_sleep()
|
69
|
+
result = receive_message(Sleep_result)
|
70
|
+
return
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
class Processor
|
76
|
+
include ::Thrift::Processor
|
77
|
+
|
78
|
+
def process_greeting(seqid, iprot, oprot)
|
79
|
+
args = read_args(iprot, Greeting_args)
|
80
|
+
result = Greeting_result.new()
|
81
|
+
result.success = @handler.greeting(args.english)
|
82
|
+
write_result(result, oprot, 'greeting', seqid)
|
83
|
+
end
|
84
|
+
|
85
|
+
def process_block(seqid, iprot, oprot)
|
86
|
+
args = read_args(iprot, Block_args)
|
87
|
+
result = Block_result.new()
|
88
|
+
result.success = @handler.block()
|
89
|
+
write_result(result, oprot, 'block', seqid)
|
90
|
+
end
|
91
|
+
|
92
|
+
def process_unblock(seqid, iprot, oprot)
|
93
|
+
args = read_args(iprot, Unblock_args)
|
94
|
+
@handler.unblock(args.n)
|
95
|
+
return
|
96
|
+
end
|
97
|
+
|
98
|
+
def process_shutdown(seqid, iprot, oprot)
|
99
|
+
args = read_args(iprot, Shutdown_args)
|
100
|
+
@handler.shutdown()
|
101
|
+
return
|
102
|
+
end
|
103
|
+
|
104
|
+
def process_sleep(seqid, iprot, oprot)
|
105
|
+
args = read_args(iprot, Sleep_args)
|
106
|
+
result = Sleep_result.new()
|
107
|
+
@handler.sleep(args.seconds)
|
108
|
+
write_result(result, oprot, 'sleep', seqid)
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
# HELPER FUNCTIONS AND STRUCTURES
|
114
|
+
|
115
|
+
class Greeting_args
|
116
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
117
|
+
ENGLISH = 1
|
118
|
+
|
119
|
+
FIELDS = {
|
120
|
+
ENGLISH => {:type => ::Thrift::Types::BOOL, :name => 'english'}
|
121
|
+
}
|
122
|
+
|
123
|
+
def struct_fields; FIELDS; end
|
124
|
+
|
125
|
+
def validate
|
126
|
+
end
|
127
|
+
|
128
|
+
::Thrift::Struct.generate_accessors self
|
129
|
+
end
|
130
|
+
|
131
|
+
class Greeting_result
|
132
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
133
|
+
SUCCESS = 0
|
134
|
+
|
135
|
+
FIELDS = {
|
136
|
+
SUCCESS => {:type => ::Thrift::Types::STRUCT, :name => 'success', :class => SpecNamespace::Hello}
|
137
|
+
}
|
138
|
+
|
139
|
+
def struct_fields; FIELDS; end
|
140
|
+
|
141
|
+
def validate
|
142
|
+
end
|
143
|
+
|
144
|
+
::Thrift::Struct.generate_accessors self
|
145
|
+
end
|
146
|
+
|
147
|
+
class Block_args
|
148
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
149
|
+
|
150
|
+
FIELDS = {
|
151
|
+
|
152
|
+
}
|
153
|
+
|
154
|
+
def struct_fields; FIELDS; end
|
155
|
+
|
156
|
+
def validate
|
157
|
+
end
|
158
|
+
|
159
|
+
::Thrift::Struct.generate_accessors self
|
160
|
+
end
|
161
|
+
|
162
|
+
class Block_result
|
163
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
164
|
+
SUCCESS = 0
|
165
|
+
|
166
|
+
FIELDS = {
|
167
|
+
SUCCESS => {:type => ::Thrift::Types::BOOL, :name => 'success'}
|
168
|
+
}
|
169
|
+
|
170
|
+
def struct_fields; FIELDS; end
|
171
|
+
|
172
|
+
def validate
|
173
|
+
end
|
174
|
+
|
175
|
+
::Thrift::Struct.generate_accessors self
|
176
|
+
end
|
177
|
+
|
178
|
+
class Unblock_args
|
179
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
180
|
+
N = 1
|
181
|
+
|
182
|
+
FIELDS = {
|
183
|
+
N => {:type => ::Thrift::Types::I32, :name => 'n'}
|
184
|
+
}
|
185
|
+
|
186
|
+
def struct_fields; FIELDS; end
|
187
|
+
|
188
|
+
def validate
|
189
|
+
end
|
190
|
+
|
191
|
+
::Thrift::Struct.generate_accessors self
|
192
|
+
end
|
193
|
+
|
194
|
+
class Unblock_result
|
195
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
196
|
+
|
197
|
+
FIELDS = {
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
def struct_fields; FIELDS; end
|
202
|
+
|
203
|
+
def validate
|
204
|
+
end
|
205
|
+
|
206
|
+
::Thrift::Struct.generate_accessors self
|
207
|
+
end
|
208
|
+
|
209
|
+
class Shutdown_args
|
210
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
211
|
+
|
212
|
+
FIELDS = {
|
213
|
+
|
214
|
+
}
|
215
|
+
|
216
|
+
def struct_fields; FIELDS; end
|
217
|
+
|
218
|
+
def validate
|
219
|
+
end
|
220
|
+
|
221
|
+
::Thrift::Struct.generate_accessors self
|
222
|
+
end
|
223
|
+
|
224
|
+
class Shutdown_result
|
225
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
226
|
+
|
227
|
+
FIELDS = {
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
def struct_fields; FIELDS; end
|
232
|
+
|
233
|
+
def validate
|
234
|
+
end
|
235
|
+
|
236
|
+
::Thrift::Struct.generate_accessors self
|
237
|
+
end
|
238
|
+
|
239
|
+
class Sleep_args
|
240
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
241
|
+
SECONDS = 1
|
242
|
+
|
243
|
+
FIELDS = {
|
244
|
+
SECONDS => {:type => ::Thrift::Types::DOUBLE, :name => 'seconds'}
|
245
|
+
}
|
246
|
+
|
247
|
+
def struct_fields; FIELDS; end
|
248
|
+
|
249
|
+
def validate
|
250
|
+
end
|
251
|
+
|
252
|
+
::Thrift::Struct.generate_accessors self
|
253
|
+
end
|
254
|
+
|
255
|
+
class Sleep_result
|
256
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
257
|
+
|
258
|
+
FIELDS = {
|
259
|
+
|
260
|
+
}
|
261
|
+
|
262
|
+
def struct_fields; FIELDS; end
|
263
|
+
|
264
|
+
def validate
|
265
|
+
end
|
266
|
+
|
267
|
+
::Thrift::Struct.generate_accessors self
|
268
|
+
end
|
269
|
+
|
270
|
+
end
|
271
|
+
|
272
|
+
end
|
@@ -0,0 +1,345 @@
|
|
1
|
+
#
|
2
|
+
# Autogenerated by Thrift Compiler (0.7.0)
|
3
|
+
#
|
4
|
+
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
5
|
+
#
|
6
|
+
|
7
|
+
|
8
|
+
module SpecNamespace
|
9
|
+
module SomeEnum
|
10
|
+
ONE = 0
|
11
|
+
TWO = 1
|
12
|
+
VALUE_MAP = {0 => "ONE", 1 => "TWO"}
|
13
|
+
VALID_VALUES = Set.new([ONE, TWO]).freeze
|
14
|
+
end
|
15
|
+
|
16
|
+
class Hello
|
17
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
18
|
+
GREETING = 1
|
19
|
+
|
20
|
+
FIELDS = {
|
21
|
+
GREETING => {:type => ::Thrift::Types::STRING, :name => 'greeting', :default => %q"hello world"}
|
22
|
+
}
|
23
|
+
|
24
|
+
def struct_fields; FIELDS; end
|
25
|
+
|
26
|
+
def validate
|
27
|
+
end
|
28
|
+
|
29
|
+
::Thrift::Struct.generate_accessors self
|
30
|
+
end
|
31
|
+
|
32
|
+
class StructWithSomeEnum
|
33
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
34
|
+
SOME_ENUM = 1
|
35
|
+
|
36
|
+
FIELDS = {
|
37
|
+
SOME_ENUM => {:type => ::Thrift::Types::I32, :name => 'some_enum', :enum_class => SpecNamespace::SomeEnum}
|
38
|
+
}
|
39
|
+
|
40
|
+
def struct_fields; FIELDS; end
|
41
|
+
|
42
|
+
def validate
|
43
|
+
unless @some_enum.nil? || SpecNamespace::SomeEnum::VALID_VALUES.include?(@some_enum)
|
44
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Invalid value of field some_enum!')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
::Thrift::Struct.generate_accessors self
|
49
|
+
end
|
50
|
+
|
51
|
+
class TestUnion < ::Thrift::Union
|
52
|
+
include ::Thrift::Struct_Union
|
53
|
+
class << self
|
54
|
+
def string_field(val)
|
55
|
+
TestUnion.new(:string_field, val)
|
56
|
+
end
|
57
|
+
|
58
|
+
def i32_field(val)
|
59
|
+
TestUnion.new(:i32_field, val)
|
60
|
+
end
|
61
|
+
|
62
|
+
def other_i32_field(val)
|
63
|
+
TestUnion.new(:other_i32_field, val)
|
64
|
+
end
|
65
|
+
|
66
|
+
def enum_field(val)
|
67
|
+
TestUnion.new(:enum_field, val)
|
68
|
+
end
|
69
|
+
|
70
|
+
def binary_field(val)
|
71
|
+
TestUnion.new(:binary_field, val)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
STRING_FIELD = 1
|
76
|
+
I32_FIELD = 2
|
77
|
+
OTHER_I32_FIELD = 3
|
78
|
+
ENUM_FIELD = 4
|
79
|
+
BINARY_FIELD = 5
|
80
|
+
|
81
|
+
FIELDS = {
|
82
|
+
# A doc string
|
83
|
+
STRING_FIELD => {:type => ::Thrift::Types::STRING, :name => 'string_field'},
|
84
|
+
I32_FIELD => {:type => ::Thrift::Types::I32, :name => 'i32_field'},
|
85
|
+
OTHER_I32_FIELD => {:type => ::Thrift::Types::I32, :name => 'other_i32_field'},
|
86
|
+
ENUM_FIELD => {:type => ::Thrift::Types::I32, :name => 'enum_field', :enum_class => SpecNamespace::SomeEnum},
|
87
|
+
BINARY_FIELD => {:type => ::Thrift::Types::STRING, :name => 'binary_field', :binary => true}
|
88
|
+
}
|
89
|
+
|
90
|
+
def struct_fields; FIELDS; end
|
91
|
+
|
92
|
+
def validate
|
93
|
+
raise(StandardError, 'Union fields are not set.') if get_set_field.nil? || get_value.nil?
|
94
|
+
if get_set_field == :enum_field
|
95
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Invalid value of field enum_field!') unless SpecNamespace::SomeEnum::VALID_VALUES.include?(get_value)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
::Thrift::Union.generate_accessors self
|
100
|
+
end
|
101
|
+
|
102
|
+
class Foo
|
103
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
104
|
+
SIMPLE = 1
|
105
|
+
WORDS = 2
|
106
|
+
HELLO = 3
|
107
|
+
INTS = 4
|
108
|
+
COMPLEX = 5
|
109
|
+
SHORTS = 6
|
110
|
+
OPT_STRING = 7
|
111
|
+
MY_BOOL = 8
|
112
|
+
|
113
|
+
FIELDS = {
|
114
|
+
SIMPLE => {:type => ::Thrift::Types::I32, :name => 'simple', :default => 53},
|
115
|
+
WORDS => {:type => ::Thrift::Types::STRING, :name => 'words', :default => %q"words"},
|
116
|
+
HELLO => {:type => ::Thrift::Types::STRUCT, :name => 'hello', :default => SpecNamespace::Hello.new({
|
117
|
+
%q"greeting" => %q"hello, world!",
|
118
|
+
}), :class => SpecNamespace::Hello},
|
119
|
+
INTS => {:type => ::Thrift::Types::LIST, :name => 'ints', :default => [
|
120
|
+
1,
|
121
|
+
2,
|
122
|
+
2,
|
123
|
+
3,
|
124
|
+
], :element => {:type => ::Thrift::Types::I32}},
|
125
|
+
COMPLEX => {:type => ::Thrift::Types::MAP, :name => 'complex', :key => {:type => ::Thrift::Types::I32}, :value => {:type => ::Thrift::Types::MAP, :key => {:type => ::Thrift::Types::STRING}, :value => {:type => ::Thrift::Types::DOUBLE}}},
|
126
|
+
SHORTS => {:type => ::Thrift::Types::SET, :name => 'shorts', :default => Set.new([
|
127
|
+
5,
|
128
|
+
17,
|
129
|
+
239,
|
130
|
+
]), :element => {:type => ::Thrift::Types::I16}},
|
131
|
+
OPT_STRING => {:type => ::Thrift::Types::STRING, :name => 'opt_string', :optional => true},
|
132
|
+
MY_BOOL => {:type => ::Thrift::Types::BOOL, :name => 'my_bool'}
|
133
|
+
}
|
134
|
+
|
135
|
+
def struct_fields; FIELDS; end
|
136
|
+
|
137
|
+
def validate
|
138
|
+
end
|
139
|
+
|
140
|
+
::Thrift::Struct.generate_accessors self
|
141
|
+
end
|
142
|
+
|
143
|
+
class Foo2
|
144
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
145
|
+
MY_BINARY = 1
|
146
|
+
|
147
|
+
FIELDS = {
|
148
|
+
MY_BINARY => {:type => ::Thrift::Types::STRING, :name => 'my_binary', :binary => true}
|
149
|
+
}
|
150
|
+
|
151
|
+
def struct_fields; FIELDS; end
|
152
|
+
|
153
|
+
def validate
|
154
|
+
end
|
155
|
+
|
156
|
+
::Thrift::Struct.generate_accessors self
|
157
|
+
end
|
158
|
+
|
159
|
+
class BoolStruct
|
160
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
161
|
+
YESNO = 1
|
162
|
+
|
163
|
+
FIELDS = {
|
164
|
+
YESNO => {:type => ::Thrift::Types::BOOL, :name => 'yesno', :default => true}
|
165
|
+
}
|
166
|
+
|
167
|
+
def struct_fields; FIELDS; end
|
168
|
+
|
169
|
+
def validate
|
170
|
+
end
|
171
|
+
|
172
|
+
::Thrift::Struct.generate_accessors self
|
173
|
+
end
|
174
|
+
|
175
|
+
class SimpleList
|
176
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
177
|
+
BOOLS = 1
|
178
|
+
BYTES = 2
|
179
|
+
I16S = 3
|
180
|
+
I32S = 4
|
181
|
+
I64S = 5
|
182
|
+
DOUBLES = 6
|
183
|
+
STRINGS = 7
|
184
|
+
MAPS = 8
|
185
|
+
LISTS = 9
|
186
|
+
SETS = 10
|
187
|
+
HELLOS = 11
|
188
|
+
|
189
|
+
FIELDS = {
|
190
|
+
BOOLS => {:type => ::Thrift::Types::LIST, :name => 'bools', :element => {:type => ::Thrift::Types::BOOL}},
|
191
|
+
BYTES => {:type => ::Thrift::Types::LIST, :name => 'bytes', :element => {:type => ::Thrift::Types::BYTE}},
|
192
|
+
I16S => {:type => ::Thrift::Types::LIST, :name => 'i16s', :element => {:type => ::Thrift::Types::I16}},
|
193
|
+
I32S => {:type => ::Thrift::Types::LIST, :name => 'i32s', :element => {:type => ::Thrift::Types::I32}},
|
194
|
+
I64S => {:type => ::Thrift::Types::LIST, :name => 'i64s', :element => {:type => ::Thrift::Types::I64}},
|
195
|
+
DOUBLES => {:type => ::Thrift::Types::LIST, :name => 'doubles', :element => {:type => ::Thrift::Types::DOUBLE}},
|
196
|
+
STRINGS => {:type => ::Thrift::Types::LIST, :name => 'strings', :element => {:type => ::Thrift::Types::STRING}},
|
197
|
+
MAPS => {:type => ::Thrift::Types::LIST, :name => 'maps', :element => {:type => ::Thrift::Types::MAP, :key => {:type => ::Thrift::Types::I16}, :value => {:type => ::Thrift::Types::I16}}},
|
198
|
+
LISTS => {:type => ::Thrift::Types::LIST, :name => 'lists', :element => {:type => ::Thrift::Types::LIST, :element => {:type => ::Thrift::Types::I16}}},
|
199
|
+
SETS => {:type => ::Thrift::Types::LIST, :name => 'sets', :element => {:type => ::Thrift::Types::SET, :element => {:type => ::Thrift::Types::I16}}},
|
200
|
+
HELLOS => {:type => ::Thrift::Types::LIST, :name => 'hellos', :element => {:type => ::Thrift::Types::STRUCT, :class => SpecNamespace::Hello}}
|
201
|
+
}
|
202
|
+
|
203
|
+
def struct_fields; FIELDS; end
|
204
|
+
|
205
|
+
def validate
|
206
|
+
end
|
207
|
+
|
208
|
+
::Thrift::Struct.generate_accessors self
|
209
|
+
end
|
210
|
+
|
211
|
+
class Xception < ::Thrift::Exception
|
212
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
213
|
+
MESSAGE = 1
|
214
|
+
CODE = 2
|
215
|
+
|
216
|
+
FIELDS = {
|
217
|
+
MESSAGE => {:type => ::Thrift::Types::STRING, :name => 'message'},
|
218
|
+
CODE => {:type => ::Thrift::Types::I32, :name => 'code', :default => 1}
|
219
|
+
}
|
220
|
+
|
221
|
+
def struct_fields; FIELDS; end
|
222
|
+
|
223
|
+
def validate
|
224
|
+
end
|
225
|
+
|
226
|
+
::Thrift::Struct.generate_accessors self
|
227
|
+
end
|
228
|
+
|
229
|
+
class My_union < ::Thrift::Union
|
230
|
+
include ::Thrift::Struct_Union
|
231
|
+
class << self
|
232
|
+
def im_true(val)
|
233
|
+
My_union.new(:im_true, val)
|
234
|
+
end
|
235
|
+
|
236
|
+
def a_bite(val)
|
237
|
+
My_union.new(:a_bite, val)
|
238
|
+
end
|
239
|
+
|
240
|
+
def integer16(val)
|
241
|
+
My_union.new(:integer16, val)
|
242
|
+
end
|
243
|
+
|
244
|
+
def integer32(val)
|
245
|
+
My_union.new(:integer32, val)
|
246
|
+
end
|
247
|
+
|
248
|
+
def integer64(val)
|
249
|
+
My_union.new(:integer64, val)
|
250
|
+
end
|
251
|
+
|
252
|
+
def double_precision(val)
|
253
|
+
My_union.new(:double_precision, val)
|
254
|
+
end
|
255
|
+
|
256
|
+
def some_characters(val)
|
257
|
+
My_union.new(:some_characters, val)
|
258
|
+
end
|
259
|
+
|
260
|
+
def other_i32(val)
|
261
|
+
My_union.new(:other_i32, val)
|
262
|
+
end
|
263
|
+
|
264
|
+
def some_enum(val)
|
265
|
+
My_union.new(:some_enum, val)
|
266
|
+
end
|
267
|
+
|
268
|
+
def my_map(val)
|
269
|
+
My_union.new(:my_map, val)
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
IM_TRUE = 1
|
274
|
+
A_BITE = 2
|
275
|
+
INTEGER16 = 3
|
276
|
+
INTEGER32 = 4
|
277
|
+
INTEGER64 = 5
|
278
|
+
DOUBLE_PRECISION = 6
|
279
|
+
SOME_CHARACTERS = 7
|
280
|
+
OTHER_I32 = 8
|
281
|
+
SOME_ENUM = 9
|
282
|
+
MY_MAP = 10
|
283
|
+
|
284
|
+
FIELDS = {
|
285
|
+
IM_TRUE => {:type => ::Thrift::Types::BOOL, :name => 'im_true'},
|
286
|
+
A_BITE => {:type => ::Thrift::Types::BYTE, :name => 'a_bite'},
|
287
|
+
INTEGER16 => {:type => ::Thrift::Types::I16, :name => 'integer16'},
|
288
|
+
INTEGER32 => {:type => ::Thrift::Types::I32, :name => 'integer32'},
|
289
|
+
INTEGER64 => {:type => ::Thrift::Types::I64, :name => 'integer64'},
|
290
|
+
DOUBLE_PRECISION => {:type => ::Thrift::Types::DOUBLE, :name => 'double_precision'},
|
291
|
+
SOME_CHARACTERS => {:type => ::Thrift::Types::STRING, :name => 'some_characters'},
|
292
|
+
OTHER_I32 => {:type => ::Thrift::Types::I32, :name => 'other_i32'},
|
293
|
+
SOME_ENUM => {:type => ::Thrift::Types::I32, :name => 'some_enum', :enum_class => SpecNamespace::SomeEnum},
|
294
|
+
MY_MAP => {:type => ::Thrift::Types::MAP, :name => 'my_map', :key => {:type => ::Thrift::Types::I32, :enum_class => SpecNamespace::SomeEnum}, :value => {:type => ::Thrift::Types::LIST, :element => {:type => ::Thrift::Types::I32, :enum_class => SpecNamespace::SomeEnum}}}
|
295
|
+
}
|
296
|
+
|
297
|
+
def struct_fields; FIELDS; end
|
298
|
+
|
299
|
+
def validate
|
300
|
+
raise(StandardError, 'Union fields are not set.') if get_set_field.nil? || get_value.nil?
|
301
|
+
if get_set_field == :some_enum
|
302
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Invalid value of field some_enum!') unless SpecNamespace::SomeEnum::VALID_VALUES.include?(get_value)
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
::Thrift::Union.generate_accessors self
|
307
|
+
end
|
308
|
+
|
309
|
+
class Struct_with_union
|
310
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
311
|
+
FUN_UNION = 1
|
312
|
+
INTEGER32 = 2
|
313
|
+
SOME_CHARACTERS = 3
|
314
|
+
|
315
|
+
FIELDS = {
|
316
|
+
FUN_UNION => {:type => ::Thrift::Types::STRUCT, :name => 'fun_union', :class => SpecNamespace::My_union},
|
317
|
+
INTEGER32 => {:type => ::Thrift::Types::I32, :name => 'integer32'},
|
318
|
+
SOME_CHARACTERS => {:type => ::Thrift::Types::STRING, :name => 'some_characters'}
|
319
|
+
}
|
320
|
+
|
321
|
+
def struct_fields; FIELDS; end
|
322
|
+
|
323
|
+
def validate
|
324
|
+
end
|
325
|
+
|
326
|
+
::Thrift::Struct.generate_accessors self
|
327
|
+
end
|
328
|
+
|
329
|
+
class StructWithEnumMap
|
330
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
331
|
+
MY_MAP = 1
|
332
|
+
|
333
|
+
FIELDS = {
|
334
|
+
MY_MAP => {:type => ::Thrift::Types::MAP, :name => 'my_map', :key => {:type => ::Thrift::Types::I32, :enum_class => SpecNamespace::SomeEnum}, :value => {:type => ::Thrift::Types::LIST, :element => {:type => ::Thrift::Types::I32, :enum_class => SpecNamespace::SomeEnum}}}
|
335
|
+
}
|
336
|
+
|
337
|
+
def struct_fields; FIELDS; end
|
338
|
+
|
339
|
+
def validate
|
340
|
+
end
|
341
|
+
|
342
|
+
::Thrift::Struct.generate_accessors self
|
343
|
+
end
|
344
|
+
|
345
|
+
end
|