mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-06 10:25:18 +00:00
THRIFT-227 Pretty print binary collections
This closes #441 commit 5da68694fec6a51e97f5a75823babb1074e32eb2 Author: Roshan George <roshan@arjie.com> Date: 2015-04-13T03:40:26Z
This commit is contained in:
parent
8f27189dfd
commit
a242c28ba1
@ -2423,6 +2423,16 @@ void t_java_generator::generate_java_struct_tostring(ofstream& out, t_struct* ts
|
||||
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;
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import java.util.SortedMap;
|
||||
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 final class TBaseHelper {
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user