Add explicit binary type to Thrift

Summary: Identical to string in all languages except Java. Java String is NOT binary-safe, so we need to use raw byte[] in that case. PHP/RUBY/Python strings are all binary safe, and C++ std::string works fine and manages memory for you so it's the safest route. Java just needs this tweak.

Reviewed By: aditya

Test Plan: Use "binary" as a type instead of String.


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665099 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/java/src/protocol/TBinaryProtocol.java b/lib/java/src/protocol/TBinaryProtocol.java
index 4ba0941..be02a3e 100644
--- a/lib/java/src/protocol/TBinaryProtocol.java
+++ b/lib/java/src/protocol/TBinaryProtocol.java
@@ -126,6 +126,11 @@
     trans_.write(dat, 0, dat.length);
   }
 
+  public void writeBinary(byte[] bin) throws TException {
+    writeI32(bin.length);
+    trans_.write(bin, 0, bin.length);
+  }
+
   /**
    * Reading methods.
    */
@@ -238,4 +243,12 @@
     trans_.readAll(buf, 0, size);
     return new String(buf);
   }
+
+  public byte[] readBinary() throws TException {
+    int size = readI32();
+    byte[] buf = new byte[size];
+    trans_.readAll(buf, 0, size);
+    return buf;
+  }
+
 }
diff --git a/lib/java/src/protocol/TProtocol.java b/lib/java/src/protocol/TProtocol.java
index 23829cf..08a7ef3 100644
--- a/lib/java/src/protocol/TProtocol.java
+++ b/lib/java/src/protocol/TProtocol.java
@@ -84,6 +84,8 @@
 
   public abstract void writeString(String str) throws TException;
 
+  public abstract void writeBinary(byte[] bin) throws TException;
+
   /**
    * Reading methods.
    */
@@ -126,4 +128,6 @@
 
   public abstract String readString() throws TException;
 
+  public abstract byte[] readBinary() throws TException;
+
 }