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.cpp b/lib/cpp/src/protocol/TBinaryProtocol.cpp
index 9fb2ec3..481012c 100644
--- a/lib/cpp/src/protocol/TBinaryProtocol.cpp
+++ b/lib/cpp/src/protocol/TBinaryProtocol.cpp
@@ -4,121 +4,109 @@
 
 namespace facebook { namespace thrift { namespace protocol { 
 
-uint32_t TBinaryProtocol::writeMessageBegin(shared_ptr<TTransport> out,
-					    const std::string name,
+uint32_t TBinaryProtocol::writeMessageBegin(const std::string name,
 					    const TMessageType messageType,
-					    const int32_t seqid) const {
+					    const int32_t seqid) {
   return 
-    writeString(out, name) + 
-    writeByte(out, (int8_t)messageType) +
-    writeI32(out, seqid);
+    writeString(name) + 
+    writeByte((int8_t)messageType) +
+    writeI32(seqid);
 }
 
-uint32_t TBinaryProtocol::writeMessageEnd(shared_ptr<TTransport> out) const {
+uint32_t TBinaryProtocol::writeMessageEnd() {
   return 0;
 }
 
-uint32_t TBinaryProtocol::writeStructBegin(shared_ptr<TTransport> out,
-                                           const string& name) const {
+uint32_t TBinaryProtocol::writeStructBegin(const string& name) {
   return 0;
 }
 
-uint32_t TBinaryProtocol::writeStructEnd(shared_ptr<TTransport> out) const {
+uint32_t TBinaryProtocol::writeStructEnd() {
   return 0;
 }
 
-uint32_t TBinaryProtocol::writeFieldBegin(shared_ptr<TTransport> out,
-                                          const string& name,
+uint32_t TBinaryProtocol::writeFieldBegin(const string& name,
                                           const TType fieldType,
-                                          const int16_t fieldId) const {
+                                          const int16_t fieldId) {
   return
-    writeByte(out, (int8_t)fieldType) +
-    writeI16(out, fieldId);
+    writeByte((int8_t)fieldType) +
+    writeI16(fieldId);
 }
 
-uint32_t TBinaryProtocol::writeFieldEnd(shared_ptr<TTransport> out) const {
+uint32_t TBinaryProtocol::writeFieldEnd() {
   return 0;
 }
 
-uint32_t TBinaryProtocol::writeFieldStop(shared_ptr<TTransport> out) const {
+uint32_t TBinaryProtocol::writeFieldStop() {
   return
-    writeByte(out, (int8_t)T_STOP);
+    writeByte((int8_t)T_STOP);
 }  
                                
-uint32_t TBinaryProtocol::writeMapBegin(shared_ptr<TTransport> out,
-                                        const TType keyType,
+uint32_t TBinaryProtocol::writeMapBegin(const TType keyType,
                                         const TType valType,
-                                        const uint32_t size) const {
+                                        const uint32_t size) {
   return
-    writeByte(out, (int8_t)keyType) +
-    writeByte(out, (int8_t)valType) +
-    writeI32(out, (int32_t)size);
+    writeByte((int8_t)keyType) +
+    writeByte((int8_t)valType) +
+    writeI32((int32_t)size);
 }
 
-uint32_t TBinaryProtocol::writeMapEnd(shared_ptr<TTransport> out) const {
+uint32_t TBinaryProtocol::writeMapEnd() {
   return 0;
 }
 
-uint32_t TBinaryProtocol::writeListBegin(shared_ptr<TTransport> out,
-                                         const TType elemType,
-                                         const uint32_t size) const {
+uint32_t TBinaryProtocol::writeListBegin(const TType elemType,
+                                         const uint32_t size) {
   return
-    writeByte(out, (int8_t) elemType) +
-    writeI32(out, (int32_t)size);
+    writeByte((int8_t) elemType) +
+    writeI32((int32_t)size);
 }
 
-uint32_t TBinaryProtocol::writeListEnd(shared_ptr<TTransport> out) const {
+uint32_t TBinaryProtocol::writeListEnd() {
   return 0;
 }
 
-uint32_t TBinaryProtocol::writeSetBegin(shared_ptr<TTransport> out,
-                                        const TType elemType,
-                                        const uint32_t size) const {
+uint32_t TBinaryProtocol::writeSetBegin(const TType elemType,
+                                        const uint32_t size) {
   return
-    writeByte(out, (int8_t)elemType) +
-    writeI32(out, (int32_t)size);
+    writeByte((int8_t)elemType) +
+    writeI32((int32_t)size);
 }
 
-uint32_t TBinaryProtocol::writeSetEnd(shared_ptr<TTransport> out) const {
+uint32_t TBinaryProtocol::writeSetEnd() {
   return 0;
 }
 
-uint32_t TBinaryProtocol::writeBool(shared_ptr<TTransport> out,
-                                    const bool value) const {
+uint32_t TBinaryProtocol::writeBool(const bool value) {
   uint8_t tmp =  value ? 1 : 0;
-  out->write(&tmp, 1);
+  outputTransport_->write(&tmp, 1);
   return 1;
 }
 
-uint32_t TBinaryProtocol::writeByte(shared_ptr<TTransport> out,
-                                    const int8_t byte) const {
-  out->write((uint8_t*)&byte, 1);
+uint32_t TBinaryProtocol::writeByte(const int8_t byte) {
+  outputTransport_->write((uint8_t*)&byte, 1);
   return 1;
 }
 
-uint32_t TBinaryProtocol::writeI16(shared_ptr<TTransport> out,
-                                   const int16_t i16) const {
+uint32_t TBinaryProtocol::writeI16(const int16_t i16) {
   int16_t net = (int16_t)htons(i16);
-  out->write((uint8_t*)&net, 2);
+  outputTransport_->write((uint8_t*)&net, 2);
   return 2;
 }
 
-uint32_t TBinaryProtocol::writeI32(shared_ptr<TTransport> out,
-                                   const int32_t i32) const {
+uint32_t TBinaryProtocol::writeI32(const int32_t i32) {
   int32_t net = (int32_t)htonl(i32);
-  out->write((uint8_t*)&net, 4);
+  outputTransport_->write((uint8_t*)&net, 4);
   return 4;
 }
 
-uint32_t TBinaryProtocol::writeI64(shared_ptr<TTransport> out,
-                                   const int64_t i64) const {
+uint32_t TBinaryProtocol::writeI64(const int64_t i64) {
   int64_t net = (int64_t)htonll(i64);
-  out->write((uint8_t*)&net, 8);
+  outputTransport_->write((uint8_t*)&net, 8);
   return 8;
 }
   
-uint32_t TBinaryProtocol::writeDouble(shared_ptr<TTransport> out,
-                                      const double dub) const {
+uint32_t TBinaryProtocol::writeDouble(const double dub) {
   uint8_t b[8];
   uint8_t* d = (uint8_t*)&dub;
   b[0] = d[7];
@@ -129,15 +117,14 @@
   b[5] = d[2];
   b[6] = d[1];
   b[7] = d[0];
-  out->write((uint8_t*)b, 8);
+  outputTransport_->write((uint8_t*)b, 8);
   return 8;
 }
 
   
-uint32_t TBinaryProtocol::writeString(shared_ptr<TTransport> out,
-                                      const string& str) const {
-  uint32_t result = writeI32(out, str.size());
-  out->write((uint8_t*)str.data(), str.size());
+uint32_t TBinaryProtocol::writeString(const string& str) {
+  uint32_t result = writeI32(str.size());
+  outputTransport_->write((uint8_t*)str.data(), str.size());
   return result + str.size();
 }
 
@@ -145,159 +132,147 @@
  * Reading functions
  */
 
-uint32_t TBinaryProtocol::readMessageBegin(shared_ptr<TTransport> in,
-					   std::string& name,
+uint32_t TBinaryProtocol::readMessageBegin(std::string& name,
 					   TMessageType& messageType,
-					   int32_t& seqid) const {
+					   int32_t& seqid) {
 
   uint32_t result = 0;
   int8_t type;
-  result+= readString(in, name);
-  result+=  readByte(in, type);
+  result+= readString(name);
+  result+=  readByte(type);
   messageType = (TMessageType)type;
-  result+= readI32(in, seqid);
+  result+= readI32(seqid);
   return result;
 }
 
-uint32_t TBinaryProtocol::readMessageEnd(shared_ptr<TTransport> in)  const{
+uint32_t TBinaryProtocol::readMessageEnd() {
   return 0;
 }
 
-uint32_t TBinaryProtocol::readStructBegin(shared_ptr<TTransport> in,
-                                          string& name) const {
+uint32_t TBinaryProtocol::readStructBegin(string& name) {
   name = "";
   return 0;
 }
 
-uint32_t TBinaryProtocol::readStructEnd(shared_ptr<TTransport> in) const {
+uint32_t TBinaryProtocol::readStructEnd() {
   return 0;
 }
 
-uint32_t TBinaryProtocol::readFieldBegin(shared_ptr<TTransport> in,
-                                         string& name,
+uint32_t TBinaryProtocol::readFieldBegin(string& name,
                                          TType& fieldType,
-                                         int16_t& fieldId) const {
+                                         int16_t& fieldId) {
   uint32_t result = 0;
   int8_t type;
-  result += readByte(in, type);
+  result += readByte(type);
   fieldType = (TType)type;
   if (fieldType == T_STOP) {
     fieldId = 0;
     return result;
   }
-  result += readI16(in, fieldId);
+  result += readI16(fieldId);
   return result;
 }
   
-uint32_t TBinaryProtocol::readFieldEnd(shared_ptr<TTransport> in) const {
+uint32_t TBinaryProtocol::readFieldEnd() {
   return 0;
 }
  
-uint32_t TBinaryProtocol::readMapBegin(shared_ptr<TTransport> in,
-                                       TType& keyType,
+uint32_t TBinaryProtocol::readMapBegin(TType& keyType,
                                        TType& valType,
-                                       uint32_t& size) const {
+                                       uint32_t& size) {
   int8_t k, v;
   uint32_t result = 0;
   int32_t sizei;
-  result += readByte(in, k);
+  result += readByte(k);
   keyType = (TType)k;
-  result += readByte(in, v);
+  result += readByte(v);
   valType = (TType)v;
-  result += readI32(in, sizei);
+  result += readI32(sizei);
   // TODO(mcslee): check for negative size
   size = (uint32_t)sizei;
   return result;
 }
 
-uint32_t TBinaryProtocol::readMapEnd(shared_ptr<TTransport> in) const {
+uint32_t TBinaryProtocol::readMapEnd() {
   return 0;
 }
 
-uint32_t TBinaryProtocol::readListBegin(shared_ptr<TTransport> in,
-                                        TType& elemType,
-                                        uint32_t& size) const {
+uint32_t TBinaryProtocol::readListBegin(TType& elemType,
+                                        uint32_t& size) {
   int8_t e;
   uint32_t result = 0;
   int32_t sizei;
-  result += readByte(in, e);
+  result += readByte(e);
   elemType = (TType)e;
-  result += readI32(in, sizei);
+  result += readI32(sizei);
   // TODO(mcslee): check for negative size
   size = (uint32_t)sizei;
   return result;
 }
 
-uint32_t TBinaryProtocol::readListEnd(shared_ptr<TTransport> in) const {
+uint32_t TBinaryProtocol::readListEnd() {
   return 0;
 }
 
-uint32_t TBinaryProtocol::readSetBegin(shared_ptr<TTransport> in,
-                                       TType& elemType,
-                                       uint32_t& size) const {
+uint32_t TBinaryProtocol::readSetBegin(TType& elemType,
+                                       uint32_t& size) {
   int8_t e;
   uint32_t result = 0;
   int32_t sizei;
-  result += readByte(in, e);
+  result += readByte(e);
   elemType = (TType)e;
-  result += readI32(in, sizei);
+  result += readI32(sizei);
   // TODO(mcslee): check for negative size
   size = (uint32_t)sizei;
   return result;
 }
 
-uint32_t TBinaryProtocol::readSetEnd(shared_ptr<TTransport> in) const {
+uint32_t TBinaryProtocol::readSetEnd() {
   return 0;
 }
 
-uint32_t TBinaryProtocol::readBool(shared_ptr<TTransport> in,
-                                   bool& value) const {
+uint32_t TBinaryProtocol::readBool(bool& value) {
   uint8_t b[1];
-  in->readAll(b, 1);
+  inputTransport_->readAll(b, 1);
   value = *(int8_t*)b != 0;
   return 1;
 }
 
-uint32_t TBinaryProtocol::readByte(shared_ptr<TTransport> in,
-                                   int8_t& byte) const {
+uint32_t TBinaryProtocol::readByte(int8_t& byte) {
   uint8_t b[1];
-  in->readAll(b, 1);
+  inputTransport_->readAll(b, 1);
   byte = *(int8_t*)b;
   return 1;
 }
 
-uint32_t TBinaryProtocol::readI16(shared_ptr<TTransport> in,
-                                  int16_t& i16) const {
+uint32_t TBinaryProtocol::readI16(int16_t& i16) {
   uint8_t b[2];
-  in->readAll(b, 2);
+  inputTransport_->readAll(b, 2);
   i16 = *(int16_t*)b;
   i16 = (int16_t)ntohs(i16);
   return 2;
 }
 
-uint32_t TBinaryProtocol::readI32(shared_ptr<TTransport> in,
-                                  int32_t& i32) const {
+uint32_t TBinaryProtocol::readI32(int32_t& i32) {
   uint8_t b[4];
-  in->readAll(b, 4);
+  inputTransport_->readAll(b, 4);
   i32 = *(int32_t*)b;
   i32 = (int32_t)ntohl(i32);
   return 4;
 }
 
-uint32_t TBinaryProtocol::readI64(shared_ptr<TTransport> in,
-                                  int64_t& i64) const {
+uint32_t TBinaryProtocol::readI64(int64_t& i64) {
   uint8_t b[8];
-  in->readAll(b, 8);
+  inputTransport_->readAll(b, 8);
   i64 = *(int64_t*)b;
   i64 = (int64_t)ntohll(i64);
   return 8;
 }
 
-uint32_t TBinaryProtocol::readDouble(shared_ptr<TTransport> in,
-                                     double& dub) const {
+uint32_t TBinaryProtocol::readDouble(double& dub) {
   uint8_t b[8];
   uint8_t d[8];
-  in->readAll(b, 8);
+  inputTransport_->readAll(b, 8);
   d[0] = b[7];
   d[1] = b[6];
   d[2] = b[5];
@@ -310,17 +285,16 @@
   return 8;
 }
 
-uint32_t TBinaryProtocol::readString(shared_ptr<TTransport> in,
-                                     string& str) const {
+uint32_t TBinaryProtocol::readString(string& str) {
   uint32_t result;
   int32_t size;
-  result = readI32(in, size);
+  result = readI32(size);
 
   // TODO(mcslee): check for negative size
 
   // Use the heap here to prevent stack overflow for v. large strings
   uint8_t *b = new uint8_t[size];
-  in->readAll(b, size);
+  inputTransport_->readAll(b, size);
   str = string((char*)b, size);
   delete [] b;