Rev 2 of Thrift, the Pillar successor

Summary: End-to-end communications and serialization in C++ is working

Reviewed By: aditya

Test Plan: See the new top-level test/ folder. It vaguely resembles a unit test, though it could be more automated.

Revert Plan: Revertible

Notes: Still a LOT of optimization work to be done on the generated C++ code, which should be using dynamic memory in a number of places. Next major task is writing the PHP/Java/Python generators.




git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664712 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/client/TClient.h b/lib/cpp/client/TClient.h
new file mode 100644
index 0000000..73dd093
--- /dev/null
+++ b/lib/cpp/client/TClient.h
@@ -0,0 +1,16 @@
+#ifndef T_CLIENT_H
+#define T_CLIENT_H
+
+#include "TDispatcher.h"
+
+class TClient : public TDispatcher {
+ public:
+  virtual ~TClient() {}
+  virtual bool open() = 0;
+  virtual void close() = 0;
+ protected:
+  TClient() {}
+};
+
+#endif
+
diff --git a/lib/cpp/client/TSimpleClient.cc b/lib/cpp/client/TSimpleClient.cc
new file mode 100644
index 0000000..9069c91
--- /dev/null
+++ b/lib/cpp/client/TSimpleClient.cc
@@ -0,0 +1,44 @@
+#include "TSimpleClient.h"
+using std::string;
+
+TSimpleClient::TSimpleClient(TTransport* transport) :
+  transport_(transport) {}
+
+bool TSimpleClient::open() {
+  return transport_->open();
+}
+
+void TSimpleClient::close() {
+  transport_->close();
+}
+
+std::string TSimpleClient::dispatch(const string& s) {
+  // Write size header
+  int32_t size = s.size();
+  // fprintf(stderr, "Writing size header %d to server\n", size);
+  transport_->write(string((char*)&size, 4));
+
+  // Write data payload
+  // fprintf(stderr, "Writing %d byte payload to server\n", (int)s.size());
+  transport_->write(s);
+
+  // Read response size
+  // fprintf(stderr, "Reading 4-byte response size header\n");
+  string response;
+  transport_->read(response, 4);
+  size = *(int32_t*)response.data();
+
+  // Read response data
+  if (size < 0) {
+    // TODO(mcslee): Handle exception
+    // fprintf(stderr, "Exception case! Response size < 0\n");
+    return "";
+  } else {
+    // fprintf(stderr, "Reading %d byte response payload\n", size);
+    transport_->read(response, size);
+    // TODO(mcslee): Check that we actually read enough data
+    // fprintf(stderr, "Done reading payload, returning.\n");
+    return response;
+  }
+}
+
diff --git a/lib/cpp/client/TSimpleClient.h b/lib/cpp/client/TSimpleClient.h
new file mode 100644
index 0000000..249afe5
--- /dev/null
+++ b/lib/cpp/client/TSimpleClient.h
@@ -0,0 +1,21 @@
+#ifndef T_SIMPLE_CLIENT_H
+#define T_SIMPLE_CLIENT_H
+
+#include "client/TClient.h"
+#include "transport/TTransport.h"
+
+class TSimpleClient : public TClient {
+ public:
+  TSimpleClient(TTransport* transport);
+  ~TSimpleClient() {}
+
+  bool open();
+  void close();
+  std::string dispatch(const std::string& in);
+
+ protected:
+  TTransport* transport_;
+};
+
+#endif
+