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