Thrift: Distinguish between string and binary types in C++ and Java.

Summary:
The upcoming TJSONProtocol handles string and binary types quite differently.
This change makes that distinction in all parts of the C++ binding.

Java already distinguished between string and binary, but this change
also updates the Java skip method to skip over strings as binary
so we don't get encoding errors when skipping binary data.

Reviewed By: mcslee

Test Plan: make check

Revert Plan: ok

Other Notes:
I just pulled this out of Chad Walters' JSON patch.
The only other change was adding readBinary (or was it writeBinary)
to TDenseProtocol.  Maybe inheriting from TBinaryProtocol wasn't a good idea.


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665481 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/protocol/TBinaryProtocol.cpp b/lib/cpp/src/protocol/TBinaryProtocol.cpp
index 289d614..929499b 100644
--- a/lib/cpp/src/protocol/TBinaryProtocol.cpp
+++ b/lib/cpp/src/protocol/TBinaryProtocol.cpp
@@ -188,6 +188,10 @@
   return result + size;
 }
 
+uint32_t TBinaryProtocol::writeBinary(const string& str) {
+  return TBinaryProtocol::writeString(str);
+}
+
 /**
  * Reading functions
  */
@@ -379,6 +383,10 @@
   return result + readStringBody(str, size);
 }
 
+uint32_t TBinaryProtocol::readBinary(string& str) {
+  return TBinaryProtocol::readString(str);
+}
+
 uint32_t TBinaryProtocol::readStringBody(string& str, int32_t size) {
   uint32_t result = 0;
 
diff --git a/lib/cpp/src/protocol/TBinaryProtocol.h b/lib/cpp/src/protocol/TBinaryProtocol.h
index c7e2791..9203865 100644
--- a/lib/cpp/src/protocol/TBinaryProtocol.h
+++ b/lib/cpp/src/protocol/TBinaryProtocol.h
@@ -119,9 +119,10 @@
 
   uint32_t writeDouble(const double dub);
 
-
   uint32_t writeString(const std::string& str);
 
+  uint32_t writeBinary(const std::string& str);
+
   /**
    * Reading functions
    */
@@ -173,6 +174,8 @@
 
   uint32_t readString(std::string& str);
 
+  uint32_t readBinary(std::string& str);
+
  protected:
   uint32_t readStringBody(std::string& str, int32_t sz);
 
diff --git a/lib/cpp/src/protocol/TDebugProtocol.cpp b/lib/cpp/src/protocol/TDebugProtocol.cpp
index 2f23b11..a24bb5b 100644
--- a/lib/cpp/src/protocol/TDebugProtocol.cpp
+++ b/lib/cpp/src/protocol/TDebugProtocol.cpp
@@ -312,4 +312,8 @@
   return writeItem(output);
 }
 
+uint32_t TDebugProtocol::writeBinary(const string& str) {
+  return TDebugProtocol::writeString(str);
+}
+
 }}} // facebook::thrift::protocol
diff --git a/lib/cpp/src/protocol/TDebugProtocol.h b/lib/cpp/src/protocol/TDebugProtocol.h
index 90b7688..196cff2 100644
--- a/lib/cpp/src/protocol/TDebugProtocol.h
+++ b/lib/cpp/src/protocol/TDebugProtocol.h
@@ -104,6 +104,8 @@
 
   uint32_t writeString(const std::string& str);
 
+  uint32_t writeBinary(const std::string& str);
+
 
  private:
   void indentUp();
diff --git a/lib/cpp/src/protocol/TDenseProtocol.cpp b/lib/cpp/src/protocol/TDenseProtocol.cpp
index 55f3902..dbb2d4a 100644
--- a/lib/cpp/src/protocol/TDenseProtocol.cpp
+++ b/lib/cpp/src/protocol/TDenseProtocol.cpp
@@ -439,6 +439,10 @@
   return subWriteString(str);
 }
 
+uint32_t TDenseProtocol::writeBinary(const std::string& str) {
+  return TDenseProtocol::writeString(str);
+}
+
 inline uint32_t TDenseProtocol::subWriteI32(const int32_t i32) {
   return vlqWrite(i32);
 }
@@ -718,6 +722,10 @@
   return subReadString(str);
 }
 
+uint32_t TDenseProtocol::readBinary(std::string& str) {
+  return TDenseProtocol::readString(str);
+}
+
 uint32_t TDenseProtocol::subReadI32(int32_t& i32) {
   uint64_t u64;
   uint32_t rv = vlqRead(u64);
diff --git a/lib/cpp/src/protocol/TDenseProtocol.h b/lib/cpp/src/protocol/TDenseProtocol.h
index dae2c18..713b57a 100644
--- a/lib/cpp/src/protocol/TDenseProtocol.h
+++ b/lib/cpp/src/protocol/TDenseProtocol.h
@@ -126,6 +126,8 @@
 
   virtual uint32_t writeString(const std::string& str);
 
+  virtual uint32_t writeBinary(const std::string& str);
+
 
   /*
    * Helper writing functions (don't do state transitions).
@@ -189,6 +191,7 @@
 
   uint32_t readString(std::string& str);
 
+  uint32_t readBinary(std::string& str);
 
   /*
    * Helper reading functions (don't do state transitions).
diff --git a/lib/cpp/src/protocol/TOneWayProtocol.h b/lib/cpp/src/protocol/TOneWayProtocol.h
index 245f830..1765413 100644
--- a/lib/cpp/src/protocol/TOneWayProtocol.h
+++ b/lib/cpp/src/protocol/TOneWayProtocol.h
@@ -137,6 +137,10 @@
         subclass_ + " does not support reading (yet).");
   }
 
+  uint32_t readBinary(std::string& str) {
+    throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
+        subclass_ + " does not support reading (yet).");
+  }
 
  private:
   std::string subclass_;
diff --git a/lib/cpp/src/protocol/TProtocol.h b/lib/cpp/src/protocol/TProtocol.h
index 85cc48a..aecc4e7 100644
--- a/lib/cpp/src/protocol/TProtocol.h
+++ b/lib/cpp/src/protocol/TProtocol.h
@@ -159,6 +159,8 @@
 
   virtual uint32_t writeString(const std::string& str) = 0;
 
+  virtual uint32_t writeBinary(const std::string& str) = 0;
+
   /**
    * Reading functions
    */
@@ -209,6 +211,8 @@
 
   virtual uint32_t readString(std::string& str) = 0;
 
+  virtual uint32_t readBinary(std::string& str) = 0;
+
   /**
    * Method to arbitrarily skip over data.
    */
@@ -247,7 +251,7 @@
     case T_STRING:
       {
         std::string str;
-        return readString(str);
+        return readBinary(str);
       }
     case T_STRUCT:
       {