blob: 26fbd3abbb17fe286aedeb8d6d6de8f79aad600c [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +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 */
David Reisse0e3d1b2008-04-08 05:06:45 +000019
20#ifndef _THRIFT_PROTOCOL_TPROTOCOLTAP_H_
21#define _THRIFT_PROTOCOL_TPROTOCOLTAP_H_ 1
22
David Reiss6806fb82010-10-06 17:09:52 +000023#include <protocol/TVirtualProtocol.h>
David Reisse0e3d1b2008-04-08 05:06:45 +000024
T Jake Lucianib5e62212009-01-31 22:36:20 +000025namespace apache { namespace thrift { namespace protocol {
David Reisse0e3d1b2008-04-08 05:06:45 +000026
T Jake Lucianib5e62212009-01-31 22:36:20 +000027using apache::thrift::transport::TTransport;
David Reisse0e3d1b2008-04-08 05:06:45 +000028
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 *
David Reisse0e3d1b2008-04-08 05:06:45 +000034 */
David Reiss6806fb82010-10-06 17:09:52 +000035class TProtocolTap : public TVirtualProtocol<TProtocolTap> {
David Reisse0e3d1b2008-04-08 05:06:45 +000036 public:
37 TProtocolTap(boost::shared_ptr<TProtocol> source,
38 boost::shared_ptr<TProtocol> sink)
David Reiss6806fb82010-10-06 17:09:52 +000039 : TVirtualProtocol<TProtocolTap>(source->getTransport())
David Reisse0e3d1b2008-04-08 05:06:45 +000040 , source_(source)
41 , sink_(sink)
42 {}
43
David Reiss6806fb82010-10-06 17:09:52 +000044 uint32_t readMessageBegin(std::string& name,
45 TMessageType& messageType,
46 int32_t& seqid) {
David Reisse0e3d1b2008-04-08 05:06:45 +000047 uint32_t rv = source_->readMessageBegin(name, messageType, seqid);
48 sink_->writeMessageBegin(name, messageType, seqid);
49 return rv;
50 }
51
David Reiss6806fb82010-10-06 17:09:52 +000052 uint32_t readMessageEnd() {
David Reisse0e3d1b2008-04-08 05:06:45 +000053 uint32_t rv = source_->readMessageEnd();
54 sink_->writeMessageEnd();
55 return rv;
56 }
57
David Reiss6806fb82010-10-06 17:09:52 +000058 uint32_t readStructBegin(std::string& name) {
David Reisse0e3d1b2008-04-08 05:06:45 +000059 uint32_t rv = source_->readStructBegin(name);
David Reiss64120002008-04-29 23:12:24 +000060 sink_->writeStructBegin(name.c_str());
David Reisse0e3d1b2008-04-08 05:06:45 +000061 return rv;
62 }
63
David Reiss6806fb82010-10-06 17:09:52 +000064 uint32_t readStructEnd() {
David Reisse0e3d1b2008-04-08 05:06:45 +000065 uint32_t rv = source_->readStructEnd();
66 sink_->writeStructEnd();
67 return rv;
68 }
69
David Reiss6806fb82010-10-06 17:09:52 +000070 uint32_t readFieldBegin(std::string& name,
71 TType& fieldType,
72 int16_t& fieldId) {
David Reisse0e3d1b2008-04-08 05:06:45 +000073 uint32_t rv = source_->readFieldBegin(name, fieldType, fieldId);
74 if (fieldType == T_STOP) {
75 sink_->writeFieldStop();
76 } else {
David Reiss64120002008-04-29 23:12:24 +000077 sink_->writeFieldBegin(name.c_str(), fieldType, fieldId);
David Reisse0e3d1b2008-04-08 05:06:45 +000078 }
79 return rv;
80 }
81
82
David Reiss6806fb82010-10-06 17:09:52 +000083 uint32_t readFieldEnd() {
David Reisse0e3d1b2008-04-08 05:06:45 +000084 uint32_t rv = source_->readFieldEnd();
85 sink_->writeFieldEnd();
86 return rv;
87 }
88
David Reiss6806fb82010-10-06 17:09:52 +000089 uint32_t readMapBegin(TType& keyType,
90 TType& valType,
91 uint32_t& size) {
David Reisse0e3d1b2008-04-08 05:06:45 +000092 uint32_t rv = source_->readMapBegin(keyType, valType, size);
93 sink_->writeMapBegin(keyType, valType, size);
94 return rv;
95 }
96
97
David Reiss6806fb82010-10-06 17:09:52 +000098 uint32_t readMapEnd() {
David Reisse0e3d1b2008-04-08 05:06:45 +000099 uint32_t rv = source_->readMapEnd();
100 sink_->writeMapEnd();
101 return rv;
102 }
103
David Reiss6806fb82010-10-06 17:09:52 +0000104 uint32_t readListBegin(TType& elemType, uint32_t& size) {
David Reisse0e3d1b2008-04-08 05:06:45 +0000105 uint32_t rv = source_->readListBegin(elemType, size);
106 sink_->writeListBegin(elemType, size);
107 return rv;
108 }
109
110
David Reiss6806fb82010-10-06 17:09:52 +0000111 uint32_t readListEnd() {
David Reisse0e3d1b2008-04-08 05:06:45 +0000112 uint32_t rv = source_->readListEnd();
113 sink_->writeListEnd();
114 return rv;
115 }
116
David Reiss6806fb82010-10-06 17:09:52 +0000117 uint32_t readSetBegin(TType& elemType, uint32_t& size) {
David Reisse0e3d1b2008-04-08 05:06:45 +0000118 uint32_t rv = source_->readSetBegin(elemType, size);
119 sink_->writeSetBegin(elemType, size);
120 return rv;
121 }
122
123
David Reiss6806fb82010-10-06 17:09:52 +0000124 uint32_t readSetEnd() {
David Reisse0e3d1b2008-04-08 05:06:45 +0000125 uint32_t rv = source_->readSetEnd();
126 sink_->writeSetEnd();
127 return rv;
128 }
129
David Reiss6806fb82010-10-06 17:09:52 +0000130 uint32_t readBool(bool& value) {
David Reisse0e3d1b2008-04-08 05:06:45 +0000131 uint32_t rv = source_->readBool(value);
132 sink_->writeBool(value);
133 return rv;
134 }
135
David Reiss6806fb82010-10-06 17:09:52 +0000136 uint32_t readByte(int8_t& byte) {
David Reisse0e3d1b2008-04-08 05:06:45 +0000137 uint32_t rv = source_->readByte(byte);
138 sink_->writeByte(byte);
139 return rv;
140 }
141
David Reiss6806fb82010-10-06 17:09:52 +0000142 uint32_t readI16(int16_t& i16) {
David Reisse0e3d1b2008-04-08 05:06:45 +0000143 uint32_t rv = source_->readI16(i16);
144 sink_->writeI16(i16);
145 return rv;
146 }
147
David Reiss6806fb82010-10-06 17:09:52 +0000148 uint32_t readI32(int32_t& i32) {
David Reisse0e3d1b2008-04-08 05:06:45 +0000149 uint32_t rv = source_->readI32(i32);
150 sink_->writeI32(i32);
151 return rv;
152 }
153
David Reiss6806fb82010-10-06 17:09:52 +0000154 uint32_t readI64(int64_t& i64) {
David Reisse0e3d1b2008-04-08 05:06:45 +0000155 uint32_t rv = source_->readI64(i64);
156 sink_->writeI64(i64);
157 return rv;
158 }
159
David Reiss6806fb82010-10-06 17:09:52 +0000160 uint32_t readDouble(double& dub) {
David Reisse0e3d1b2008-04-08 05:06:45 +0000161 uint32_t rv = source_->readDouble(dub);
162 sink_->writeDouble(dub);
163 return rv;
164 }
165
David Reiss6806fb82010-10-06 17:09:52 +0000166 uint32_t readString(std::string& str) {
David Reisse0e3d1b2008-04-08 05:06:45 +0000167 uint32_t rv = source_->readString(str);
168 sink_->writeString(str);
169 return rv;
170 }
171
David Reiss6806fb82010-10-06 17:09:52 +0000172 uint32_t readBinary(std::string& str) {
David Reisse0e3d1b2008-04-08 05:06:45 +0000173 uint32_t rv = source_->readBinary(str);
174 sink_->writeBinary(str);
175 return rv;
176 }
177
178 private:
179 boost::shared_ptr<TProtocol> source_;
180 boost::shared_ptr<TProtocol> sink_;
181};
182
T Jake Lucianib5e62212009-01-31 22:36:20 +0000183}}} // apache::thrift::protocol
David Reisse0e3d1b2008-04-08 05:06:45 +0000184
185#endif // #define _THRIFT_PROTOCOL_TPROTOCOLTAP_H_ 1