| 30 |
ashish |
1 |
#
|
|
|
2 |
# Licensed to the Apache Software Foundation (ASF) under one
|
|
|
3 |
# or more contributor license agreements. See the NOTICE file
|
|
|
4 |
# distributed with this work for additional information
|
|
|
5 |
# regarding copyright ownership. The ASF licenses this file
|
|
|
6 |
# to you under the Apache License, Version 2.0 (the
|
|
|
7 |
# "License"); you may not use this file except in compliance
|
|
|
8 |
# with the License. You may obtain a copy of the License at
|
|
|
9 |
#
|
|
|
10 |
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
11 |
#
|
|
|
12 |
# Unless required by applicable law or agreed to in writing,
|
|
|
13 |
# software distributed under the License is distributed on an
|
|
|
14 |
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
15 |
# KIND, either express or implied. See the License for the
|
|
|
16 |
# specific language governing permissions and limitations
|
|
|
17 |
# under the License.
|
|
|
18 |
#
|
|
|
19 |
|
|
|
20 |
module Thrift
|
|
|
21 |
module Processor
|
|
|
22 |
def initialize(handler)
|
|
|
23 |
@handler = handler
|
|
|
24 |
end
|
|
|
25 |
|
|
|
26 |
def process(iprot, oprot)
|
|
|
27 |
name, type, seqid = iprot.read_message_begin
|
|
|
28 |
if respond_to?("process_#{name}")
|
|
|
29 |
send("process_#{name}", seqid, iprot, oprot)
|
|
|
30 |
true
|
|
|
31 |
else
|
|
|
32 |
iprot.skip(Types::STRUCT)
|
|
|
33 |
iprot.read_message_end
|
|
|
34 |
x = ApplicationException.new(ApplicationException::UNKNOWN_METHOD, 'Unknown function '+name)
|
|
|
35 |
oprot.write_message_begin(name, MessageTypes::EXCEPTION, seqid)
|
|
|
36 |
x.write(oprot)
|
|
|
37 |
oprot.write_message_end
|
|
|
38 |
oprot.trans.flush
|
|
|
39 |
false
|
|
|
40 |
end
|
|
|
41 |
end
|
|
|
42 |
|
|
|
43 |
def read_args(iprot, args_class)
|
|
|
44 |
args = args_class.new
|
|
|
45 |
args.read(iprot)
|
|
|
46 |
iprot.read_message_end
|
|
|
47 |
args
|
|
|
48 |
end
|
|
|
49 |
|
|
|
50 |
def write_result(result, oprot, name, seqid)
|
|
|
51 |
oprot.write_message_begin(name, MessageTypes::REPLY, seqid)
|
|
|
52 |
result.write(oprot)
|
|
|
53 |
oprot.write_message_end
|
|
|
54 |
oprot.trans.flush
|
|
|
55 |
end
|
|
|
56 |
end
|
|
|
57 |
end
|