Thrift library updates, remove unsigned types


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664772 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/Thrift.h b/lib/cpp/src/Thrift.h
index 1f98d82..9254b56 100644
--- a/lib/cpp/src/Thrift.h
+++ b/lib/cpp/src/Thrift.h
@@ -9,7 +9,7 @@
 #include <set>
 #include <exception>
 
-namespace facebook {namespace thrift {
+namespace facebook { namespace thrift {
 
 class Exception : public std::exception {
 private:
diff --git a/lib/cpp/src/protocol/TBinaryProtocol.cc b/lib/cpp/src/protocol/TBinaryProtocol.cc
index f2fbe87..51c9306 100644
--- a/lib/cpp/src/protocol/TBinaryProtocol.cc
+++ b/lib/cpp/src/protocol/TBinaryProtocol.cc
@@ -7,11 +7,11 @@
 uint32_t TBinaryProtocol::writeMessageBegin(shared_ptr<TTransport> out,
 					    const std::string name,
 					    const TMessageType messageType,
-					    const uint32_t seqid) const {
+					    const int32_t seqid) const {
   return 
     writeString(out, name) + 
-    writeByte(out, (uint8_t)messageType) +
-    writeU32(out, seqid);
+    writeByte(out, (int8_t)messageType) +
+    writeI32(out, seqid);
 }
 
 uint32_t TBinaryProtocol::writeMessageEnd(shared_ptr<TTransport> out) const {
@@ -32,7 +32,7 @@
                                           const TType fieldType,
                                           const int16_t fieldId) const {
   return
-    writeByte(out, (uint8_t)fieldType) +
+    writeByte(out, (int8_t)fieldType) +
     writeI16(out, fieldId);
 }
 
@@ -42,7 +42,7 @@
 
 uint32_t TBinaryProtocol::writeFieldStop(shared_ptr<TTransport> out) const {
   return
-    writeByte(out, (uint8_t)T_STOP);
+    writeByte(out, (int8_t)T_STOP);
 }  
                                
 uint32_t TBinaryProtocol::writeMapBegin(shared_ptr<TTransport> out,
@@ -50,9 +50,9 @@
                                         const TType valType,
                                         const uint32_t size) const {
   return
-    writeByte(out, (uint8_t)keyType) +
-    writeByte(out, (uint8_t)valType) +
-    writeU32(out, (uint32_t)size);
+    writeByte(out, (int8_t)keyType) +
+    writeByte(out, (int8_t)valType) +
+    writeI32(out, (int32_t)size);
 }
 
 uint32_t TBinaryProtocol::writeMapEnd(shared_ptr<TTransport> out) const {
@@ -63,8 +63,8 @@
                                          const TType elemType,
                                          const uint32_t size) const {
   return
-    writeByte(out, (uint8_t) elemType) +
-    writeU32(out, (int32_t)size);
+    writeByte(out, (int8_t) elemType) +
+    writeI32(out, (int32_t)size);
 }
 
 uint32_t TBinaryProtocol::writeListEnd(shared_ptr<TTransport> out) const {
@@ -75,8 +75,8 @@
                                         const TType elemType,
                                         const uint32_t size) const {
   return
-    writeByte(out, (uint8_t)elemType) +
-    writeU32(out, (int32_t)size);
+    writeByte(out, (int8_t)elemType) +
+    writeI32(out, (int32_t)size);
 }
 
 uint32_t TBinaryProtocol::writeSetEnd(shared_ptr<TTransport> out) const {
@@ -91,18 +91,11 @@
 }
 
 uint32_t TBinaryProtocol::writeByte(shared_ptr<TTransport> out,
-                                    const uint8_t byte) const {
-  out->write(&byte, 1);
+                                    const int8_t byte) const {
+  out->write((uint8_t*)&byte, 1);
   return 1;
 }
 
-uint32_t TBinaryProtocol::writeU16(shared_ptr<TTransport> out,
-                                   const uint16_t u16) const {
-  uint16_t net = (uint16_t)htons(u16);
-  out->write((uint8_t*)&net, 2);
-  return 2;
-}
-
 uint32_t TBinaryProtocol::writeI16(shared_ptr<TTransport> out,
                                    const int16_t i16) const {
   int16_t net = (int16_t)htons(i16);
@@ -110,13 +103,6 @@
   return 2;
 }
 
-uint32_t TBinaryProtocol::writeU32(shared_ptr<TTransport> out,
-                                   const uint32_t u32) const {
-  uint32_t net = (uint32_t)htonl(u32);
-  out->write((uint8_t*)&net, 4);
-  return 4;
-}
-
 uint32_t TBinaryProtocol::writeI32(shared_ptr<TTransport> out,
                                    const int32_t i32) const {
   int32_t net = (int32_t)htonl(i32);
@@ -124,13 +110,6 @@
   return 4;
 }
 
-uint32_t TBinaryProtocol::writeU64(shared_ptr<TTransport> out,
-                                   const uint64_t u64) const {
-  uint64_t net = (uint64_t)htonll(u64);
-  out->write((uint8_t*)&net, 8);
-  return 8;
-}
-
 uint32_t TBinaryProtocol::writeI64(shared_ptr<TTransport> out,
                                    const int64_t i64) const {
   int64_t net = (int64_t)htonll(i64);
@@ -152,14 +131,14 @@
 uint32_t TBinaryProtocol::readMessageBegin(shared_ptr<TTransport> in,
 					   std::string& name,
 					   TMessageType& messageType,
-					   uint32_t& seqid) const {
+					   int32_t& seqid) const {
 
   uint32_t result = 0;
-  uint8_t type;
+  int8_t type;
   result+= readString(in, name);
   result+=  readByte(in, type);
   messageType = (TMessageType)type;
-  result+= readU32(in, seqid);
+  result+= readI32(in, seqid);
   return result;
 }
 
@@ -182,7 +161,7 @@
                                          TType& fieldType,
                                          int16_t& fieldId) const {
   uint32_t result = 0;
-  uint8_t type;
+  int8_t type;
   result += readByte(in, type);
   fieldType = (TType)type;
   if (fieldType == T_STOP) {
@@ -201,13 +180,16 @@
                                        TType& keyType,
                                        TType& valType,
                                        uint32_t& size) const {
-  uint8_t k, v;
+  int8_t k, v;
   uint32_t result = 0;
+  int32_t sizei;
   result += readByte(in, k);
   keyType = (TType)k;
   result += readByte(in, v);
   valType = (TType)v;
-  result += readU32(in, size);
+  result += readI32(in, sizei);
+  // TODO(mcslee): check for negative size
+  size = (uint32_t)sizei;
   return result;
 }
 
@@ -218,11 +200,14 @@
 uint32_t TBinaryProtocol::readListBegin(shared_ptr<TTransport> in,
                                         TType& elemType,
                                         uint32_t& size) const {
-  uint8_t e;
+  int8_t e;
   uint32_t result = 0;
+  int32_t sizei;
   result += readByte(in, e);
   elemType = (TType)e;
-  result += readU32(in, size);
+  result += readI32(in, sizei);
+  // TODO(mcslee): check for negative size
+  size = (uint32_t)sizei;
   return result;
 }
 
@@ -233,11 +218,14 @@
 uint32_t TBinaryProtocol::readSetBegin(shared_ptr<TTransport> in,
                                        TType& elemType,
                                        uint32_t& size) const {
-  uint8_t e;
+  int8_t e;
   uint32_t result = 0;
+  int32_t sizei;
   result += readByte(in, e);
   elemType = (TType)e;
-  result += readU32(in, size);
+  result += readI32(in, sizei);
+  // TODO(mcslee): check for negative size
+  size = (uint32_t)sizei;
   return result;
 }
 
@@ -249,27 +237,18 @@
                                    bool& value) const {
   uint8_t b[1];
   in->readAll(b, 1);
-  value = *(uint8_t*)b != 0;
+  value = *(int8_t*)b != 0;
   return 1;
 }
 
 uint32_t TBinaryProtocol::readByte(shared_ptr<TTransport> in,
-                                   uint8_t& byte) const {
+                                   int8_t& byte) const {
   uint8_t b[1];
   in->readAll(b, 1);
-  byte = *(uint8_t*)b;
+  byte = *(int8_t*)b;
   return 1;
 }
 
-uint32_t TBinaryProtocol::readU16(shared_ptr<TTransport> in,
-                                  uint16_t& u16) const {
-  uint8_t b[2];
-  in->readAll(b, 2);
-  u16 = *(uint16_t*)b;
-  u16 = (uint16_t)ntohs(u16);
-  return 2;
-}
-
 uint32_t TBinaryProtocol::readI16(shared_ptr<TTransport> in,
                                   int16_t& i16) const {
   uint8_t b[2];
@@ -279,15 +258,6 @@
   return 2;
 }
 
-uint32_t TBinaryProtocol::readU32(shared_ptr<TTransport> in,
-                                  uint32_t& u32) const {
-  uint8_t b[4];
-  in->readAll(b, 4);
-  u32 = *(uint32_t*)b;
-  u32 = (uint32_t)ntohl(u32);
-  return 4;
-}
-
 uint32_t TBinaryProtocol::readI32(shared_ptr<TTransport> in,
                                   int32_t& i32) const {
   uint8_t b[4];
@@ -297,15 +267,6 @@
   return 4;
 }
 
-uint32_t TBinaryProtocol::readU64(shared_ptr<TTransport> in,
-                                  uint64_t& u64) const {
-  uint8_t b[8];
-  in->readAll(b, 8);
-  u64 = *(uint64_t*)b;
-  u64 = (uint64_t)ntohll(u64);
-  return 8;
-}
-
 uint32_t TBinaryProtocol::readI64(shared_ptr<TTransport> in,
                                   int64_t& i64) const {
   uint8_t b[8];
@@ -318,8 +279,10 @@
 uint32_t TBinaryProtocol::readString(shared_ptr<TTransport> in,
                                      string& str) const {
   uint32_t result;
-  uint32_t size;
-  result = readU32(in, size);
+  int32_t size;
+  result = readI32(in, 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];
@@ -329,4 +292,5 @@
 
   return result + (uint32_t)size;
 }
+
 }}} // facebook::thrift::protocol
diff --git a/lib/cpp/src/protocol/TBinaryProtocol.h b/lib/cpp/src/protocol/TBinaryProtocol.h
index 7780f16..d66fa2f 100644
--- a/lib/cpp/src/protocol/TBinaryProtocol.h
+++ b/lib/cpp/src/protocol/TBinaryProtocol.h
@@ -27,7 +27,7 @@
   virtual uint32_t writeMessageBegin(shared_ptr<TTransport> out,
 				     const std::string name,
 				     const TMessageType messageType,
-				     const uint32_t seqid) const;
+				     const int32_t seqid) const;
 
   virtual uint32_t writeMessageEnd(shared_ptr<TTransport> out) const;
 
@@ -69,23 +69,14 @@
 		      const bool value) const;
 
   uint32_t writeByte(shared_ptr<TTransport> out,
-		      const uint8_t byte) const;
-
-  uint32_t writeU16(shared_ptr<TTransport> out,
-		    const uint16_t u16) const;
+		      const int8_t byte) const;
 
   uint32_t writeI16(shared_ptr<TTransport> out,
 		     const int16_t i16) const;
 
-  uint32_t writeU32(shared_ptr<TTransport> out,
-		     const uint32_t u32) const;
-
   uint32_t writeI32(shared_ptr<TTransport> out,
 		     const int32_t i32) const;
 
-  uint32_t writeU64(shared_ptr<TTransport> out,
-		     const uint64_t u64) const;
-
   uint32_t writeI64(shared_ptr<TTransport> out,
 		     const int64_t i64) const;
 
@@ -100,7 +91,7 @@
   uint32_t readMessageBegin(shared_ptr<TTransport> in,
 			    std::string& name,
 			    TMessageType& messageType,
-			    uint32_t& seqid) const;
+			    int32_t& seqid) const;
 
   uint32_t readMessageEnd(shared_ptr<TTransport> in) const;
 
@@ -139,23 +130,14 @@
 		      bool& value) const;
 
   uint32_t readByte(shared_ptr<TTransport> in,
-		     uint8_t& byte) const;
-
-  uint32_t readU16(shared_ptr<TTransport> in,
-		    uint16_t& u16) const;
+                    int8_t& byte) const;
 
   uint32_t readI16(shared_ptr<TTransport> in,
 		    int16_t& i16) const;
 
-  uint32_t readU32(shared_ptr<TTransport> in,
-		    uint32_t& u32) const;
-
   uint32_t readI32(shared_ptr<TTransport> in,
 		    int32_t& i32) const;
 
-  uint32_t readU64(shared_ptr<TTransport> in,
-		    uint64_t& u64) const;
-
   uint32_t readI64(shared_ptr<TTransport> in,
 		    int64_t& i64) const;
 
diff --git a/lib/cpp/src/protocol/TProtocol.h b/lib/cpp/src/protocol/TProtocol.h
index 092dd8d..2b3666f 100644
--- a/lib/cpp/src/protocol/TProtocol.h
+++ b/lib/cpp/src/protocol/TProtocol.h
@@ -33,11 +33,8 @@
   T_VOID       = 1,
   T_BOOL       = 2,
   T_BYTE       = 3,
-  T_U08        = 3,
-  T_I08        = 4,
-  T_U16        = 5,
+  T_I08        = 3,
   T_I16        = 6,
-  T_U32        = 7,
   T_I32        = 8,
   T_U64        = 9,
   T_I64        = 10,
@@ -82,7 +79,7 @@
   virtual uint32_t writeMessageBegin(shared_ptr<TTransport> out,
 				     const std::string name,
 				     const TMessageType messageType,
-				     const uint32_t seqid) const = 0;
+				     const int32_t seqid) const = 0;
 
   virtual uint32_t writeMessageEnd(shared_ptr<TTransport> out) const = 0;
 
@@ -124,23 +121,14 @@
 			     const bool value) const = 0;
 
   virtual uint32_t writeByte(shared_ptr<TTransport> out,
-			     const uint8_t byte) const = 0;
+			     const int8_t byte) const = 0;
 
   virtual uint32_t writeI16(shared_ptr<TTransport> out,
 			    const int16_t i16) const = 0;
 
-  virtual uint32_t writeU16(shared_ptr<TTransport> out,
-			    const uint16_t u16) const = 0;
-
-  virtual uint32_t writeU32(shared_ptr<TTransport> out,
-			    const uint32_t u32) const = 0;
-  
   virtual uint32_t writeI32(shared_ptr<TTransport> out,
 			    const int32_t i32) const = 0;
 
-  virtual uint32_t writeU64(shared_ptr<TTransport> out,
-			    const uint64_t u64) const = 0;
-
   virtual uint32_t writeI64(shared_ptr<TTransport> out,
 			    const int64_t i64) const = 0;
 
@@ -154,7 +142,7 @@
   virtual uint32_t readMessageBegin(shared_ptr<TTransport> in,
 				    std::string& name,
 				    TMessageType& messageType,
-				    uint32_t& seqid) const = 0;
+				    int32_t& seqid) const = 0;
   
   virtual uint32_t readMessageEnd(shared_ptr<TTransport> in) const = 0;
 
@@ -193,23 +181,14 @@
 			    bool& value) const = 0;
 
   virtual uint32_t readByte(shared_ptr<TTransport> in,
-			    uint8_t& byte) const = 0;
-
-  virtual uint32_t readU16(shared_ptr<TTransport> in,
-			   uint16_t& u16) const = 0;
+			    int8_t& byte) const = 0;
 
   virtual uint32_t readI16(shared_ptr<TTransport> in,
 			   int16_t& i16) const = 0;
 
-  virtual uint32_t readU32(shared_ptr<TTransport> in,
-			   uint32_t& u32) const = 0;
-
   virtual uint32_t readI32(shared_ptr<TTransport> in,
 			   int32_t& i32) const = 0;
 
-  virtual uint32_t readU64(shared_ptr<TTransport> in,
-			   uint64_t& u64) const = 0;
-
   virtual uint32_t readI64(shared_ptr<TTransport> in,
 			   int64_t& i64) const = 0;
 
@@ -223,24 +202,19 @@
     switch (type) {
     case T_BYTE:
       {
-        uint8_t byte;
+        int8_t byte;
         return readByte(in, byte);
       }
-    case T_U32:
+    case T_I16:
       {
-        uint32_t u32;
-        return readU32(in, u32);
+        int16_t i16;
+        return readI16(in, i16);
       }
     case T_I32:
       {
         int32_t i32;
         return readI32(in, i32);
       }
-    case T_U64:
-      {
-        uint64_t u64;
-        return readU64(in, u64);
-      }
     case T_I64:
       {
         int64_t i64;