Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 08:35:02

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one
0003  * or more contributor license agreements. See the NOTICE file
0004  * distributed with this work for additional information
0005  * regarding copyright ownership. The ASF licenses this file
0006  * to you under the Apache License, Version 2.0 (the
0007  * "License"); you may not use this file except in compliance
0008  * with the License. You may obtain a copy of the License at
0009  *
0010  *   http://www.apache.org/licenses/LICENSE-2.0
0011  *
0012  * Unless required by applicable law or agreed to in writing,
0013  * software distributed under the License is distributed on an
0014  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0015  * KIND, either express or implied. See the License for the
0016  * specific language governing permissions and limitations
0017  * under the License.
0018  */
0019 
0020 #ifndef _THRIFT_PROTOCOL_TPROTOCOLTAP_H_
0021 #define _THRIFT_PROTOCOL_TPROTOCOLTAP_H_ 1
0022 
0023 #include <thrift/protocol/TVirtualProtocol.h>
0024 
0025 namespace apache {
0026 namespace thrift {
0027 namespace protocol {
0028 
0029 using apache::thrift::transport::TTransport;
0030 
0031 /**
0032  * Puts a wiretap on a protocol object.  Any reads to this class are passed
0033  * through to an enclosed protocol object, but also mirrored as write to a
0034  * second protocol object.
0035  *
0036  */
0037 class TProtocolTap : public TVirtualProtocol<TProtocolTap> {
0038 public:
0039   TProtocolTap(std::shared_ptr<TProtocol> source, std::shared_ptr<TProtocol> sink)
0040     : TVirtualProtocol<TProtocolTap>(source->getTransport()), source_(source), sink_(sink) {}
0041 
0042   uint32_t readMessageBegin(std::string& name, TMessageType& messageType, int32_t& seqid) {
0043     uint32_t rv = source_->readMessageBegin(name, messageType, seqid);
0044     sink_->writeMessageBegin(name, messageType, seqid);
0045     return rv;
0046   }
0047 
0048   uint32_t readMessageEnd() {
0049     uint32_t rv = source_->readMessageEnd();
0050     sink_->writeMessageEnd();
0051     return rv;
0052   }
0053 
0054   uint32_t readStructBegin(std::string& name) {
0055     uint32_t rv = source_->readStructBegin(name);
0056     sink_->writeStructBegin(name.c_str());
0057     return rv;
0058   }
0059 
0060   uint32_t readStructEnd() {
0061     uint32_t rv = source_->readStructEnd();
0062     sink_->writeStructEnd();
0063     return rv;
0064   }
0065 
0066   uint32_t readFieldBegin(std::string& name, TType& fieldType, int16_t& fieldId) {
0067     uint32_t rv = source_->readFieldBegin(name, fieldType, fieldId);
0068     if (fieldType == T_STOP) {
0069       sink_->writeFieldStop();
0070     } else {
0071       sink_->writeFieldBegin(name.c_str(), fieldType, fieldId);
0072     }
0073     return rv;
0074   }
0075 
0076   uint32_t readFieldEnd() {
0077     uint32_t rv = source_->readFieldEnd();
0078     sink_->writeFieldEnd();
0079     return rv;
0080   }
0081 
0082   uint32_t readMapBegin(TType& keyType, TType& valType, uint32_t& size) {
0083     uint32_t rv = source_->readMapBegin(keyType, valType, size);
0084     sink_->writeMapBegin(keyType, valType, size);
0085     return rv;
0086   }
0087 
0088   uint32_t readMapEnd() {
0089     uint32_t rv = source_->readMapEnd();
0090     sink_->writeMapEnd();
0091     return rv;
0092   }
0093 
0094   uint32_t readListBegin(TType& elemType, uint32_t& size) {
0095     uint32_t rv = source_->readListBegin(elemType, size);
0096     sink_->writeListBegin(elemType, size);
0097     return rv;
0098   }
0099 
0100   uint32_t readListEnd() {
0101     uint32_t rv = source_->readListEnd();
0102     sink_->writeListEnd();
0103     return rv;
0104   }
0105 
0106   uint32_t readSetBegin(TType& elemType, uint32_t& size) {
0107     uint32_t rv = source_->readSetBegin(elemType, size);
0108     sink_->writeSetBegin(elemType, size);
0109     return rv;
0110   }
0111 
0112   uint32_t readSetEnd() {
0113     uint32_t rv = source_->readSetEnd();
0114     sink_->writeSetEnd();
0115     return rv;
0116   }
0117 
0118   uint32_t readBool(bool& value) {
0119     uint32_t rv = source_->readBool(value);
0120     sink_->writeBool(value);
0121     return rv;
0122   }
0123 
0124   // Provide the default readBool() implementation for std::vector<bool>
0125   using TVirtualProtocol<TProtocolTap>::readBool;
0126 
0127   uint32_t readByte(int8_t& byte) {
0128     uint32_t rv = source_->readByte(byte);
0129     sink_->writeByte(byte);
0130     return rv;
0131   }
0132 
0133   uint32_t readI16(int16_t& i16) {
0134     uint32_t rv = source_->readI16(i16);
0135     sink_->writeI16(i16);
0136     return rv;
0137   }
0138 
0139   uint32_t readI32(int32_t& i32) {
0140     uint32_t rv = source_->readI32(i32);
0141     sink_->writeI32(i32);
0142     return rv;
0143   }
0144 
0145   uint32_t readI64(int64_t& i64) {
0146     uint32_t rv = source_->readI64(i64);
0147     sink_->writeI64(i64);
0148     return rv;
0149   }
0150 
0151   uint32_t readDouble(double& dub) {
0152     uint32_t rv = source_->readDouble(dub);
0153     sink_->writeDouble(dub);
0154     return rv;
0155   }
0156 
0157   uint32_t readString(std::string& str) {
0158     uint32_t rv = source_->readString(str);
0159     sink_->writeString(str);
0160     return rv;
0161   }
0162 
0163   uint32_t readBinary(std::string& str) {
0164     uint32_t rv = source_->readBinary(str);
0165     sink_->writeBinary(str);
0166     return rv;
0167   }
0168 
0169 private:
0170   std::shared_ptr<TProtocol> source_;
0171   std::shared_ptr<TProtocol> sink_;
0172 };
0173 }
0174 }
0175 } // apache::thrift::protocol
0176 
0177 #endif // #define _THRIFT_PROTOCOL_TPROTOCOLTAP_H_ 1