Add TProtocolTap: a meta-protocol for "wiretapping".
TProtocolTap is a protocol that passes reads through to a "source" protocol,
but mirrors them as writes to a "sink" protocol.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665643 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/protocol/TOneWayProtocol.h b/lib/cpp/src/protocol/TOneWayProtocol.h
index 1765413..3c31d1e 100644
--- a/lib/cpp/src/protocol/TOneWayProtocol.h
+++ b/lib/cpp/src/protocol/TOneWayProtocol.h
@@ -146,6 +146,148 @@
std::string subclass_;
};
+
+/**
+ * Abstract class for implementing a protocol that can only be read,
+ * not written.
+ *
+ * @author David Reiss <dreiss@facebook.com>
+ */
+class TReadOnlyProtocol : public TProtocol {
+ public:
+ /**
+ * @param subclass_name The name of the concrete subclass.
+ */
+ TReadOnlyProtocol(boost::shared_ptr<TTransport> trans,
+ const std::string& subclass_name)
+ : TProtocol(trans)
+ , subclass_(subclass_name)
+ {}
+
+ // All reading functions remain abstract.
+
+ /**
+ * Writing functions all throw an exception.
+ */
+
+ uint32_t writeMessageBegin(const std::string& name,
+ const TMessageType messageType,
+ const int32_t seqid) {
+ throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
+ subclass_ + " does not support writing (yet).");
+ }
+
+ uint32_t writeMessageEnd() {
+ throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
+ subclass_ + " does not support writing (yet).");
+ }
+
+
+ uint32_t writeStructBegin(const std::string& name) {
+ throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
+ subclass_ + " does not support writing (yet).");
+ }
+
+ uint32_t writeStructEnd() {
+ throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
+ subclass_ + " does not support writing (yet).");
+ }
+
+ uint32_t writeFieldBegin(const std::string& name,
+ const TType fieldType,
+ const int16_t fieldId) {
+ throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
+ subclass_ + " does not support writing (yet).");
+ }
+
+ uint32_t writeFieldEnd() {
+ throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
+ subclass_ + " does not support writing (yet).");
+ }
+
+ uint32_t writeFieldStop() {
+ throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
+ subclass_ + " does not support writing (yet).");
+ }
+
+ uint32_t writeMapBegin(const TType keyType,
+ const TType valType,
+ const uint32_t size) {
+ throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
+ subclass_ + " does not support writing (yet).");
+ }
+
+ uint32_t writeMapEnd() {
+ throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
+ subclass_ + " does not support writing (yet).");
+ }
+
+ uint32_t writeListBegin(const TType elemType,
+ const uint32_t size) {
+ throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
+ subclass_ + " does not support writing (yet).");
+ }
+
+ uint32_t writeListEnd() {
+ throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
+ subclass_ + " does not support writing (yet).");
+ }
+
+ uint32_t writeSetBegin(const TType elemType,
+ const uint32_t size) {
+ throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
+ subclass_ + " does not support writing (yet).");
+ }
+
+ uint32_t writeSetEnd() {
+ throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
+ subclass_ + " does not support writing (yet).");
+ }
+
+ uint32_t writeBool(const bool value) {
+ throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
+ subclass_ + " does not support writing (yet).");
+ }
+
+ uint32_t writeByte(const int8_t byte) {
+ throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
+ subclass_ + " does not support writing (yet).");
+ }
+
+ uint32_t writeI16(const int16_t i16) {
+ throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
+ subclass_ + " does not support writing (yet).");
+ }
+
+ uint32_t writeI32(const int32_t i32) {
+ throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
+ subclass_ + " does not support writing (yet).");
+ }
+
+ uint32_t writeI64(const int64_t i64) {
+ throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
+ subclass_ + " does not support writing (yet).");
+ }
+
+ uint32_t writeDouble(const double dub) {
+ throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
+ subclass_ + " does not support writing (yet).");
+ }
+
+ uint32_t writeString(const std::string& str) {
+ throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
+ subclass_ + " does not support writing (yet).");
+ }
+
+ uint32_t writeBinary(const std::string& str) {
+ throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
+ subclass_ + " does not support writing (yet).");
+ }
+
+ private:
+ std::string subclass_;
+};
+
}}} // facebook::thrift::protocol
#endif // #ifndef _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_