garru-ruby_scribe_client 0.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.
Files changed (40) hide show
  1. data/CHANGELOG +3 -0
  2. data/LICENSE +0 -0
  3. data/Manifest +39 -0
  4. data/README +0 -0
  5. data/Rakefile +8 -0
  6. data/etc/scribe_cat.rb +23 -0
  7. data/lib/ruby_scribe_client/FacebookService.rb +685 -0
  8. data/lib/ruby_scribe_client/fb303_types.rb +16 -0
  9. data/lib/ruby_scribe_client/reflection_limited_types.rb +148 -0
  10. data/lib/ruby_scribe_client/scribe.rb +82 -0
  11. data/lib/ruby_scribe_client/scribe_types.rb +32 -0
  12. data/lib/ruby_scribe_client.rb +33 -0
  13. data/ruby_scribe_client.gemspec +31 -0
  14. data/vendor/thrift/client.rb +44 -0
  15. data/vendor/thrift/deprecation.rb +155 -0
  16. data/vendor/thrift/exceptions.rb +65 -0
  17. data/vendor/thrift/processor.rb +39 -0
  18. data/vendor/thrift/protocol/binaryprotocol.rb +213 -0
  19. data/vendor/thrift/protocol/binaryprotocolaccelerated.rb +19 -0
  20. data/vendor/thrift/protocol/tbinaryprotocol.rb +2 -0
  21. data/vendor/thrift/protocol/tprotocol.rb +2 -0
  22. data/vendor/thrift/protocol.rb +270 -0
  23. data/vendor/thrift/serializer.rb +27 -0
  24. data/vendor/thrift/server/httpserver.rb +44 -0
  25. data/vendor/thrift/server/nonblockingserver.rb +278 -0
  26. data/vendor/thrift/server/thttpserver.rb +2 -0
  27. data/vendor/thrift/server/tserver.rb +2 -0
  28. data/vendor/thrift/server.rb +135 -0
  29. data/vendor/thrift/struct.rb +272 -0
  30. data/vendor/thrift/thrift.rb +14 -0
  31. data/vendor/thrift/transport/httpclient.rb +29 -0
  32. data/vendor/thrift/transport/socket.rb +153 -0
  33. data/vendor/thrift/transport/thttpclient.rb +2 -0
  34. data/vendor/thrift/transport/tsocket.rb +2 -0
  35. data/vendor/thrift/transport/ttransport.rb +2 -0
  36. data/vendor/thrift/transport/unixsocket.rb +58 -0
  37. data/vendor/thrift/transport.rb +319 -0
  38. data/vendor/thrift/types.rb +83 -0
  39. data/vendor/thrift.rb +28 -0
  40. metadata +104 -0
@@ -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,270 @@
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
+
11
+ # this require is to make generated struct definitions happy
12
+ require 'set'
13
+
14
+ module Thrift
15
+ class ProtocolException < Exception
16
+
17
+ UNKNOWN = 0
18
+ INVALID_DATA = 1
19
+ NEGATIVE_SIZE = 2
20
+ SIZE_LIMIT = 3
21
+ BAD_VERSION = 4
22
+
23
+ attr_reader :type
24
+
25
+ def initialize(type=UNKNOWN, message=nil)
26
+ super(message)
27
+ @type = type
28
+ end
29
+
30
+ end
31
+ deprecate_class! :TProtocolException => ProtocolException
32
+
33
+ class Protocol
34
+
35
+ attr_reader :trans
36
+
37
+ def initialize(trans)
38
+ @trans = trans
39
+ end
40
+
41
+ def native?
42
+ puts "wrong method is being called!"
43
+ false
44
+ end
45
+
46
+ def write_message_begin(name, type, seqid); nil; end
47
+ deprecate! :writeMessageBegin => :write_message_begin
48
+
49
+ def write_message_end; nil; end
50
+ deprecate! :writeMessageEnd => :write_message_end
51
+
52
+ def write_struct_begin(name); nil; end
53
+ deprecate! :writeStructBegin => :write_struct_begin
54
+
55
+ def write_struct_end; nil; end
56
+ deprecate! :writeStructEnd => :write_struct_end
57
+
58
+ def write_field_begin(name, type, id); nil; end
59
+ deprecate! :writeFieldBegin => :write_field_begin
60
+
61
+ def write_field_end; nil; end
62
+ deprecate! :writeFieldEnd => :write_field_end
63
+
64
+ def write_field_stop; nil; end
65
+ deprecate! :writeFieldStop => :write_field_stop
66
+
67
+ def write_map_begin(ktype, vtype, size); nil; end
68
+ deprecate! :writeMapBegin => :write_map_begin
69
+
70
+ def write_map_end; nil; end
71
+ deprecate! :writeMapEnd => :write_map_end
72
+
73
+ def write_list_begin(etype, size); nil; end
74
+ deprecate! :writeListBegin => :write_list_begin
75
+
76
+ def write_list_end; nil; end
77
+ deprecate! :writeListEnd => :write_list_end
78
+
79
+ def write_set_begin(etype, size); nil; end
80
+ deprecate! :writeSetBegin => :write_set_begin
81
+
82
+ def write_set_end; nil; end
83
+ deprecate! :writeSetEnd => :write_set_end
84
+
85
+ def write_bool(bool); nil; end
86
+ deprecate! :writeBool => :write_bool
87
+
88
+ def write_byte(byte); nil; end
89
+ deprecate! :writeByte => :write_byte
90
+
91
+ def write_i16(i16); nil; end
92
+ deprecate! :writeI16 => :write_i16
93
+
94
+ def write_i32(i32); nil; end
95
+ deprecate! :writeI32 => :write_i32
96
+
97
+ def write_i64(i64); nil; end
98
+ deprecate! :writeI64 => :write_i64
99
+
100
+ def write_double(dub); nil; end
101
+ deprecate! :writeDouble => :write_double
102
+
103
+ def write_string(str); nil; end
104
+ deprecate! :writeString => :write_string
105
+
106
+ def read_message_begin; nil; end
107
+ deprecate! :readMessageBegin => :read_message_begin
108
+
109
+ def read_message_end; nil; end
110
+ deprecate! :readMessageEnd => :read_message_end
111
+
112
+ def read_struct_begin; nil; end
113
+ deprecate! :readStructBegin => :read_struct_begin
114
+
115
+ def read_struct_end; nil; end
116
+ deprecate! :readStructEnd => :read_struct_end
117
+
118
+ def read_field_begin; nil; end
119
+ deprecate! :readFieldBegin => :read_field_begin
120
+
121
+ def read_field_end; nil; end
122
+ deprecate! :readFieldEnd => :read_field_end
123
+
124
+ def read_map_begin; nil; end
125
+ deprecate! :readMapBegin => :read_map_begin
126
+
127
+ def read_map_end; nil; end
128
+ deprecate! :readMapEnd => :read_map_end
129
+
130
+ def read_list_begin; nil; end
131
+ deprecate! :readListBegin => :read_list_begin
132
+
133
+ def read_list_end; nil; end
134
+ deprecate! :readListEnd => :read_list_end
135
+
136
+ def read_set_begin; nil; end
137
+ deprecate! :readSetBegin => :read_set_begin
138
+
139
+ def read_set_end; nil; end
140
+ deprecate! :readSetEnd => :read_set_end
141
+
142
+ def read_bool; nil; end
143
+ deprecate! :readBool => :read_bool
144
+
145
+ def read_byte; nil; end
146
+ deprecate! :readByte => :read_byte
147
+
148
+ def read_i16; nil; end
149
+ deprecate! :readI16 => :read_i16
150
+
151
+ def read_i32; nil; end
152
+ deprecate! :readI32 => :read_i32
153
+
154
+ def read_i64; nil; end
155
+ deprecate! :readI64 => :read_i64
156
+
157
+ def read_double; nil; end
158
+ deprecate! :readDouble => :read_double
159
+
160
+ def read_string; nil; end
161
+ deprecate! :readString => :read_string
162
+
163
+ def write_field(name, type, fid, value)
164
+ write_field_begin(name, type, fid)
165
+ write_type(type, value)
166
+ write_field_end
167
+ end
168
+
169
+ def write_type(type, value)
170
+ case type
171
+ when Types::BOOL
172
+ write_bool(value)
173
+ when Types::BYTE
174
+ write_byte(value)
175
+ when Types::DOUBLE
176
+ write_double(value)
177
+ when Types::I16
178
+ write_i16(value)
179
+ when Types::I32
180
+ write_i32(value)
181
+ when Types::I64
182
+ write_i64(value)
183
+ when Types::STRING
184
+ write_string(value)
185
+ when Types::STRUCT
186
+ value.write(self)
187
+ else
188
+ raise NotImplementedError
189
+ end
190
+ end
191
+
192
+ def read_type(type)
193
+ case type
194
+ when Types::BOOL
195
+ read_bool
196
+ when Types::BYTE
197
+ read_byte
198
+ when Types::DOUBLE
199
+ read_double
200
+ when Types::I16
201
+ read_i16
202
+ when Types::I32
203
+ read_i32
204
+ when Types::I64
205
+ read_i64
206
+ when Types::STRING
207
+ read_string
208
+ else
209
+ raise NotImplementedError
210
+ end
211
+ end
212
+
213
+ def skip(type)
214
+ case type
215
+ when Types::STOP
216
+ nil
217
+ when Types::BOOL
218
+ read_bool
219
+ when Types::BYTE
220
+ read_byte
221
+ when Types::I16
222
+ read_i16
223
+ when Types::I32
224
+ read_i32
225
+ when Types::I64
226
+ read_i64
227
+ when Types::DOUBLE
228
+ read_double
229
+ when Types::STRING
230
+ read_string
231
+ when Types::STRUCT
232
+ read_struct_begin
233
+ while true
234
+ name, type, id = read_field_begin
235
+ break if type == Types::STOP
236
+ skip(type)
237
+ read_field_end
238
+ end
239
+ read_struct_end
240
+ when Types::MAP
241
+ ktype, vtype, size = read_map_begin
242
+ size.times do
243
+ skip(ktype)
244
+ skip(vtype)
245
+ end
246
+ read_map_end
247
+ when Types::SET
248
+ etype, size = read_set_begin
249
+ size.times do
250
+ skip(etype)
251
+ end
252
+ read_set_end
253
+ when Types::LIST
254
+ etype, size = read_list_begin
255
+ size.times do
256
+ skip(etype)
257
+ end
258
+ read_list_end
259
+ end
260
+ end
261
+
262
+ end
263
+ deprecate_class! :TProtocol => Protocol
264
+
265
+ class ProtocolFactory
266
+ def get_protocol(trans); nil; end
267
+ deprecate! :getProtocol => :get_protocol
268
+ end
269
+ deprecate_class! :TProtocolFactory => ProtocolFactory
270
+ end
@@ -0,0 +1,27 @@
1
+ module Thrift
2
+ class Serializer
3
+ def initialize(protocolFactory = BinaryProtocolFactory.new)
4
+ @transport = MemoryBuffer.new
5
+ @protocol = protocolFactory.get_protocol(@transport)
6
+ end
7
+
8
+ def serialize(base)
9
+ @transport.reset_buffer
10
+ base.write(@protocol)
11
+ @transport.read(@transport.available)
12
+ end
13
+ end
14
+
15
+ class Deserializer
16
+ def initialize(protocolFactory = BinaryProtocolFactory.new)
17
+ @transport = MemoryBuffer.new
18
+ @protocol = protocolFactory.get_protocol(@transport)
19
+ end
20
+
21
+ def deserialize(base, buffer)
22
+ @transport.reset_buffer(buffer)
23
+ base.read(@protocol)
24
+ base
25
+ end
26
+ end
27
+ end
@@ -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