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_TPROTOCOLDECORATOR_H_ 21 #define THRIFT_TPROTOCOLDECORATOR_H_ 1 22 23 #include <thrift/protocol/TProtocol.h> 24 #include <memory> 25 26 namespace apache { 27 namespace thrift { 28 namespace protocol { 29 using std::shared_ptr; 30 31 /** 32 * <code>TProtocolDecorator</code> forwards all requests to an enclosed 33 * <code>TProtocol</code> instance, providing a way to author concise 34 * concrete decorator subclasses. 35 * 36 * <p>See p.175 of Design Patterns (by Gamma et al.)</p> 37 * 38 * @see apache::thrift::protocol::TMultiplexedProtocol 39 */ 40 class TProtocolDecorator : public TProtocol { 41 public: 42 ~TProtocolDecorator() override = default; 43 44 // Desc: Initializes the protocol decorator object. TProtocolDecorator(shared_ptr<TProtocol> proto)45 TProtocolDecorator(shared_ptr<TProtocol> proto) 46 : TProtocol(proto->getTransport()), protocol(proto) {} 47 writeMessageBegin_virt(const std::string & name,const TMessageType messageType,const int32_t seqid)48 uint32_t writeMessageBegin_virt(const std::string& name, 49 const TMessageType messageType, 50 const int32_t seqid) override { 51 return protocol->writeMessageBegin(name, messageType, seqid); 52 } writeMessageEnd_virt()53 uint32_t writeMessageEnd_virt() override { return protocol->writeMessageEnd(); } writeStructBegin_virt(const char * name)54 uint32_t writeStructBegin_virt(const char* name) override { 55 return protocol->writeStructBegin(name); 56 } writeStructEnd_virt()57 uint32_t writeStructEnd_virt() override { return protocol->writeStructEnd(); } 58 writeFieldBegin_virt(const char * name,const TType fieldType,const int16_t fieldId)59 uint32_t writeFieldBegin_virt(const char* name, 60 const TType fieldType, 61 const int16_t fieldId) override { 62 return protocol->writeFieldBegin(name, fieldType, fieldId); 63 } 64 writeFieldEnd_virt()65 uint32_t writeFieldEnd_virt() override { return protocol->writeFieldEnd(); } writeFieldStop_virt()66 uint32_t writeFieldStop_virt() override { return protocol->writeFieldStop(); } 67 writeMapBegin_virt(const TType keyType,const TType valType,const uint32_t size)68 uint32_t writeMapBegin_virt(const TType keyType, 69 const TType valType, 70 const uint32_t size) override { 71 return protocol->writeMapBegin(keyType, valType, size); 72 } 73 writeMapEnd_virt()74 uint32_t writeMapEnd_virt() override { return protocol->writeMapEnd(); } 75 writeListBegin_virt(const TType elemType,const uint32_t size)76 uint32_t writeListBegin_virt(const TType elemType, const uint32_t size) override { 77 return protocol->writeListBegin(elemType, size); 78 } writeListEnd_virt()79 uint32_t writeListEnd_virt() override { return protocol->writeListEnd(); } 80 writeSetBegin_virt(const TType elemType,const uint32_t size)81 uint32_t writeSetBegin_virt(const TType elemType, const uint32_t size) override { 82 return protocol->writeSetBegin(elemType, size); 83 } writeSetEnd_virt()84 uint32_t writeSetEnd_virt() override { return protocol->writeSetEnd(); } 85 writeBool_virt(const bool value)86 uint32_t writeBool_virt(const bool value) override { return protocol->writeBool(value); } writeByte_virt(const int8_t byte)87 uint32_t writeByte_virt(const int8_t byte) override { return protocol->writeByte(byte); } writeI16_virt(const int16_t i16)88 uint32_t writeI16_virt(const int16_t i16) override { return protocol->writeI16(i16); } writeI32_virt(const int32_t i32)89 uint32_t writeI32_virt(const int32_t i32) override { return protocol->writeI32(i32); } writeI64_virt(const int64_t i64)90 uint32_t writeI64_virt(const int64_t i64) override { return protocol->writeI64(i64); } 91 writeDouble_virt(const double dub)92 uint32_t writeDouble_virt(const double dub) override { return protocol->writeDouble(dub); } writeString_virt(const std::string & str)93 uint32_t writeString_virt(const std::string& str) override { return protocol->writeString(str); } writeBinary_virt(const std::string & str)94 uint32_t writeBinary_virt(const std::string& str) override { return protocol->writeBinary(str); } 95 readMessageBegin_virt(std::string & name,TMessageType & messageType,int32_t & seqid)96 uint32_t readMessageBegin_virt(std::string& name, 97 TMessageType& messageType, 98 int32_t& seqid) override { 99 return protocol->readMessageBegin(name, messageType, seqid); 100 } readMessageEnd_virt()101 uint32_t readMessageEnd_virt() override { return protocol->readMessageEnd(); } 102 readStructBegin_virt(std::string & name)103 uint32_t readStructBegin_virt(std::string& name) override { 104 return protocol->readStructBegin(name); 105 } readStructEnd_virt()106 uint32_t readStructEnd_virt() override { return protocol->readStructEnd(); } 107 readFieldBegin_virt(std::string & name,TType & fieldType,int16_t & fieldId)108 uint32_t readFieldBegin_virt(std::string& name, TType& fieldType, int16_t& fieldId) override { 109 return protocol->readFieldBegin(name, fieldType, fieldId); 110 } readFieldEnd_virt()111 uint32_t readFieldEnd_virt() override { return protocol->readFieldEnd(); } 112 readMapBegin_virt(TType & keyType,TType & valType,uint32_t & size)113 uint32_t readMapBegin_virt(TType& keyType, TType& valType, uint32_t& size) override { 114 return protocol->readMapBegin(keyType, valType, size); 115 } readMapEnd_virt()116 uint32_t readMapEnd_virt() override { return protocol->readMapEnd(); } 117 readListBegin_virt(TType & elemType,uint32_t & size)118 uint32_t readListBegin_virt(TType& elemType, uint32_t& size) override { 119 return protocol->readListBegin(elemType, size); 120 } readListEnd_virt()121 uint32_t readListEnd_virt() override { return protocol->readListEnd(); } 122 readSetBegin_virt(TType & elemType,uint32_t & size)123 uint32_t readSetBegin_virt(TType& elemType, uint32_t& size) override { 124 return protocol->readSetBegin(elemType, size); 125 } readSetEnd_virt()126 uint32_t readSetEnd_virt() override { return protocol->readSetEnd(); } 127 readBool_virt(bool & value)128 uint32_t readBool_virt(bool& value) override { return protocol->readBool(value); } readBool_virt(std::vector<bool>::reference value)129 uint32_t readBool_virt(std::vector<bool>::reference value) override { 130 return protocol->readBool(value); 131 } 132 readByte_virt(int8_t & byte)133 uint32_t readByte_virt(int8_t& byte) override { return protocol->readByte(byte); } 134 readI16_virt(int16_t & i16)135 uint32_t readI16_virt(int16_t& i16) override { return protocol->readI16(i16); } readI32_virt(int32_t & i32)136 uint32_t readI32_virt(int32_t& i32) override { return protocol->readI32(i32); } readI64_virt(int64_t & i64)137 uint32_t readI64_virt(int64_t& i64) override { return protocol->readI64(i64); } 138 readDouble_virt(double & dub)139 uint32_t readDouble_virt(double& dub) override { return protocol->readDouble(dub); } 140 readString_virt(std::string & str)141 uint32_t readString_virt(std::string& str) override { return protocol->readString(str); } readBinary_virt(std::string & str)142 uint32_t readBinary_virt(std::string& str) override { return protocol->readBinary(str); } 143 144 private: 145 shared_ptr<TProtocol> protocol; 146 }; 147 } 148 } 149 } 150 151 #endif // THRIFT_TPROTOCOLDECORATOR_H_ 152