Update Thrift CPP libraries to work with new generated source, change underlying buffers to use uint8_t* instead of std::string
Summary: Major overhaul to the CPP libraries.
Reviewed By: aditya
Test Plan: Again, keep an eye out for the unit tests commit
Notes: Initial perf tests show that Thrift is not only more robust than Pillar, but its implementation is actually around 10-20% faster. We can do about 10 RPC function calls with small data payloads in under 2ms. THAT IS FAST. THAT IS THRIFTY.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664714 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/transport/TBufferedTransport.h b/lib/cpp/transport/TBufferedTransport.h
new file mode 100644
index 0000000..991b50c
--- /dev/null
+++ b/lib/cpp/transport/TBufferedTransport.h
@@ -0,0 +1,75 @@
+#ifndef T_BUFFERED_TRANSPORT_H
+#define T_BUFFERED_TRANSPORT_H
+
+#include "transport/TTransport.h"
+#include <string>
+
+/**
+ * Buffered transport. For reads it will read more data than is requested
+ * and will serve future data out of a local buffer. For writes, data is
+ * stored to an in memory buffer before being written out.
+ *
+ * @author Mark Slee <mcslee@facebook.com>
+ */
+class TBufferedTransport : public TTransport {
+ public:
+ TBufferedTransport(TTransport* transport) :
+ transport_(transport),
+ rBufSize_(512), rPos_(0), rLen_(0),
+ wBufSize_(512), wLen_(0) {
+ rBuf_ = new uint8_t[rBufSize_];
+ wBuf_ = new uint8_t[wBufSize_];
+ }
+
+ TBufferedTransport(TTransport* transport, uint32_t sz) :
+ transport_(transport),
+ rBufSize_(sz), rPos_(0), rLen_(0),
+ wBufSize_(sz), wLen_(0) {
+ rBuf_ = new uint8_t[rBufSize_];
+ wBuf_ = new uint8_t[wBufSize_];
+ }
+
+ TBufferedTransport(TTransport* transport, uint32_t rsz, uint32_t wsz) :
+ transport_(transport),
+ rBufSize_(rsz), rPos_(0), rLen_(0),
+ wBufSize_(wsz), wLen_(0) {
+ rBuf_ = new uint8_t[rBufSize_];
+ wBuf_ = new uint8_t[wBufSize_];
+ }
+
+ ~TBufferedTransport() {
+ delete [] rBuf_;
+ delete [] wBuf_;
+ }
+
+ bool isOpen() {
+ return transport_->isOpen();
+ }
+
+ void open() {
+ transport_->open();
+ }
+
+ void close() {
+ transport_->close();
+ }
+
+ uint32_t read(uint8_t* buf, uint32_t len);
+
+ void write(const uint8_t* buf, uint32_t len);
+
+ void flush();
+
+ protected:
+ TTransport* transport_;
+ uint8_t* rBuf_;
+ uint32_t rBufSize_;
+ uint32_t rPos_;
+ uint32_t rLen_;
+
+ uint8_t* wBuf_;
+ uint32_t wBufSize_;
+ uint32_t wLen_;
+};
+
+#endif