blob: 32238fbc66d45f3ac4286cefcf713d1e4cd6fb52 [file] [log] [blame]
David Reissac110e42010-03-09 05:20:07 +00001/*
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#include <TApplicationException.h>
21#include <protocol/TProtocol.h>
22
23namespace apache { namespace thrift {
24
25uint32_t TApplicationException::read(apache::thrift::protocol::TProtocol* iprot) {
26 uint32_t xfer = 0;
27 std::string fname;
28 apache::thrift::protocol::TType ftype;
29 int16_t fid;
30
31 xfer += iprot->readStructBegin(fname);
32
33 while (true) {
34 xfer += iprot->readFieldBegin(fname, ftype, fid);
35 if (ftype == apache::thrift::protocol::T_STOP) {
36 break;
37 }
38 switch (fid) {
39 case 1:
40 if (ftype == apache::thrift::protocol::T_STRING) {
41 xfer += iprot->readString(message_);
42 } else {
43 xfer += iprot->skip(ftype);
44 }
45 break;
46 case 2:
47 if (ftype == apache::thrift::protocol::T_I32) {
48 int32_t type;
49 xfer += iprot->readI32(type);
50 type_ = (TApplicationExceptionType)type;
51 } else {
52 xfer += iprot->skip(ftype);
53 }
54 break;
55 default:
56 xfer += iprot->skip(ftype);
57 break;
58 }
59 xfer += iprot->readFieldEnd();
60 }
61
62 xfer += iprot->readStructEnd();
63 return xfer;
64}
65
66uint32_t TApplicationException::write(apache::thrift::protocol::TProtocol* oprot) const {
67 uint32_t xfer = 0;
68 xfer += oprot->writeStructBegin("TApplicationException");
69 xfer += oprot->writeFieldBegin("message", apache::thrift::protocol::T_STRING, 1);
70 xfer += oprot->writeString(message_);
71 xfer += oprot->writeFieldEnd();
72 xfer += oprot->writeFieldBegin("type", apache::thrift::protocol::T_I32, 2);
73 xfer += oprot->writeI32(type_);
74 xfer += oprot->writeFieldEnd();
75 xfer += oprot->writeFieldStop();
76 xfer += oprot->writeStructEnd();
77 return xfer;
78}
79
80}} // apache::thrift