thrift 0.2.0 → 0.2.0.2

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.
data.tar.gz.sig CHANGED
Binary file
data/CHANGELOG CHANGED
@@ -1,3 +1,4 @@
1
+ v0.2.0.2 Remove -Werror from compile.
1
2
 
2
3
  v0.2.0. Update version to Thrift release 0.2.0. No actual code changes.
3
4
 
data/Manifest CHANGED
@@ -6,14 +6,15 @@ Rakefile
6
6
  benchmark/Benchmark.thrift
7
7
  benchmark/benchmark.rb
8
8
  benchmark/client.rb
9
+ benchmark/gen-rb/BenchmarkService.rb
10
+ benchmark/gen-rb/Benchmark_constants.rb
11
+ benchmark/gen-rb/Benchmark_types.rb
9
12
  benchmark/server.rb
10
13
  benchmark/thin_server.rb
11
14
  ext/binary_protocol_accelerated.c
12
15
  ext/binary_protocol_accelerated.h
13
16
  ext/compact_protocol.c
14
17
  ext/compact_protocol.h
15
- ext/conftest.dSYM/Contents/Info.plist
16
- ext/conftest.dSYM/Contents/Resources/DWARF/conftest
17
18
  ext/constants.h
18
19
  ext/extconf.rb
19
20
  ext/macros.h
@@ -33,15 +34,23 @@ lib/thrift/processor.rb
33
34
  lib/thrift/protocol/base_protocol.rb
34
35
  lib/thrift/protocol/binary_protocol.rb
35
36
  lib/thrift/protocol/binary_protocol_accelerated.rb
37
+ lib/thrift/protocol/binaryprotocol.rb
38
+ lib/thrift/protocol/binaryprotocolaccelerated.rb
36
39
  lib/thrift/protocol/compact_protocol.rb
40
+ lib/thrift/protocol/tbinaryprotocol.rb
41
+ lib/thrift/protocol/tprotocol.rb
37
42
  lib/thrift/serializer/deserializer.rb
38
43
  lib/thrift/serializer/serializer.rb
39
44
  lib/thrift/server/base_server.rb
45
+ lib/thrift/server/httpserver.rb
40
46
  lib/thrift/server/mongrel_http_server.rb
41
47
  lib/thrift/server/nonblocking_server.rb
48
+ lib/thrift/server/nonblockingserver.rb
42
49
  lib/thrift/server/simple_server.rb
43
50
  lib/thrift/server/thread_pool_server.rb
44
51
  lib/thrift/server/threaded_server.rb
52
+ lib/thrift/server/thttpserver.rb
53
+ lib/thrift/server/tserver.rb
45
54
  lib/thrift/struct.rb
46
55
  lib/thrift/thrift_native.rb
47
56
  lib/thrift/transport/base_server_transport.rb
@@ -69,6 +78,9 @@ spec/binary_protocol_spec_shared.rb
69
78
  spec/client_spec.rb
70
79
  spec/compact_protocol_spec.rb
71
80
  spec/exception_spec.rb
81
+ spec/gen-rb/NonblockingService.rb
82
+ spec/gen-rb/ThriftSpec_constants.rb
83
+ spec/gen-rb/ThriftSpec_types.rb
72
84
  spec/http_client_spec.rb
73
85
  spec/mongrel_http_server_spec.rb
74
86
  spec/nonblocking_server_spec.rb
@@ -0,0 +1,81 @@
1
+ #
2
+ # Autogenerated by Thrift
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+
7
+ require 'thrift'
8
+ require 'thrift/protocol'
9
+ require File.dirname(__FILE__) + '/Benchmark_types'
10
+
11
+ module ThriftBenchmark
12
+ module BenchmarkService
13
+ class Client
14
+ include ::Thrift::Client
15
+
16
+ def fibonacci(n)
17
+ send_fibonacci(n)
18
+ return recv_fibonacci()
19
+ end
20
+
21
+ def send_fibonacci(n)
22
+ send_message('fibonacci', Fibonacci_args, :n => n)
23
+ end
24
+
25
+ def recv_fibonacci()
26
+ result = receive_message(Fibonacci_result)
27
+ return result.success unless result.success.nil?
28
+ raise Thrift::ApplicationException.new(Thrift::ApplicationException::MISSING_RESULT, 'fibonacci failed: unknown result')
29
+ end
30
+
31
+ end
32
+
33
+ class Processor
34
+ include ::Thrift::Processor
35
+
36
+ def process_fibonacci(seqid, iprot, oprot)
37
+ args = read_args(iprot, Fibonacci_args)
38
+ result = Fibonacci_result.new()
39
+ result.success = @handler.fibonacci(args.n)
40
+ write_result(result, oprot, 'fibonacci', seqid)
41
+ end
42
+
43
+ end
44
+
45
+ # HELPER FUNCTIONS AND STRUCTURES
46
+
47
+ class Fibonacci_args
48
+ include ::Thrift::Struct
49
+ N = 1
50
+
51
+ Thrift::Struct.field_accessor self, :n
52
+ FIELDS = {
53
+ N => {:type => Thrift::Types::BYTE, :name => 'n'}
54
+ }
55
+
56
+ def struct_fields; FIELDS; end
57
+
58
+ def validate
59
+ end
60
+
61
+ end
62
+
63
+ class Fibonacci_result
64
+ include ::Thrift::Struct
65
+ SUCCESS = 0
66
+
67
+ Thrift::Struct.field_accessor self, :success
68
+ FIELDS = {
69
+ SUCCESS => {:type => Thrift::Types::I32, :name => 'success'}
70
+ }
71
+
72
+ def struct_fields; FIELDS; end
73
+
74
+ def validate
75
+ end
76
+
77
+ end
78
+
79
+ end
80
+
81
+ end
@@ -0,0 +1,11 @@
1
+ #
2
+ # Autogenerated by Thrift
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+
7
+ require 'thrift/protocol'
8
+ require File.dirname(__FILE__) + '/Benchmark_types'
9
+
10
+ module ThriftBenchmark
11
+ end
@@ -0,0 +1,10 @@
1
+ #
2
+ # Autogenerated by Thrift
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+
7
+ require 'thrift/protocol'
8
+
9
+ module ThriftBenchmark
10
+ end
data/ext/extconf.rb CHANGED
@@ -19,7 +19,7 @@
19
19
 
20
20
  require 'mkmf'
21
21
 
22
- $CFLAGS = "-g -O2 -Wall -Werror"
22
+ $CFLAGS = "-g -O2 -Wall"
23
23
 
24
24
  have_func("strlcpy", "string.h")
25
25
 
@@ -0,0 +1,213 @@
1
+ #
2
+ # Copyright (c) 2006- Facebook
3
+ # Distributed under the Apache Software License
4
+ #
5
+ # See accompanying file LICENSE or visit the Thrift site at:
6
+ # http://developers.facebook.com/thrift/
7
+ #
8
+ # Author: Mark Slee <mcslee@facebook.com>
9
+ #
10
+ require 'thrift/protocol'
11
+
12
+ module Thrift
13
+ class BinaryProtocol < Protocol
14
+ VERSION_MASK = 0xffff0000
15
+ VERSION_1 = 0x80010000
16
+ TYPE_MASK = 0x000000ff
17
+
18
+ attr_reader :strict_read, :strict_write
19
+
20
+ def initialize(trans, strict_read=true, strict_write=true)
21
+ super(trans)
22
+ @strict_read = strict_read
23
+ @strict_write = strict_write
24
+ end
25
+
26
+ def write_message_begin(name, type, seqid)
27
+ # this is necessary because we added (needed) bounds checking to
28
+ # write_i32, and 0x80010000 is too big for that.
29
+ if strict_write
30
+ write_i16(VERSION_1 >> 16)
31
+ write_i16(type)
32
+ write_string(name)
33
+ write_i32(seqid)
34
+ else
35
+ write_string(name)
36
+ write_byte(type)
37
+ write_i32(seqid)
38
+ end
39
+ end
40
+
41
+ def write_field_begin(name, type, id)
42
+ write_byte(type)
43
+ write_i16(id)
44
+ end
45
+
46
+ def write_field_stop
47
+ write_byte(Thrift::Types::STOP)
48
+ end
49
+
50
+ def write_map_begin(ktype, vtype, size)
51
+ write_byte(ktype)
52
+ write_byte(vtype)
53
+ write_i32(size)
54
+ end
55
+
56
+ def write_list_begin(etype, size)
57
+ write_byte(etype)
58
+ write_i32(size)
59
+ end
60
+
61
+ def write_set_begin(etype, size)
62
+ write_byte(etype)
63
+ write_i32(size)
64
+ end
65
+
66
+ def write_bool(bool)
67
+ write_byte(bool ? 1 : 0)
68
+ end
69
+
70
+ def write_byte(byte)
71
+ trans.write([byte].pack('c'))
72
+ end
73
+
74
+ def write_i16(i16)
75
+ trans.write([i16].pack('n'))
76
+ end
77
+
78
+ def write_i32(i32)
79
+ raise RangeError if i32 < -2**31 || i32 >= 2**31
80
+ trans.write([i32].pack('N'))
81
+ end
82
+
83
+ def write_i64(i64)
84
+ hi = i64 >> 32
85
+ lo = i64 & 0xffffffff
86
+ trans.write([hi, lo].pack('N2'))
87
+ end
88
+
89
+ def write_double(dub)
90
+ trans.write([dub].pack('G'))
91
+ end
92
+
93
+ def write_string(str)
94
+ write_i32(str.length)
95
+ trans.write(str)
96
+ end
97
+
98
+ def read_message_begin
99
+ version = read_i32
100
+ if version < 0
101
+ if (version & VERSION_MASK != VERSION_1)
102
+ raise ProtocolException.new(ProtocolException::BAD_VERSION, 'Missing version identifier')
103
+ end
104
+ type = version & TYPE_MASK
105
+ name = read_string
106
+ seqid = read_i32
107
+ [name, type, seqid]
108
+ else
109
+ if strict_read
110
+ raise ProtocolException.new(ProtocolException::BAD_VERSION, 'No version identifier, old protocol client?')
111
+ end
112
+ name = trans.read_all(version)
113
+ type = read_byte
114
+ seqid = read_i32
115
+ [name, type, seqid]
116
+ end
117
+ end
118
+
119
+ def read_field_begin
120
+ type = read_byte
121
+ if (type == Types::STOP)
122
+ [nil, type, 0]
123
+ else
124
+ id = read_i16
125
+ [nil, type, id]
126
+ end
127
+ end
128
+
129
+ def read_map_begin
130
+ ktype = read_byte
131
+ vtype = read_byte
132
+ size = read_i32
133
+ [ktype, vtype, size]
134
+ end
135
+
136
+ def read_list_begin
137
+ etype = read_byte
138
+ size = read_i32
139
+ [etype, size]
140
+ end
141
+
142
+ def read_set_begin
143
+ etype = read_byte
144
+ size = read_i32
145
+ [etype, size]
146
+ end
147
+
148
+ def read_bool
149
+ byte = read_byte
150
+ byte != 0
151
+ end
152
+
153
+ def read_byte
154
+ dat = trans.read_all(1)
155
+ val = dat[0]
156
+ if (val > 0x7f)
157
+ val = 0 - ((val - 1) ^ 0xff)
158
+ end
159
+ val
160
+ end
161
+
162
+ def read_i16
163
+ dat = trans.read_all(2)
164
+ val, = dat.unpack('n')
165
+ if (val > 0x7fff)
166
+ val = 0 - ((val - 1) ^ 0xffff)
167
+ end
168
+ val
169
+ end
170
+
171
+ def read_i32
172
+ dat = trans.read_all(4)
173
+ val, = dat.unpack('N')
174
+ if (val > 0x7fffffff)
175
+ val = 0 - ((val - 1) ^ 0xffffffff)
176
+ end
177
+ val
178
+ end
179
+
180
+ def read_i64
181
+ dat = trans.read_all(8)
182
+ hi, lo = dat.unpack('N2')
183
+ if (hi > 0x7fffffff)
184
+ hi ^= 0xffffffff
185
+ lo ^= 0xffffffff
186
+ 0 - (hi << 32) - lo - 1
187
+ else
188
+ (hi << 32) + lo
189
+ end
190
+ end
191
+
192
+ def read_double
193
+ dat = trans.read_all(8)
194
+ val = dat.unpack('G').first
195
+ val
196
+ end
197
+
198
+ def read_string
199
+ sz = read_i32
200
+ dat = trans.read_all(sz)
201
+ dat
202
+ end
203
+
204
+ end
205
+ deprecate_class! :TBinaryProtocol => BinaryProtocol
206
+
207
+ class BinaryProtocolFactory < ProtocolFactory
208
+ def get_protocol(trans)
209
+ return Thrift::BinaryProtocol.new(trans)
210
+ end
211
+ end
212
+ deprecate_class! :TBinaryProtocolFactory => BinaryProtocolFactory
213
+ end
@@ -0,0 +1,19 @@
1
+ require 'thrift/protocol/binaryprotocol'
2
+ require 'thrift_native'
3
+
4
+ =begin
5
+ The only change required for a transport to support TBinaryProtocolAccelerated is to implement 2 methods:
6
+ * borrow(size), which takes an optional argument and returns atleast _size_ bytes from the transport,
7
+ or the default buffer size if no argument is given
8
+ * consume!(size), which removes size bytes from the front of the buffer
9
+
10
+ See TMemoryBuffer and TBufferedTransport for examples.
11
+ =end
12
+
13
+ module Thrift
14
+ class BinaryProtocolAcceleratedFactory < ProtocolFactory
15
+ def get_protocol(trans)
16
+ BinaryProtocolAccelerated.new(trans)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,2 @@
1
+ require 'thrift/deprecation'
2
+ require 'thrift/protocol/binaryprotocol'
@@ -0,0 +1,2 @@
1
+ require 'thrift/deprecation'
2
+ require 'thrift/protocol'
@@ -0,0 +1,44 @@
1
+ require 'thrift/protocol'
2
+ require 'thrift/protocol/binaryprotocol'
3
+ require 'thrift/transport'
4
+
5
+ require 'mongrel'
6
+
7
+ ## Sticks a service on a URL, using mongrel to do the HTTP work
8
+ module Thrift
9
+ class SimpleMongrelHTTPServer
10
+ class Handler < Mongrel::HttpHandler
11
+ def initialize(processor, protocol_factory)
12
+ @processor = processor
13
+ @protocol_factory = protocol_factory
14
+ end
15
+
16
+ def process(request, response)
17
+ if request.params["REQUEST_METHOD"] == "POST"
18
+ response.start(200) do |head, out|
19
+ head["Content-Type"] = "application/x-thrift"
20
+ transport = IOStreamTransport.new request.body, out
21
+ protocol = @protocol_factory.get_protocol transport
22
+ @processor.process protocol, protocol
23
+ end
24
+ else
25
+ response.start(404) { }
26
+ end
27
+ end
28
+ end
29
+
30
+ def initialize(processor, opts={})
31
+ port = opts[:port] || 80
32
+ ip = opts[:ip] || "0.0.0.0"
33
+ path = opts[:path] || ""
34
+ protocol_factory = opts[:protocol_factory] || BinaryProtocolFactory.new
35
+ @server = Mongrel::HttpServer.new ip, port
36
+ @server.register "/#{path}", Handler.new(processor, protocol_factory)
37
+ end
38
+
39
+ def serve
40
+ @server.run.join
41
+ end
42
+ end
43
+ deprecate_class! :TSimpleMongrelHTTPServer => SimpleMongrelHTTPServer
44
+ end