THRIFT-227 Pretty print binary collections
This closes #441
commit 5da68694fec6a51e97f5a75823babb1074e32eb2
Author: Roshan George <roshan@arjie.com>
Date: 2015-04-13T03:40:26Z
diff --git a/compiler/cpp/src/generate/t_java_generator.cc b/compiler/cpp/src/generate/t_java_generator.cc
index 9ca1567..3d8da1e 100644
--- a/compiler/cpp/src/generate/t_java_generator.cc
+++ b/compiler/cpp/src/generate/t_java_generator.cc
@@ -2423,6 +2423,16 @@
if (field->get_type()->is_base_type() && ((t_base_type*)(field->get_type()))->is_binary()) {
indent(out) << "org.apache.thrift.TBaseHelper.toString(this." << field->get_name() << ", sb);"
<< endl;
+ } else if ((field->get_type()->is_set()) &&
+ (((t_set*) field->get_type())->get_elem_type()->is_base_type()) &&
+ (((t_base_type*) ((t_set*) field->get_type())->get_elem_type())->is_binary())) {
+ indent(out) << "org.apache.thrift.TBaseHelper.toString(this." << field->get_name() << ", sb);"
+ << endl;
+ } else if ((field->get_type()->is_list()) &&
+ (((t_list*) field->get_type())->get_elem_type()->is_base_type()) &&
+ (((t_base_type*) ((t_list*) field->get_type())->get_elem_type())->is_binary())) {
+ indent(out) << "org.apache.thrift.TBaseHelper.toString(this." << field->get_name() << ", sb);"
+ << endl;
} else {
indent(out) << "sb.append(this." << (*f_iter)->get_name() << ");" << endl;
}
diff --git a/lib/java/src/org/apache/thrift/TBaseHelper.java b/lib/java/src/org/apache/thrift/TBaseHelper.java
index 4f02b06..5517536 100644
--- a/lib/java/src/org/apache/thrift/TBaseHelper.java
+++ b/lib/java/src/org/apache/thrift/TBaseHelper.java
@@ -28,6 +28,7 @@
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
+import java.util.Collection;
public final class TBaseHelper {
@@ -221,6 +222,25 @@
}
}
+ public static void toString(Collection<ByteBuffer> bbs, StringBuilder sb) {
+ Iterator<ByteBuffer> it = bbs.iterator();
+ if (!it.hasNext()) {
+ sb.append("[]");
+ } else {
+ sb.append("[");
+ while (true) {
+ ByteBuffer bb = it.next();
+ org.apache.thrift.TBaseHelper.toString(bb, sb);
+ if (!it.hasNext()) {
+ sb.append("]");
+ return;
+ } else {
+ sb.append(", ");
+ }
+ }
+ }
+ }
+
public static void toString(ByteBuffer bb, StringBuilder sb) {
byte[] buf = bb.array();