File indexing completed on 2026-04-17 08:35:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef _THRIFT_TDISPATCHPROCESSOR_H_
0020 #define _THRIFT_TDISPATCHPROCESSOR_H_ 1
0021
0022 #include <thrift/TProcessor.h>
0023
0024 namespace apache {
0025 namespace thrift {
0026
0027
0028
0029
0030
0031
0032
0033 template <class Protocol_>
0034 class TDispatchProcessorT : public TProcessor {
0035 public:
0036 bool process(std::shared_ptr<protocol::TProtocol> in,
0037 std::shared_ptr<protocol::TProtocol> out,
0038 void* connectionContext) override {
0039 protocol::TProtocol* inRaw = in.get();
0040 protocol::TProtocol* outRaw = out.get();
0041
0042
0043 auto* specificIn = dynamic_cast<Protocol_*>(inRaw);
0044 auto* specificOut = dynamic_cast<Protocol_*>(outRaw);
0045 if (specificIn && specificOut) {
0046 return processFast(specificIn, specificOut, connectionContext);
0047 }
0048
0049
0050 T_GENERIC_PROTOCOL(this, inRaw, specificIn);
0051 T_GENERIC_PROTOCOL(this, outRaw, specificOut);
0052
0053 std::string fname;
0054 protocol::TMessageType mtype;
0055 int32_t seqid;
0056 inRaw->readMessageBegin(fname, mtype, seqid);
0057
0058
0059
0060
0061
0062
0063 if (mtype != protocol::T_CALL && mtype != protocol::T_ONEWAY) {
0064 GlobalOutput.printf("received invalid message type %d from client", mtype);
0065 return false;
0066 }
0067
0068 return this->dispatchCall(inRaw, outRaw, fname, seqid, connectionContext);
0069 }
0070
0071 protected:
0072 bool processFast(Protocol_* in, Protocol_* out, void* connectionContext) {
0073 std::string fname;
0074 protocol::TMessageType mtype;
0075 int32_t seqid;
0076 in->readMessageBegin(fname, mtype, seqid);
0077
0078 if (mtype != protocol::T_CALL && mtype != protocol::T_ONEWAY) {
0079 GlobalOutput.printf("received invalid message type %d from client", mtype);
0080 return false;
0081 }
0082
0083 return this->dispatchCallTemplated(in, out, fname, seqid, connectionContext);
0084 }
0085
0086
0087
0088
0089 virtual bool dispatchCall(apache::thrift::protocol::TProtocol* in,
0090 apache::thrift::protocol::TProtocol* out,
0091 const std::string& fname,
0092 int32_t seqid,
0093 void* callContext) = 0;
0094
0095 virtual bool dispatchCallTemplated(Protocol_* in,
0096 Protocol_* out,
0097 const std::string& fname,
0098 int32_t seqid,
0099 void* callContext) = 0;
0100 };
0101
0102
0103
0104
0105
0106 class TDispatchProcessor : public TProcessor {
0107 public:
0108 bool process(std::shared_ptr<protocol::TProtocol> in,
0109 std::shared_ptr<protocol::TProtocol> out,
0110 void* connectionContext) override {
0111 std::string fname;
0112 protocol::TMessageType mtype;
0113 int32_t seqid;
0114 in->readMessageBegin(fname, mtype, seqid);
0115
0116 if (mtype != protocol::T_CALL && mtype != protocol::T_ONEWAY) {
0117 GlobalOutput.printf("received invalid message type %d from client", mtype);
0118 return false;
0119 }
0120
0121 return dispatchCall(in.get(), out.get(), fname, seqid, connectionContext);
0122 }
0123
0124 protected:
0125 virtual bool dispatchCall(apache::thrift::protocol::TProtocol* in,
0126 apache::thrift::protocol::TProtocol* out,
0127 const std::string& fname,
0128 int32_t seqid,
0129 void* callContext) = 0;
0130 };
0131
0132
0133
0134 template <>
0135 class TDispatchProcessorT<protocol::TDummyProtocol> : public TDispatchProcessor {};
0136 template <>
0137 class TDispatchProcessorT<protocol::TProtocol> : public TDispatchProcessor {};
0138 }
0139 }
0140
0141 #endif