Change Thrift c++ to new protocol wrapping transport model
Summary: Also cleaned up excessive .h/.cpp files into Utils files
Reviewed By: aditya
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664838 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/protocol/TBinaryProtocol.h b/lib/cpp/src/protocol/TBinaryProtocol.h
index 7f36a57..de9a836 100644
--- a/lib/cpp/src/protocol/TBinaryProtocol.h
+++ b/lib/cpp/src/protocol/TBinaryProtocol.h
@@ -17,139 +17,130 @@
*/
class TBinaryProtocol : public TProtocol {
public:
- TBinaryProtocol() {}
+ TBinaryProtocol(shared_ptr<TTransport> in, shared_ptr<TTransport> out) :
+ TProtocol(in, out) {}
+
~TBinaryProtocol() {}
/**
* Writing functions.
*/
- virtual uint32_t writeMessageBegin(shared_ptr<TTransport> out,
- const std::string name,
+ virtual uint32_t writeMessageBegin(const std::string name,
const TMessageType messageType,
- const int32_t seqid) const;
+ const int32_t seqid);
- virtual uint32_t writeMessageEnd(shared_ptr<TTransport> out) const;
+ virtual uint32_t writeMessageEnd();
- uint32_t writeStructBegin(shared_ptr<TTransport> out,
- const std::string& name) const;
+ uint32_t writeStructBegin(const std::string& name);
- uint32_t writeStructEnd(shared_ptr<TTransport> out) const;
+ uint32_t writeStructEnd();
- uint32_t writeFieldBegin(shared_ptr<TTransport> out,
- const std::string& name,
- const TType fieldType,
- const int16_t fieldId) const;
+ uint32_t writeFieldBegin(const std::string& name,
+ const TType fieldType,
+ const int16_t fieldId);
- uint32_t writeFieldEnd(shared_ptr<TTransport> out) const;
+ uint32_t writeFieldEnd();
- uint32_t writeFieldStop(shared_ptr<TTransport> out) const;
+ uint32_t writeFieldStop();
- uint32_t writeMapBegin(shared_ptr<TTransport> out,
- const TType keyType,
- const TType valType,
- const uint32_t size) const;
+ uint32_t writeMapBegin(const TType keyType,
+ const TType valType,
+ const uint32_t size);
- uint32_t writeMapEnd(shared_ptr<TTransport> out) const;
+ uint32_t writeMapEnd();
- uint32_t writeListBegin(shared_ptr<TTransport> out,
- const TType elemType,
- const uint32_t size) const;
+ uint32_t writeListBegin(const TType elemType,
+ const uint32_t size);
- uint32_t writeListEnd(shared_ptr<TTransport> out) const;
+ uint32_t writeListEnd();
- uint32_t writeSetBegin(shared_ptr<TTransport> out,
- const TType elemType,
- const uint32_t size) const;
+ uint32_t writeSetBegin(const TType elemType,
+ const uint32_t size);
- uint32_t writeSetEnd(shared_ptr<TTransport> out) const;
+ uint32_t writeSetEnd();
- uint32_t writeBool(shared_ptr<TTransport> out,
- const bool value) const;
+ uint32_t writeBool(const bool value);
- uint32_t writeByte(shared_ptr<TTransport> out,
- const int8_t byte) const;
+ uint32_t writeByte(const int8_t byte);
- uint32_t writeI16(shared_ptr<TTransport> out,
- const int16_t i16) const;
+ uint32_t writeI16(const int16_t i16);
- uint32_t writeI32(shared_ptr<TTransport> out,
- const int32_t i32) const;
+ uint32_t writeI32(const int32_t i32);
- uint32_t writeI64(shared_ptr<TTransport> out,
- const int64_t i64) const;
+ uint32_t writeI64(const int64_t i64);
- uint32_t writeDouble(shared_ptr<TTransport> out,
- const double dub) const;
+ uint32_t writeDouble(const double dub);
- uint32_t writeString(shared_ptr<TTransport> out,
- const std::string& str) const;
+ uint32_t writeString(const std::string& str);
/**
* Reading functions
*/
- uint32_t readMessageBegin(shared_ptr<TTransport> in,
- std::string& name,
+ uint32_t readMessageBegin(std::string& name,
TMessageType& messageType,
- int32_t& seqid) const;
+ int32_t& seqid);
- uint32_t readMessageEnd(shared_ptr<TTransport> in) const;
+ uint32_t readMessageEnd();
- uint32_t readStructBegin(shared_ptr<TTransport> in,
- std::string& name) const;
+ uint32_t readStructBegin(std::string& name);
- uint32_t readStructEnd(shared_ptr<TTransport> in) const;
+ uint32_t readStructEnd();
- uint32_t readFieldBegin(shared_ptr<TTransport> in,
- std::string& name,
- TType& fieldType,
- int16_t& fieldId) const;
+ uint32_t readFieldBegin(std::string& name,
+ TType& fieldType,
+ int16_t& fieldId);
- uint32_t readFieldEnd(shared_ptr<TTransport> in) const;
+ uint32_t readFieldEnd();
- uint32_t readMapBegin(shared_ptr<TTransport> in,
- TType& keyType,
- TType& valType,
- uint32_t& size) const;
+ uint32_t readMapBegin(TType& keyType,
+ TType& valType,
+ uint32_t& size);
- uint32_t readMapEnd(shared_ptr<TTransport> in) const;
+ uint32_t readMapEnd();
- uint32_t readListBegin(shared_ptr<TTransport> in,
- TType& elemType,
- uint32_t& size) const;
+ uint32_t readListBegin(TType& elemType,
+ uint32_t& size);
- uint32_t readListEnd(shared_ptr<TTransport> in) const;
+ uint32_t readListEnd();
- uint32_t readSetBegin(shared_ptr<TTransport> in,
- TType& elemType,
- uint32_t& size) const;
+ uint32_t readSetBegin(TType& elemType,
+ uint32_t& size);
- uint32_t readSetEnd(shared_ptr<TTransport> in) const;
+ uint32_t readSetEnd();
- uint32_t readBool(shared_ptr<TTransport> in,
- bool& value) const;
+ uint32_t readBool(bool& value);
- uint32_t readByte(shared_ptr<TTransport> in,
- int8_t& byte) const;
+ uint32_t readByte(int8_t& byte);
- uint32_t readI16(shared_ptr<TTransport> in,
- int16_t& i16) const;
+ uint32_t readI16(int16_t& i16);
- uint32_t readI32(shared_ptr<TTransport> in,
- int32_t& i32) const;
+ uint32_t readI32(int32_t& i32);
- uint32_t readI64(shared_ptr<TTransport> in,
- int64_t& i64) const;
+ uint32_t readI64(int64_t& i64);
- uint32_t readDouble(shared_ptr<TTransport> in,
- double& dub) const;
+ uint32_t readDouble(double& dub);
- uint32_t readString(shared_ptr<TTransport> in,
- std::string& str) const;
+ uint32_t readString(std::string& str);
+};
+
+/**
+ * Constructs binary protocol handlers
+ */
+class TBinaryProtocolFactory : public TProtocolFactory {
+ public:
+ TBinaryProtocolFactory() {}
+
+ virtual ~TBinaryProtocolFactory() {}
+
+ std::pair<boost::shared_ptr<TProtocol>, boost::shared_ptr<TProtocol> > getIOProtocols(boost::shared_ptr<TTransport> in, boost::shared_ptr<TTransport> out) {
+ boost::shared_ptr<TProtocol> prot(new TBinaryProtocol(in, out));
+ return std::make_pair(prot, prot);
+ }
};
}}} // facebook::thrift::protocol