Allow wrapping TTransportFactory into a TZlibTransportFactory
Client: cpp
diff --git a/lib/cpp/src/thrift/transport/TZlibTransport.cpp b/lib/cpp/src/thrift/transport/TZlibTransport.cpp
index 437190b..b4c43d6 100644
--- a/lib/cpp/src/thrift/transport/TZlibTransport.cpp
+++ b/lib/cpp/src/thrift/transport/TZlibTransport.cpp
@@ -397,6 +397,18 @@
"verifyChecksum() called before end of "
"zlib stream");
}
+
+TZlibTransportFactory::TZlibTransportFactory(std::shared_ptr<TTransportFactory> transportFactory)
+ :transportFactory_(transportFactory) {
+}
+
+std::shared_ptr<TTransport> TZlibTransportFactory::getTransport(std::shared_ptr<TTransport> trans) {
+ if (transportFactory_) {
+ return std::shared_ptr<TTransport>(new TZlibTransport(transportFactory_->getTransport(trans)));
+ } else {
+ return std::shared_ptr<TTransport>(new TZlibTransport(trans));
+ }
+}
}
}
} // apache::thrift::transport
diff --git a/lib/cpp/src/thrift/transport/TZlibTransport.h b/lib/cpp/src/thrift/transport/TZlibTransport.h
index 29afae0..4990aff 100644
--- a/lib/cpp/src/thrift/transport/TZlibTransport.h
+++ b/lib/cpp/src/thrift/transport/TZlibTransport.h
@@ -229,12 +229,19 @@
public:
TZlibTransportFactory() = default;
+ /**
+ * Wraps a transport factory into a zlibbed one.
+ */
+ TZlibTransportFactory(std::shared_ptr<TTransportFactory> transportFactory);
+
~TZlibTransportFactory() override = default;
- std::shared_ptr<TTransport> getTransport(std::shared_ptr<TTransport> trans) override {
- return std::shared_ptr<TTransport>(new TZlibTransport(trans));
- }
+ std::shared_ptr<TTransport> getTransport(std::shared_ptr<TTransport> trans) override;
+
+protected:
+ std::shared_ptr<TTransportFactory> transportFactory_;
};
+
}
}
} // apache::thrift::transport
diff --git a/test/cpp/src/TestServer.cpp b/test/cpp/src/TestServer.cpp
index 8d5b4d9..8fdab86 100644
--- a/test/cpp/src/TestServer.cpp
+++ b/test/cpp/src/TestServer.cpp
@@ -735,8 +735,8 @@
}
if (zlib) {
- // hmm.. doesn't seem to be a way to make it wrap the others...
- transportFactory = std::make_shared<TZlibTransportFactory>();
+ // currently TZlibTransportFactory is the only factory than can wrap another:
+ transportFactory = std::make_shared<TZlibTransportFactory>(transportFactory);
}
// Server Info
@@ -816,7 +816,7 @@
// if using header
server->setOutputProtocolFactory(std::shared_ptr<TProtocolFactory>());
}
-
+
apache::thrift::concurrency::ThreadFactory factory;
factory.setDetached(false);
std::shared_ptr<apache::thrift::concurrency::Runnable> serverThreadRunner(server);
@@ -829,7 +829,7 @@
thread->start();
gMonitor.waitForever(); // wait for a shutdown signal
-
+
#ifdef HAVE_SIGNAL_H
signal(SIGINT, SIG_DFL);
#endif
@@ -842,4 +842,3 @@
cout << "done." << endl;
return 0;
}
-