THRIFT-4136 Align is_binary() method with is_string() to simplify those checks
Client: Compiler (general)
Patch: Jens Geyer
This closes #1221
diff --git a/compiler/cpp/src/thrift/generate/t_as3_generator.cc b/compiler/cpp/src/thrift/generate/t_as3_generator.cc
index 5ae3f91..fc92de9 100644
--- a/compiler/cpp/src/thrift/generate/t_as3_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_as3_generator.cc
@@ -1251,7 +1251,7 @@
indent_up();
}
- if (field->get_type()->is_base_type() && ((t_base_type*)(field->get_type()))->is_binary()) {
+ if (field->get_type()->is_binary()) {
indent(out) << " ret += \"BINARY\";" << endl;
} else if (field->get_type()->is_enum()) {
indent(out) << "var " << field->get_name()
@@ -1984,7 +1984,7 @@
throw "compiler error: cannot serialize void field in a struct: " + name;
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "readBinary();";
} else {
out << "readString();";
@@ -2168,7 +2168,7 @@
throw "compiler error: cannot serialize void field in a struct: " + name;
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "writeBinary(" << name << ");";
} else {
out << "writeString(" << name << ");";
diff --git a/compiler/cpp/src/thrift/generate/t_c_glib_generator.cc b/compiler/cpp/src/thrift/generate/t_c_glib_generator.cc
index 7d4818e..a7beca7 100644
--- a/compiler/cpp/src/thrift/generate/t_c_glib_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_c_glib_generator.cc
@@ -3734,7 +3734,7 @@
out << "double (protocol, " << name;
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "binary (protocol, " << name << " ? ((GByteArray *) " << name << ")->data : NULL, "
<< name << " ? ((GByteArray *) " << name << ")->len : 0";
} else {
@@ -4010,7 +4010,7 @@
throw "compiler error: cannot serialize void field in a struct: " + name;
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "binary (protocol, &data, &len";
} else {
out << "string (protocol, &" << name;
@@ -4042,7 +4042,7 @@
<< endl;
// load the byte array with the data
- if (tbase == t_base_type::TYPE_STRING && ((t_base_type*)type)->is_binary()) {
+ if (tbase == t_base_type::TYPE_STRING && type->is_binary()) {
indent(out) << name << " = g_byte_array_new();" << endl;
indent(out) << "g_byte_array_append (" << name << ", (guint8 *) data, (guint) len);" << endl;
indent(out) << "g_free (data);" << endl;
diff --git a/compiler/cpp/src/thrift/generate/t_cocoa_generator.cc b/compiler/cpp/src/thrift/generate/t_cocoa_generator.cc
index eba94c0..c2f09e8 100644
--- a/compiler/cpp/src/thrift/generate/t_cocoa_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_cocoa_generator.cc
@@ -2174,7 +2174,7 @@
throw "compiler error: cannot serialize void field in a struct: " + tfield->get_name();
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "readBinary:&" << fieldName << " error: __thriftError]";
} else {
out << "readString:&" << fieldName << " error: __thriftError]";
@@ -2423,7 +2423,7 @@
throw "compiler error: cannot serialize void field in a struct: " + fieldName;
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "writeBinary: " << fieldName << " error: __thriftError]";
} else {
out << "writeString: " << fieldName << " error: __thriftError]";
@@ -2824,7 +2824,7 @@
case t_base_type::TYPE_STRING:
// We must handle binary constant but the syntax of IDL defines
// nothing about binary constant.
- // if ((t_base_type*)type)->is_binary())
+ // if type->is_binary())
// // binary code
render << "@\"" << get_escaped_string(value) << '"';
break;
diff --git a/compiler/cpp/src/thrift/generate/t_cpp_generator.cc b/compiler/cpp/src/thrift/generate/t_cpp_generator.cc
index e484afa..0518ec8 100644
--- a/compiler/cpp/src/thrift/generate/t_cpp_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_cpp_generator.cc
@@ -3734,7 +3734,7 @@
throw "compiler error: cannot serialize void field in a struct: " + name;
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "readBinary(" << name << ");";
} else {
out << "readString(" << name << ");";
@@ -3941,7 +3941,7 @@
throw "compiler error: cannot serialize void field in a struct: " + name;
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "writeBinary(" << name << ");";
} else {
out << "writeString(" << name << ");";
diff --git a/compiler/cpp/src/thrift/generate/t_csharp_generator.cc b/compiler/cpp/src/thrift/generate/t_csharp_generator.cc
index ae3c48b..57c3c5b 100644
--- a/compiler/cpp/src/thrift/generate/t_csharp_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_csharp_generator.cc
@@ -1350,7 +1350,7 @@
<< normalize_name((*f_iter)->get_name()) << ") || (";
}
t_type* ttype = (*f_iter)->get_type();
- if (ttype->is_container() || (ttype->is_base_type() && (((t_base_type*)ttype)->is_binary()))) {
+ if (ttype->is_container() || ttype->is_binary()) {
out << "TCollections.Equals(";
} else {
out << "System.Object.Equals(";
@@ -2468,7 +2468,7 @@
throw "compiler error: cannot serialize void field in a struct: " + name;
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "ReadBinary();";
} else {
out << "ReadString();";
@@ -2645,7 +2645,7 @@
throw "compiler error: cannot serialize void field in a struct: " + name;
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "WriteBinary(";
} else {
out << "WriteString(";
diff --git a/compiler/cpp/src/thrift/generate/t_d_generator.cc b/compiler/cpp/src/thrift/generate/t_d_generator.cc
index 8192549..b602e0d 100644
--- a/compiler/cpp/src/thrift/generate/t_d_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_d_generator.cc
@@ -381,8 +381,8 @@
out << indent() << "// Your implementation goes here." << endl << indent() << "writeln(\""
<< (*f_iter)->get_name() << " called\");" << endl;
- t_base_type* rt = (t_base_type*)(*f_iter)->get_returntype();
- if (!rt->is_void()) {
+ t_type* rt = (*f_iter)->get_returntype();
+ if (!rt->is_void()) {
indent(out) << "return typeof(return).init;" << endl;
}
diff --git a/compiler/cpp/src/thrift/generate/t_dart_generator.cc b/compiler/cpp/src/thrift/generate/t_dart_generator.cc
index 19bbb7b..f7bd1c2 100644
--- a/compiler/cpp/src/thrift/generate/t_dart_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_dart_generator.cc
@@ -1292,7 +1292,7 @@
scope_up(out);
}
- if (field->get_type()->is_base_type() && ((t_base_type*)(field->get_type()))->is_binary()) {
+ if (field->get_type()->is_binary()) {
indent(out) << "ret.write(\"BINARY\");" << endl;
} else if (field->get_type()->is_enum()) {
indent(out) << "String " << field_name << "_name = "
@@ -1809,7 +1809,7 @@
throw "compiler error: cannot serialize void field in a struct: " + name;
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "readBinary();";
} else {
out << "readString();";
@@ -1991,7 +1991,7 @@
throw "compiler error: cannot serialize void field in a struct: " + name;
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "writeBinary(" << name << ");";
} else {
out << "writeString(" << name << ");";
diff --git a/compiler/cpp/src/thrift/generate/t_delphi_generator.cc b/compiler/cpp/src/thrift/generate/t_delphi_generator.cc
index 8b1a445..d238566 100644
--- a/compiler/cpp/src/thrift/generate/t_delphi_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_delphi_generator.cc
@@ -2541,7 +2541,7 @@
throw "compiler error: cannot serialize void field in a struct: " + name;
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
if (ansistr_binary_) {
out << "ReadAnsiString();";
} else {
@@ -2742,7 +2742,7 @@
throw "compiler error: cannot serialize void field in a struct: " + name;
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
if (ansistr_binary_) {
out << "WriteAnsiString(";
} else {
@@ -3268,7 +3268,7 @@
case t_base_type::TYPE_VOID:
return "0";
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
if (ansistr_binary_) {
return "''";
} else {
diff --git a/compiler/cpp/src/thrift/generate/t_go_generator.cc b/compiler/cpp/src/thrift/generate/t_go_generator.cc
index 088f3ae..c7f5279 100644
--- a/compiler/cpp/src/thrift/generate/t_go_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_go_generator.cc
@@ -329,7 +329,7 @@
throw "";
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
//[]byte are always inline
return false;
}
@@ -357,7 +357,7 @@
static bool type_need_reference(t_type* type) {
type = type->get_true_type();
if (type->is_map() || type->is_set() || type->is_list() || type->is_struct()
- || type->is_xception() || (type->is_string() && ((t_base_type*)type)->is_binary())) {
+ || type->is_xception() || type->is_binary()) {
return false;
}
return true;
@@ -387,7 +387,7 @@
throw "";
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
//[]byte are always inline
return false;
}
@@ -1064,7 +1064,7 @@
switch (tbase) {
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "[]byte(\"" << get_escaped_string(value) << "\")";
} else {
out << '"' << get_escaped_string(value) << '"';
@@ -1405,7 +1405,7 @@
<< endl;
indent_up();
t_type* ttype = (*f_iter)->get_type()->get_true_type();
- bool is_byteslice = ttype->is_base_type() && ((t_base_type*)ttype)->is_binary();
+ bool is_byteslice = ttype->is_binary();
bool compare_to_nil_only = ttype->is_set() || ttype->is_list() || ttype->is_map()
|| (is_byteslice && !(*f_iter)->get_value());
if (is_pointer_field(*f_iter) || compare_to_nil_only) {
@@ -2336,7 +2336,7 @@
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)the_type2)->is_binary()) {
+ if (the_type2->is_binary()) {
f_remote << indent() << "argvalue" << i << " := []byte(flag.Arg(" << flagArg << "))"
<< endl;
} else {
@@ -2868,7 +2868,7 @@
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary() && !inkey) {
+ if (type->is_binary() && !inkey) {
out << "ReadBinary()";
} else {
out << "ReadString()";
@@ -3117,7 +3117,7 @@
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary() && !inkey) {
+ if (type->is_binary() && !inkey) {
out << "WriteBinary(" << name << ")";
} else {
out << "WriteString(string(" << name << "))";
@@ -3508,7 +3508,7 @@
case t_base_type::TYPE_STRING:
/* this is wrong, binary is still a string type internally
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
return "thrift.BINARY";
}
*/
@@ -3562,7 +3562,7 @@
throw "Cannot produce a valid type for a Go map key: " + type_to_go_type(type) + " - aborting.";
}
- if (resolved_type->is_string() && ((t_base_type*)resolved_type)->is_binary())
+ if (resolved_type->is_binary())
return "string";
return type_to_go_type(type);
@@ -3595,7 +3595,7 @@
throw "";
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
return maybe_pointer + "[]byte";
}
diff --git a/compiler/cpp/src/thrift/generate/t_gv_generator.cc b/compiler/cpp/src/thrift/generate/t_gv_generator.cc
index 72b7c82..14b5377 100644
--- a/compiler/cpp/src/thrift/generate/t_gv_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_gv_generator.cc
@@ -225,7 +225,7 @@
f_out_ << "\\>";
}
} else if (ttype->is_base_type()) {
- f_out_ << (((t_base_type*)ttype)->is_binary() ? "binary" : ttype->get_name());
+ f_out_ << (ttype->is_binary() ? "binary" : ttype->get_name());
} else {
f_out_ << ttype->get_name();
edges.push_back(struct_field_ref + " -> " + ttype->get_name());
diff --git a/compiler/cpp/src/thrift/generate/t_haxe_generator.cc b/compiler/cpp/src/thrift/generate/t_haxe_generator.cc
index e7be1a5..f5d292f 100644
--- a/compiler/cpp/src/thrift/generate/t_haxe_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_haxe_generator.cc
@@ -1304,7 +1304,7 @@
indent_up();
}
- if (field->get_type()->is_base_type() && ((t_base_type*)(field->get_type()))->is_binary()) {
+ if (field->get_type()->is_binary()) {
indent(out) << " ret += \"BINARY\";" << endl;
} else if (field->get_type()->is_enum()) {
indent(out) << "var " << field->get_name()
@@ -2200,7 +2200,7 @@
throw "compiler error: cannot serialize void field in a struct: " + name;
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "readBinary();";
} else {
out << "readString();";
@@ -2384,7 +2384,7 @@
throw "compiler error: cannot serialize void field in a struct: " + name;
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "writeBinary(" << name << ");";
} else {
out << "writeString(" << name << ");";
@@ -2553,7 +2553,7 @@
t_base_type::t_base tbase = ((t_base_type*)tkey)->get_base();
switch (tbase) {
case t_base_type::TYPE_STRING:
- if (!(((t_base_type*)tkey)->is_binary())) {
+ if (!(tkey->is_binary())) {
return "StringMap< " + type_name(tval) + ">";
}
case t_base_type::TYPE_I8:
@@ -2578,7 +2578,7 @@
t_base_type::t_base tbase = ((t_base_type*)tkey)->get_base();
switch (tbase) {
case t_base_type::TYPE_STRING:
- if (!(((t_base_type*)tkey)->is_binary())) {
+ if (!(tkey->is_binary())) {
return "StringSet";
}
case t_base_type::TYPE_I8:
diff --git a/compiler/cpp/src/thrift/generate/t_hs_generator.cc b/compiler/cpp/src/thrift/generate/t_hs_generator.cc
index a3ccd8d..29c0816 100644
--- a/compiler/cpp/src/thrift/generate/t_hs_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_hs_generator.cc
@@ -1369,11 +1369,11 @@
} else if (type->is_base_type()) {
t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
- if (tbase == t_base_type::TYPE_STRING && !((t_base_type*)type)->is_binary()) {
+ if (tbase == t_base_type::TYPE_STRING && !type->is_binary()) {
out << "E.decodeUtf8 ";
}
out << val;
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
// Since wire type of binary is the same as string, we actually receive T.TString not
// T.TBinary
out << "; T.TString " << val << " -> " << val;
@@ -1448,7 +1448,7 @@
if (type->is_base_type()) {
t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
out << type_to_constructor(type) << " ";
- if (tbase == t_base_type::TYPE_STRING && !((t_base_type*)type)->is_binary()) {
+ if (tbase == t_base_type::TYPE_STRING && !type->is_binary()) {
out << "$ E.encodeUtf8 ";
}
out << name;
@@ -1550,7 +1550,7 @@
case t_base_type::TYPE_VOID:
return "T.T_VOID";
case t_base_type::TYPE_STRING:
- return ((t_base_type*)type)->is_binary() ? "T.T_BINARY" : "T.T_STRING";
+ return type->is_binary() ? "T.T_BINARY" : "T.T_STRING";
case t_base_type::TYPE_BOOL:
return "T.T_BOOL";
case t_base_type::TYPE_I8:
@@ -1645,7 +1645,7 @@
case t_base_type::TYPE_VOID:
return "()";
case t_base_type::TYPE_STRING:
- return (((t_base_type*)type)->is_binary() ? "LBS.ByteString" : "LT.Text");
+ return (type->is_binary() ? "LBS.ByteString" : "LT.Text");
case t_base_type::TYPE_BOOL:
return "P.Bool";
case t_base_type::TYPE_I8:
@@ -1698,7 +1698,7 @@
case t_base_type::TYPE_VOID:
throw "invalid type: T_VOID";
case t_base_type::TYPE_STRING:
- return ((t_base_type*)type)->is_binary() ? "T.TBinary" : "T.TString";
+ return type->is_binary() ? "T.TBinary" : "T.TString";
case t_base_type::TYPE_BOOL:
return "T.TBool";
case t_base_type::TYPE_I8:
diff --git a/compiler/cpp/src/thrift/generate/t_html_generator.cc b/compiler/cpp/src/thrift/generate/t_html_generator.cc
index ec78e10..a7fa13c 100644
--- a/compiler/cpp/src/thrift/generate/t_html_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_html_generator.cc
@@ -691,7 +691,7 @@
f_out_ << ">";
}
} else if (ttype->is_base_type()) {
- f_out_ << (((t_base_type*)ttype)->is_binary() ? "binary" : ttype->get_name());
+ f_out_ << (ttype->is_binary() ? "binary" : ttype->get_name());
len = ttype->get_name().size();
} else {
string prog_name = ttype->get_program()->get_name();
diff --git a/compiler/cpp/src/thrift/generate/t_java_generator.cc b/compiler/cpp/src/thrift/generate/t_java_generator.cc
index 593eda6..db70dc5 100644
--- a/compiler/cpp/src/thrift/generate/t_java_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_java_generator.cc
@@ -874,7 +874,7 @@
indent(out) << " return x;" << endl;
indent(out) << "}" << endl << endl;
- if (type->is_base_type() && ((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
indent(out) << "public static " << type_name(tstruct) << " " << (*m_iter)->get_name()
<< "(byte[] value) {" << endl;
indent(out) << " " << type_name(tstruct) << " x = new " << type_name(tstruct) << "();"
@@ -905,7 +905,7 @@
bool is_deprecated = this->is_deprecated(field->annotations_);
generate_java_doc(out, field);
- if (type->is_base_type() && ((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
if (is_deprecated) {
indent(out) << "@Deprecated" << endl;
}
@@ -952,7 +952,7 @@
out << endl;
generate_java_doc(out, field);
- if (type->is_base_type() && ((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
if (is_deprecated) {
indent(out) << "@Deprecated" << endl;
}
@@ -1488,7 +1488,7 @@
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
if ((*m_iter)->get_req() != t_field::T_OPTIONAL) {
t_type* type = get_true_type((*m_iter)->get_type());
- if (type->is_base_type() && ((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
indent(out) << "this." << (*m_iter)->get_name()
<< " = org.apache.thrift.TBaseHelper.copyBinary(" << (*m_iter)->get_name()
<< ");" << endl;
@@ -1642,7 +1642,7 @@
} else if (t->is_map()) {
indent(out) << "out.writeMap(" << name << ");" << endl;
} else if (t->is_base_type()) {
- if (((t_base_type*)t)->is_binary()) {
+ if (t->is_binary()) {
indent(out) << "out.writeInt(" << name << "!=null ? 1 : 0);" << endl;
indent(out) << "if(" << name << " != null) { " << endl;
indent_up();
@@ -1853,7 +1853,7 @@
<< "this_present_" << name << " && that_present_" << name << "))" << endl << indent()
<< " return false;" << endl;
- if (t->is_base_type() && ((t_base_type*)t)->is_binary()) {
+ if (t->is_binary()) {
unequal = "!this." + name + ".equals(that." + name + ")";
} else if (can_be_null) {
unequal = "!this." + name + ".equals(that." + name + ")";
@@ -2094,7 +2094,7 @@
t_type* type,
string field_name,
string cap_name) {
- const bool is_binary = type->is_base_type() && ((t_base_type*)type)->is_binary();
+ const bool is_binary = type->is_binary();
indent(out) << "case " << constant_name(field_name) << ":" << endl;
indent_up();
indent(out) << "if (value == null) {" << endl;
@@ -2327,7 +2327,7 @@
// Simple getter
generate_java_doc(out, field);
- if (type->is_base_type() && ((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
if (is_deprecated) {
indent(out) << "@Deprecated" << endl;
}
@@ -2388,7 +2388,7 @@
// Simple setter
generate_java_doc(out, field);
- if (type->is_base_type() && ((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
if (is_deprecated) {
indent(out) << "@Deprecated" << endl;
}
@@ -2418,7 +2418,7 @@
out << " set" << cap_name << "(" << type_name(type) << " " << field_name << ") {" << endl;
indent_up();
indent(out) << "this." << field_name << " = ";
- if (type->is_base_type() && ((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "org.apache.thrift.TBaseHelper.copyBinary(" << field_name << ")";
} else {
out << field_name;
@@ -2526,20 +2526,15 @@
indent_up();
}
- if (get_true_type(field->get_type())->is_base_type()
- && ((t_base_type*)(get_true_type(field->get_type())))->is_binary()) {
+ if (get_true_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())
- && (get_true_type(((t_set*)field->get_type())->get_elem_type())->is_base_type())
- && (((t_base_type*)get_true_type(((t_set*)field->get_type())->get_elem_type()))
- ->is_binary())) {
+ && (get_true_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())
- && (get_true_type(((t_list*)field->get_type())->get_elem_type())->is_base_type())
- && (((t_base_type*)get_true_type(((t_list*)field->get_type())->get_elem_type()))
- ->is_binary())) {
+ && (get_true_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 {
@@ -2710,7 +2705,7 @@
<< get_java_type_string(type);
if (type->is_typedef()) {
indent(out) << ", \"" << ((t_typedef*)type)->get_symbolic() << "\"";
- } else if (((t_base_type*)type)->is_binary()) {
+ } else if (type->is_binary()) {
indent(out) << ", true";
}
}
@@ -3647,7 +3642,7 @@
throw "compiler error: cannot serialize void field in a struct: " + name;
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "readBinary();";
} else {
out << "readString();";
@@ -3932,7 +3927,7 @@
throw "compiler error: cannot serialize void field in a struct: " + name;
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "writeBinary(" << name << ");";
} else {
out << "writeString(" << name << ");";
@@ -4636,7 +4631,7 @@
indent(out) << result_name << ".add(" << result_element_name << ");" << endl;
} else {
// iterative copy
- if (((t_base_type*)elem_type)->is_binary()) {
+ if (elem_type->is_binary()) {
indent(out) << "java.nio.ByteBuffer temp_binary_element = ";
generate_deep_copy_non_container(out,
iterator_element_name,
@@ -4663,7 +4658,7 @@
t_type* type) {
(void)dest_name;
if (type->is_base_type() || type->is_enum() || type->is_typedef()) {
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "org.apache.thrift.TBaseHelper.copyBinary(" << source_name << ")";
} else {
// everything else can be copied directly
diff --git a/compiler/cpp/src/thrift/generate/t_javame_generator.cc b/compiler/cpp/src/thrift/generate/t_javame_generator.cc
index 94d66fc..24b7560 100644
--- a/compiler/cpp/src/thrift/generate/t_javame_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_javame_generator.cc
@@ -1222,7 +1222,7 @@
<< "this_present_" << name << " && that_present_" << name << "))" << endl << indent()
<< " return false;" << endl;
- if (t->is_base_type() && ((t_base_type*)t)->is_binary()) {
+ if (t->is_binary()) {
unequal = "TBaseHelper.compareTo(this." + name + ", that." + name + ") != 0";
} else if (can_be_null) {
unequal = "!this." + name + ".equals(that." + name + ")";
@@ -1740,7 +1740,7 @@
indent_up();
}
- if (field->get_type()->is_base_type() && ((t_base_type*)(field->get_type()))->is_binary()) {
+ if (field->get_type()->is_binary()) {
indent(out) << "TBaseHelper.toString(this." << field->get_name() << ", sb);" << endl;
} else {
indent(out) << "sb.append(this." << (*f_iter)->get_name() << ");" << endl;
@@ -2413,7 +2413,7 @@
throw "compiler error: cannot serialize void field in a struct: " + name;
break;
case t_base_type::TYPE_STRING:
- if (!((t_base_type*)type)->is_binary()) {
+ if (!type->is_binary()) {
out << "readString();";
} else {
out << "readBinary();";
@@ -2609,7 +2609,7 @@
throw "compiler error: cannot serialize void field in a struct: " + name;
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "writeBinary(" << name << ");";
} else {
out << "writeString(" << name << ");";
@@ -3144,7 +3144,7 @@
}
} else {
// iterative copy
- if (((t_base_type*)elem_type)->is_binary()) {
+ if (elem_type->is_binary()) {
indent(out) << type_name(elem_type, true, false) << " temp_binary_element = ";
generate_deep_copy_non_container(out,
iterator_element_name,
@@ -3175,7 +3175,7 @@
t_type* type) {
if (type->is_base_type() || type->is_enum() || type->is_typedef()) {
// binary fields need to be copied with System.arraycopy
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "new byte[" << source_name << ".length];" << endl;
indent(out) << "System.arraycopy(" << source_name << ", 0, " << dest_name << ", 0, "
<< source_name << ".length)";
diff --git a/compiler/cpp/src/thrift/generate/t_js_generator.cc b/compiler/cpp/src/thrift/generate/t_js_generator.cc
index 985ee0c..856f75c 100644
--- a/compiler/cpp/src/thrift/generate/t_js_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_js_generator.cc
@@ -1651,7 +1651,7 @@
throw "compiler error: cannot serialize void field in a struct: " + name;
break;
case t_base_type::TYPE_STRING:
- out << (((t_base_type*)type)->is_binary() ? "readBinary()" : "readString()");
+ out << (type->is_binary() ? "readBinary()" : "readString()");
break;
case t_base_type::TYPE_BOOL:
out << "readBool()";
@@ -1849,7 +1849,7 @@
throw "compiler error: cannot serialize void field in a struct: " + name;
break;
case t_base_type::TYPE_STRING:
- out << (((t_base_type*)type)->is_binary() ? "writeBinary(" : "writeString(") << name << ")";
+ out << (type->is_binary() ? "writeBinary(" : "writeString(") << name << ")";
break;
case t_base_type::TYPE_BOOL:
out << "writeBool(" << name << ")";
diff --git a/compiler/cpp/src/thrift/generate/t_netcore_generator.cc b/compiler/cpp/src/thrift/generate/t_netcore_generator.cc
index f4298c2..71e4236 100644
--- a/compiler/cpp/src/thrift/generate/t_netcore_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_netcore_generator.cc
@@ -1540,7 +1540,7 @@
<< normalize_name((*f_iter)->get_name()) << ") || (";
}
t_type* ttype = (*f_iter)->get_type();
- if (ttype->is_container() || (ttype->is_base_type() && (((t_base_type*)ttype)->is_binary())))
+ if (ttype->is_container() || ttype->is_binary())
{
out << "TCollections.Equals(";
}
@@ -2291,7 +2291,7 @@
throw "compiler error: cannot serialize void field in a struct: " + name;
break;
case t_base_type::TYPE_STRING:
- if (static_cast<t_base_type*>(type)->is_binary())
+ if (type->is_binary())
{
out << "ReadBinaryAsync(cancellationToken);";
}
@@ -2497,7 +2497,7 @@
case t_base_type::TYPE_VOID:
throw "compiler error: cannot serialize void field in a struct: " + name;
case t_base_type::TYPE_STRING:
- if (static_cast<t_base_type*>(type)->is_binary())
+ if (type->is_binary())
{
out << "WriteBinaryAsync(";
}
diff --git a/compiler/cpp/src/thrift/generate/t_py_generator.cc b/compiler/cpp/src/thrift/generate/t_py_generator.cc
index fa4b1e4..6b8697d 100644
--- a/compiler/cpp/src/thrift/generate/t_py_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_py_generator.cc
@@ -2071,7 +2071,7 @@
case t_base_type::TYPE_VOID:
throw "compiler error: cannot serialize void field in a struct: " + name;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "readBinary()";
} else if(!gen_utf8strings_) {
out << "readString()";
@@ -2259,7 +2259,7 @@
throw "compiler error: cannot serialize void field in a struct: " + name;
break;
case t_base_type::TYPE_STRING:
- if (((t_base_type*)type)->is_binary()) {
+ if (type->is_binary()) {
out << "writeBinary(" << name << ")";
} else if (!gen_utf8strings_) {
out << "writeString(" << name << ")";
@@ -2599,7 +2599,7 @@
ttype = ((t_typedef*)ttype)->get_type();
}
- if (ttype->is_base_type() && reinterpret_cast<t_base_type*>(ttype)->is_binary()) {
+ if (ttype->is_binary()) {
return "'BINARY'";
} else if (gen_utf8strings_ && ttype->is_base_type()
&& reinterpret_cast<t_base_type*>(ttype)->is_string()) {
diff --git a/compiler/cpp/src/thrift/parse/t_type.h b/compiler/cpp/src/thrift/parse/t_type.h
index 30f8c1f..3a6d1e0 100644
--- a/compiler/cpp/src/thrift/parse/t_type.h
+++ b/compiler/cpp/src/thrift/parse/t_type.h
@@ -47,6 +47,7 @@
virtual bool is_void() const { return false; }
virtual bool is_base_type() const { return false; }
virtual bool is_string() const { return false; }
+ virtual bool is_binary() const { return false; }
virtual bool is_bool() const { return false; }
virtual bool is_typedef() const { return false; }
virtual bool is_enum() const { return false; }