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_TVIRTUALPROTOCOL_H_
0021 #define _THRIFT_PROTOCOL_TVIRTUALPROTOCOL_H_ 1
0022 
0023 #include <thrift/protocol/TProtocol.h>
0024 
0025 namespace apache {
0026 namespace thrift {
0027 namespace protocol {
0028 
0029 using apache::thrift::transport::TTransport;
0030 
0031 /**
0032  * Helper class that provides default implementations of TProtocol methods.
0033  *
0034  * This class provides default implementations of the non-virtual TProtocol
0035  * methods.  It exists primarily so TVirtualProtocol can derive from it.  It
0036  * prevents TVirtualProtocol methods from causing infinite recursion if the
0037  * non-virtual methods are not overridden by the TVirtualProtocol subclass.
0038  *
0039  * You probably don't want to use this class directly.  Use TVirtualProtocol
0040  * instead.
0041  */
0042 class TProtocolDefaults : public TProtocol {
0043 public:
0044   uint32_t readMessageBegin(std::string& name, TMessageType& messageType, int32_t& seqid) {
0045     (void)name;
0046     (void)messageType;
0047     (void)seqid;
0048     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0049                              "this protocol does not support reading (yet).");
0050   }
0051 
0052   uint32_t readMessageEnd() {
0053     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0054                              "this protocol does not support reading (yet).");
0055   }
0056 
0057   uint32_t readStructBegin(std::string& name) {
0058     (void)name;
0059     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0060                              "this protocol does not support reading (yet).");
0061   }
0062 
0063   uint32_t readStructEnd() {
0064     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0065                              "this protocol does not support reading (yet).");
0066   }
0067 
0068   uint32_t readFieldBegin(std::string& name, TType& fieldType, int16_t& fieldId) {
0069     (void)name;
0070     (void)fieldType;
0071     (void)fieldId;
0072     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0073                              "this protocol does not support reading (yet).");
0074   }
0075 
0076   uint32_t readFieldEnd() {
0077     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0078                              "this protocol does not support reading (yet).");
0079   }
0080 
0081   uint32_t readMapBegin(TType& keyType, TType& valType, uint32_t& size) {
0082     (void)keyType;
0083     (void)valType;
0084     (void)size;
0085     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0086                              "this protocol does not support reading (yet).");
0087   }
0088 
0089   uint32_t readMapEnd() {
0090     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0091                              "this protocol does not support reading (yet).");
0092   }
0093 
0094   uint32_t readListBegin(TType& elemType, uint32_t& size) {
0095     (void)elemType;
0096     (void)size;
0097     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0098                              "this protocol does not support reading (yet).");
0099   }
0100 
0101   uint32_t readListEnd() {
0102     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0103                              "this protocol does not support reading (yet).");
0104   }
0105 
0106   uint32_t readSetBegin(TType& elemType, uint32_t& size) {
0107     (void)elemType;
0108     (void)size;
0109     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0110                              "this protocol does not support reading (yet).");
0111   }
0112 
0113   uint32_t readSetEnd() {
0114     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0115                              "this protocol does not support reading (yet).");
0116   }
0117 
0118   uint32_t readBool(bool& value) {
0119     (void)value;
0120     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0121                              "this protocol does not support reading (yet).");
0122   }
0123 
0124   uint32_t readBool(std::vector<bool>::reference value) {
0125     (void)value;
0126     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0127                              "this protocol does not support reading (yet).");
0128   }
0129 
0130   uint32_t readByte(int8_t& byte) {
0131     (void)byte;
0132     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0133                              "this protocol does not support reading (yet).");
0134   }
0135 
0136   uint32_t readI16(int16_t& i16) {
0137     (void)i16;
0138     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0139                              "this protocol does not support reading (yet).");
0140   }
0141 
0142   uint32_t readI32(int32_t& i32) {
0143     (void)i32;
0144     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0145                              "this protocol does not support reading (yet).");
0146   }
0147 
0148   uint32_t readI64(int64_t& i64) {
0149     (void)i64;
0150     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0151                              "this protocol does not support reading (yet).");
0152   }
0153 
0154   uint32_t readDouble(double& dub) {
0155     (void)dub;
0156     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0157                              "this protocol does not support reading (yet).");
0158   }
0159 
0160   uint32_t readString(std::string& str) {
0161     (void)str;
0162     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0163                              "this protocol does not support reading (yet).");
0164   }
0165 
0166   uint32_t readBinary(std::string& str) {
0167     (void)str;
0168     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0169                              "this protocol does not support reading (yet).");
0170   }
0171 
0172   uint32_t writeMessageBegin(const std::string& name,
0173                              const TMessageType messageType,
0174                              const int32_t seqid) {
0175     (void)name;
0176     (void)messageType;
0177     (void)seqid;
0178     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0179                              "this protocol does not support writing (yet).");
0180   }
0181 
0182   uint32_t writeMessageEnd() {
0183     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0184                              "this protocol does not support writing (yet).");
0185   }
0186 
0187   uint32_t writeStructBegin(const char* name) {
0188     (void)name;
0189     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0190                              "this protocol does not support writing (yet).");
0191   }
0192 
0193   uint32_t writeStructEnd() {
0194     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0195                              "this protocol does not support writing (yet).");
0196   }
0197 
0198   uint32_t writeFieldBegin(const char* name, const TType fieldType, const int16_t fieldId) {
0199     (void)name;
0200     (void)fieldType;
0201     (void)fieldId;
0202     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0203                              "this protocol does not support writing (yet).");
0204   }
0205 
0206   uint32_t writeFieldEnd() {
0207     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0208                              "this protocol does not support writing (yet).");
0209   }
0210 
0211   uint32_t writeFieldStop() {
0212     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0213                              "this protocol does not support writing (yet).");
0214   }
0215 
0216   uint32_t writeMapBegin(const TType keyType, const TType valType, const uint32_t size) {
0217     (void)keyType;
0218     (void)valType;
0219     (void)size;
0220     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0221                              "this protocol does not support writing (yet).");
0222   }
0223 
0224   uint32_t writeMapEnd() {
0225     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0226                              "this protocol does not support writing (yet).");
0227   }
0228 
0229   uint32_t writeListBegin(const TType elemType, const uint32_t size) {
0230     (void)elemType;
0231     (void)size;
0232     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0233                              "this protocol does not support writing (yet).");
0234   }
0235 
0236   uint32_t writeListEnd() {
0237     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0238                              "this protocol does not support writing (yet).");
0239   }
0240 
0241   uint32_t writeSetBegin(const TType elemType, const uint32_t size) {
0242     (void)elemType;
0243     (void)size;
0244     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0245                              "this protocol does not support writing (yet).");
0246   }
0247 
0248   uint32_t writeSetEnd() {
0249     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0250                              "this protocol does not support writing (yet).");
0251   }
0252 
0253   uint32_t writeBool(const bool value) {
0254     (void)value;
0255     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0256                              "this protocol does not support writing (yet).");
0257   }
0258 
0259   uint32_t writeByte(const int8_t byte) {
0260     (void)byte;
0261     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0262                              "this protocol does not support writing (yet).");
0263   }
0264 
0265   uint32_t writeI16(const int16_t i16) {
0266     (void)i16;
0267     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0268                              "this protocol does not support writing (yet).");
0269   }
0270 
0271   uint32_t writeI32(const int32_t i32) {
0272     (void)i32;
0273     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0274                              "this protocol does not support writing (yet).");
0275   }
0276 
0277   uint32_t writeI64(const int64_t i64) {
0278     (void)i64;
0279     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0280                              "this protocol does not support writing (yet).");
0281   }
0282 
0283   uint32_t writeDouble(const double dub) {
0284     (void)dub;
0285     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0286                              "this protocol does not support writing (yet).");
0287   }
0288 
0289   uint32_t writeString(const std::string& str) {
0290     (void)str;
0291     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0292                              "this protocol does not support writing (yet).");
0293   }
0294 
0295   uint32_t writeBinary(const std::string& str) {
0296     (void)str;
0297     throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
0298                              "this protocol does not support writing (yet).");
0299   }
0300 
0301   uint32_t skip(TType type) { return ::apache::thrift::protocol::skip(*this, type); }
0302 
0303 protected:
0304   TProtocolDefaults(std::shared_ptr<TTransport> ptrans) : TProtocol(ptrans) {}
0305 };
0306 
0307 /**
0308  * Concrete TProtocol classes should inherit from TVirtualProtocol
0309  * so they don't have to manually override virtual methods.
0310  */
0311 template <class Protocol_, class Super_ = TProtocolDefaults>
0312 class TVirtualProtocol : public Super_ {
0313 public:
0314   /**
0315    * Writing functions.
0316    */
0317 
0318   uint32_t writeMessageBegin_virt(const std::string& name,
0319                                           const TMessageType messageType,
0320                                           const int32_t seqid) override {
0321     return static_cast<Protocol_*>(this)->writeMessageBegin(name, messageType, seqid);
0322   }
0323 
0324   uint32_t writeMessageEnd_virt() override {
0325     return static_cast<Protocol_*>(this)->writeMessageEnd();
0326   }
0327 
0328   uint32_t writeStructBegin_virt(const char* name) override {
0329     return static_cast<Protocol_*>(this)->writeStructBegin(name);
0330   }
0331 
0332   uint32_t writeStructEnd_virt() override { return static_cast<Protocol_*>(this)->writeStructEnd(); }
0333 
0334   uint32_t writeFieldBegin_virt(const char* name,
0335                                         const TType fieldType,
0336                                         const int16_t fieldId) override {
0337     return static_cast<Protocol_*>(this)->writeFieldBegin(name, fieldType, fieldId);
0338   }
0339 
0340   uint32_t writeFieldEnd_virt() override { return static_cast<Protocol_*>(this)->writeFieldEnd(); }
0341 
0342   uint32_t writeFieldStop_virt() override { return static_cast<Protocol_*>(this)->writeFieldStop(); }
0343 
0344   uint32_t writeMapBegin_virt(const TType keyType,
0345                                       const TType valType,
0346                                       const uint32_t size) override {
0347     return static_cast<Protocol_*>(this)->writeMapBegin(keyType, valType, size);
0348   }
0349 
0350   uint32_t writeMapEnd_virt() override { return static_cast<Protocol_*>(this)->writeMapEnd(); }
0351 
0352   uint32_t writeListBegin_virt(const TType elemType, const uint32_t size) override {
0353     return static_cast<Protocol_*>(this)->writeListBegin(elemType, size);
0354   }
0355 
0356   uint32_t writeListEnd_virt() override { return static_cast<Protocol_*>(this)->writeListEnd(); }
0357 
0358   uint32_t writeSetBegin_virt(const TType elemType, const uint32_t size) override {
0359     return static_cast<Protocol_*>(this)->writeSetBegin(elemType, size);
0360   }
0361 
0362   uint32_t writeSetEnd_virt() override { return static_cast<Protocol_*>(this)->writeSetEnd(); }
0363 
0364   uint32_t writeBool_virt(const bool value) override {
0365     return static_cast<Protocol_*>(this)->writeBool(value);
0366   }
0367 
0368   uint32_t writeByte_virt(const int8_t byte) override {
0369     return static_cast<Protocol_*>(this)->writeByte(byte);
0370   }
0371 
0372   uint32_t writeI16_virt(const int16_t i16) override {
0373     return static_cast<Protocol_*>(this)->writeI16(i16);
0374   }
0375 
0376   uint32_t writeI32_virt(const int32_t i32) override {
0377     return static_cast<Protocol_*>(this)->writeI32(i32);
0378   }
0379 
0380   uint32_t writeI64_virt(const int64_t i64) override {
0381     return static_cast<Protocol_*>(this)->writeI64(i64);
0382   }
0383 
0384   uint32_t writeDouble_virt(const double dub) override {
0385     return static_cast<Protocol_*>(this)->writeDouble(dub);
0386   }
0387 
0388   uint32_t writeString_virt(const std::string& str) override {
0389     return static_cast<Protocol_*>(this)->writeString(str);
0390   }
0391 
0392   uint32_t writeBinary_virt(const std::string& str) override {
0393     return static_cast<Protocol_*>(this)->writeBinary(str);
0394   }
0395 
0396   uint32_t writeUUID_virt(const TUuid& uuid) override {
0397     return static_cast<Protocol_*>(this)->writeUUID(uuid);
0398   }
0399 
0400   /**
0401    * Reading functions
0402    */
0403 
0404   uint32_t readMessageBegin_virt(std::string& name,
0405                                          TMessageType& messageType,
0406                                          int32_t& seqid) override {
0407     return static_cast<Protocol_*>(this)->readMessageBegin(name, messageType, seqid);
0408   }
0409 
0410   uint32_t readMessageEnd_virt() override { return static_cast<Protocol_*>(this)->readMessageEnd(); }
0411 
0412   uint32_t readStructBegin_virt(std::string& name) override {
0413     return static_cast<Protocol_*>(this)->readStructBegin(name);
0414   }
0415 
0416   uint32_t readStructEnd_virt() override { return static_cast<Protocol_*>(this)->readStructEnd(); }
0417 
0418   uint32_t readFieldBegin_virt(std::string& name, TType& fieldType, int16_t& fieldId) override {
0419     return static_cast<Protocol_*>(this)->readFieldBegin(name, fieldType, fieldId);
0420   }
0421 
0422   uint32_t readFieldEnd_virt() override { return static_cast<Protocol_*>(this)->readFieldEnd(); }
0423 
0424   uint32_t readMapBegin_virt(TType& keyType, TType& valType, uint32_t& size) override {
0425     return static_cast<Protocol_*>(this)->readMapBegin(keyType, valType, size);
0426   }
0427 
0428   uint32_t readMapEnd_virt() override { return static_cast<Protocol_*>(this)->readMapEnd(); }
0429 
0430   uint32_t readListBegin_virt(TType& elemType, uint32_t& size) override {
0431     return static_cast<Protocol_*>(this)->readListBegin(elemType, size);
0432   }
0433 
0434   uint32_t readListEnd_virt() override { return static_cast<Protocol_*>(this)->readListEnd(); }
0435 
0436   uint32_t readSetBegin_virt(TType& elemType, uint32_t& size) override {
0437     return static_cast<Protocol_*>(this)->readSetBegin(elemType, size);
0438   }
0439 
0440   uint32_t readSetEnd_virt() override { return static_cast<Protocol_*>(this)->readSetEnd(); }
0441 
0442   uint32_t readBool_virt(bool& value) override {
0443     return static_cast<Protocol_*>(this)->readBool(value);
0444   }
0445 
0446   uint32_t readBool_virt(std::vector<bool>::reference value) override {
0447     return static_cast<Protocol_*>(this)->readBool(value);
0448   }
0449 
0450   uint32_t readByte_virt(int8_t& byte) override {
0451     return static_cast<Protocol_*>(this)->readByte(byte);
0452   }
0453 
0454   uint32_t readI16_virt(int16_t& i16) override {
0455     return static_cast<Protocol_*>(this)->readI16(i16);
0456   }
0457 
0458   uint32_t readI32_virt(int32_t& i32) override {
0459     return static_cast<Protocol_*>(this)->readI32(i32);
0460   }
0461 
0462   uint32_t readI64_virt(int64_t& i64) override {
0463     return static_cast<Protocol_*>(this)->readI64(i64);
0464   }
0465 
0466   uint32_t readDouble_virt(double& dub) override {
0467     return static_cast<Protocol_*>(this)->readDouble(dub);
0468   }
0469 
0470   uint32_t readString_virt(std::string& str) override {
0471     return static_cast<Protocol_*>(this)->readString(str);
0472   }
0473 
0474   uint32_t readBinary_virt(std::string& str) override {
0475     return static_cast<Protocol_*>(this)->readBinary(str);
0476   }
0477 
0478   uint32_t readUUID_virt(TUuid& uuid) override {
0479     return static_cast<Protocol_*>(this)->readUUID(uuid);
0480   }
0481 
0482   uint32_t skip_virt(TType type) override { return static_cast<Protocol_*>(this)->skip(type); }
0483 
0484   /*
0485    * Provide a default skip() implementation that uses non-virtual read
0486    * methods.
0487    *
0488    * Note: subclasses that use TVirtualProtocol to derive from another protocol
0489    * implementation (i.e., not TProtocolDefaults) should beware that this may
0490    * override any non-default skip() implementation provided by the parent
0491    * transport class.  They may need to explicitly redefine skip() to call the
0492    * correct parent implementation, if desired.
0493    */
0494   uint32_t skip(TType type) {
0495     auto* const prot = static_cast<Protocol_*>(this);
0496     return ::apache::thrift::protocol::skip(*prot, type);
0497   }
0498 
0499   /*
0500    * Provide a default readBool() implementation for use with
0501    * std::vector<bool>, that behaves the same as reading into a normal bool.
0502    *
0503    * Subclasses can override this if desired, but there normally shouldn't
0504    * be a need to.
0505    */
0506   uint32_t readBool(std::vector<bool>::reference value) {
0507     bool b = false;
0508     uint32_t ret = static_cast<Protocol_*>(this)->readBool(b);
0509     value = b;
0510     return ret;
0511   }
0512   using Super_::readBool; // so we don't hide readBool(bool&)
0513 
0514 protected:
0515   TVirtualProtocol(std::shared_ptr<TTransport> ptrans) : Super_(ptrans) {}
0516 };
0517 }
0518 }
0519 } // apache::thrift::protocol
0520 
0521 #endif // #define _THRIFT_PROTOCOL_TVIRTUALPROTOCOL_H_ 1