| 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 |
#ifndef _THRIFT_PROTOCOL_TPROTOCOLTAP_H_
|
|
|
21 |
#define _THRIFT_PROTOCOL_TPROTOCOLTAP_H_ 1
|
|
|
22 |
|
|
|
23 |
#include <protocol/TOneWayProtocol.h>
|
|
|
24 |
|
|
|
25 |
namespace apache { namespace thrift { namespace protocol {
|
|
|
26 |
|
|
|
27 |
using apache::thrift::transport::TTransport;
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Puts a wiretap on a protocol object. Any reads to this class are passed
|
|
|
31 |
* through to an enclosed protocol object, but also mirrored as write to a
|
|
|
32 |
* second protocol object.
|
|
|
33 |
*
|
|
|
34 |
*/
|
|
|
35 |
class TProtocolTap : public TReadOnlyProtocol {
|
|
|
36 |
public:
|
|
|
37 |
TProtocolTap(boost::shared_ptr<TProtocol> source,
|
|
|
38 |
boost::shared_ptr<TProtocol> sink)
|
|
|
39 |
: TReadOnlyProtocol(source->getTransport(), "TProtocolTap")
|
|
|
40 |
, source_(source)
|
|
|
41 |
, sink_(sink)
|
|
|
42 |
{}
|
|
|
43 |
|
|
|
44 |
virtual uint32_t readMessageBegin(std::string& name,
|
|
|
45 |
TMessageType& messageType,
|
|
|
46 |
int32_t& seqid) {
|
|
|
47 |
uint32_t rv = source_->readMessageBegin(name, messageType, seqid);
|
|
|
48 |
sink_->writeMessageBegin(name, messageType, seqid);
|
|
|
49 |
return rv;
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
virtual uint32_t readMessageEnd() {
|
|
|
53 |
uint32_t rv = source_->readMessageEnd();
|
|
|
54 |
sink_->writeMessageEnd();
|
|
|
55 |
return rv;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
virtual uint32_t readStructBegin(std::string& name) {
|
|
|
59 |
uint32_t rv = source_->readStructBegin(name);
|
|
|
60 |
sink_->writeStructBegin(name.c_str());
|
|
|
61 |
return rv;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
virtual uint32_t readStructEnd() {
|
|
|
65 |
uint32_t rv = source_->readStructEnd();
|
|
|
66 |
sink_->writeStructEnd();
|
|
|
67 |
return rv;
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
virtual uint32_t readFieldBegin(std::string& name,
|
|
|
71 |
TType& fieldType,
|
|
|
72 |
int16_t& fieldId) {
|
|
|
73 |
uint32_t rv = source_->readFieldBegin(name, fieldType, fieldId);
|
|
|
74 |
if (fieldType == T_STOP) {
|
|
|
75 |
sink_->writeFieldStop();
|
|
|
76 |
} else {
|
|
|
77 |
sink_->writeFieldBegin(name.c_str(), fieldType, fieldId);
|
|
|
78 |
}
|
|
|
79 |
return rv;
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
virtual uint32_t readFieldEnd() {
|
|
|
84 |
uint32_t rv = source_->readFieldEnd();
|
|
|
85 |
sink_->writeFieldEnd();
|
|
|
86 |
return rv;
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
virtual uint32_t readMapBegin(TType& keyType,
|
|
|
90 |
TType& valType,
|
|
|
91 |
uint32_t& size) {
|
|
|
92 |
uint32_t rv = source_->readMapBegin(keyType, valType, size);
|
|
|
93 |
sink_->writeMapBegin(keyType, valType, size);
|
|
|
94 |
return rv;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
virtual uint32_t readMapEnd() {
|
|
|
99 |
uint32_t rv = source_->readMapEnd();
|
|
|
100 |
sink_->writeMapEnd();
|
|
|
101 |
return rv;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
virtual uint32_t readListBegin(TType& elemType,
|
|
|
105 |
uint32_t& size) {
|
|
|
106 |
uint32_t rv = source_->readListBegin(elemType, size);
|
|
|
107 |
sink_->writeListBegin(elemType, size);
|
|
|
108 |
return rv;
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
|
|
|
112 |
virtual uint32_t readListEnd() {
|
|
|
113 |
uint32_t rv = source_->readListEnd();
|
|
|
114 |
sink_->writeListEnd();
|
|
|
115 |
return rv;
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
virtual uint32_t readSetBegin(TType& elemType,
|
|
|
119 |
uint32_t& size) {
|
|
|
120 |
uint32_t rv = source_->readSetBegin(elemType, size);
|
|
|
121 |
sink_->writeSetBegin(elemType, size);
|
|
|
122 |
return rv;
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
virtual uint32_t readSetEnd() {
|
|
|
127 |
uint32_t rv = source_->readSetEnd();
|
|
|
128 |
sink_->writeSetEnd();
|
|
|
129 |
return rv;
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
virtual uint32_t readBool(bool& value) {
|
|
|
133 |
uint32_t rv = source_->readBool(value);
|
|
|
134 |
sink_->writeBool(value);
|
|
|
135 |
return rv;
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
virtual uint32_t readByte(int8_t& byte) {
|
|
|
139 |
uint32_t rv = source_->readByte(byte);
|
|
|
140 |
sink_->writeByte(byte);
|
|
|
141 |
return rv;
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
virtual uint32_t readI16(int16_t& i16) {
|
|
|
145 |
uint32_t rv = source_->readI16(i16);
|
|
|
146 |
sink_->writeI16(i16);
|
|
|
147 |
return rv;
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
virtual uint32_t readI32(int32_t& i32) {
|
|
|
151 |
uint32_t rv = source_->readI32(i32);
|
|
|
152 |
sink_->writeI32(i32);
|
|
|
153 |
return rv;
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
virtual uint32_t readI64(int64_t& i64) {
|
|
|
157 |
uint32_t rv = source_->readI64(i64);
|
|
|
158 |
sink_->writeI64(i64);
|
|
|
159 |
return rv;
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
virtual uint32_t readDouble(double& dub) {
|
|
|
163 |
uint32_t rv = source_->readDouble(dub);
|
|
|
164 |
sink_->writeDouble(dub);
|
|
|
165 |
return rv;
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
virtual uint32_t readString(std::string& str) {
|
|
|
169 |
uint32_t rv = source_->readString(str);
|
|
|
170 |
sink_->writeString(str);
|
|
|
171 |
return rv;
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
virtual uint32_t readBinary(std::string& str) {
|
|
|
175 |
uint32_t rv = source_->readBinary(str);
|
|
|
176 |
sink_->writeBinary(str);
|
|
|
177 |
return rv;
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
private:
|
|
|
181 |
boost::shared_ptr<TProtocol> source_;
|
|
|
182 |
boost::shared_ptr<TProtocol> sink_;
|
|
|
183 |
};
|
|
|
184 |
|
|
|
185 |
}}} // apache::thrift::protocol
|
|
|
186 |
|
|
|
187 |
#endif // #define _THRIFT_PROTOCOL_TPROTOCOLTAP_H_ 1
|