name;
break;
case t_base_type::TYPE_STRING:
- out << "readString();";
+ if (((t_base_type*)type)->is_binary()) {
+ out << "readBinary();";
+ } else {
+ out << "readString();";
+ }
break;
case t_base_type::TYPE_BOOL:
out << "readBool();";
"compiler error: cannot serialize void field in a struct: " + name;
break;
case t_base_type::TYPE_STRING:
- out << "writeString(" << name << ");";
+ if (((t_base_type*)type)->is_binary()) {
+ out << "writeBinary(" << name << ");";
+ } else {
+ out << "writeString(" << name << ");";
+ }
break;
case t_base_type::TYPE_BOOL:
out << "writeBool(" << name << ");";
}
if (ttype->is_base_type()) {
- return base_type_name(((t_base_type*)ttype)->get_base(), in_container);
+ return base_type_name((t_base_type*)ttype, in_container);
} else if (ttype->is_enum()) {
return (in_container ? "Integer" : "int");
} else if (ttype->is_map()) {
* @param tbase The base type
* @param container Is it going in a Java container?
*/
-string t_java_generator::base_type_name(t_base_type::t_base tbase,
+string t_java_generator::base_type_name(t_base_type* type,
bool in_container) {
+ t_base_type::t_base tbase = type->get_base();
+
switch (tbase) {
case t_base_type::TYPE_VOID:
return "void";
case t_base_type::TYPE_STRING:
- return "String";
+ if (type->is_binary()) {
+ return "byte[]";
+ } else {
+ return "String";
+ }
case t_base_type::TYPE_BOOL:
return "boolean";
case t_base_type::TYPE_BYTE:
std::string java_type_imports();
std::string java_thrift_imports();
std::string type_name(t_type* ttype, bool in_container=false, bool in_init=false);
- std::string base_type_name(t_base_type::t_base tbase, bool in_container=false);
+ std::string base_type_name(t_base_type* tbase, bool in_container=false);
std::string declare_field(t_field* tfield, bool init=false);
std::string function_signature(t_function* tfunction, std::string prefix="");
std::string argument_list(t_struct* tstruct);
extern t_type* g_type_void;
extern t_type* g_type_string;
+extern t_type* g_type_binary;
extern t_type* g_type_slist;
extern t_type* g_type_bool;
extern t_type* g_type_byte;
t_type* g_type_void;
t_type* g_type_string;
+t_type* g_type_binary;
t_type* g_type_slist;
t_type* g_type_bool;
t_type* g_type_byte;
// Initialize global types
g_type_void = new t_base_type("void", t_base_type::TYPE_VOID);
g_type_string = new t_base_type("string", t_base_type::TYPE_STRING);
+ g_type_binary = new t_base_type("string", t_base_type::TYPE_STRING);
+ ((t_base_type*)g_type_binary)->set_binary(true);
g_type_slist = new t_base_type("string", t_base_type::TYPE_STRING);
((t_base_type*)g_type_slist)->set_string_list(true);
g_type_bool = new t_base_type("bool", t_base_type::TYPE_BOOL);
}
bool is_string_list() const {
- return base_ == TYPE_STRING && string_list_;
+ return (base_ == TYPE_STRING) && string_list_;
+ }
+
+ void set_binary(bool val) {
+ binary_ = val;
+ }
+
+ bool is_binary() const {
+ return (base_ == TYPE_STRING) && binary_;
}
void set_string_enum(bool val) {
t_base base_;
bool string_list_;
+ bool binary_;
bool string_enum_;
std::vector<std::string> string_enum_vals_;
};
"i64" { return tok_i64; }
"double" { return tok_double; }
"string" { return tok_string; }
+"binary" { return tok_binary; }
"slist" { return tok_slist; }
"senum" { return tok_senum; }
"map" { return tok_map; }
%token tok_bool
%token tok_byte
%token tok_string
+%token tok_binary
%token tok_slist
%token tok_senum
%token tok_i16
pdebug("BaseType -> tok_string");
$$ = g_type_string;
}
+| tok_binary
+ {
+ pdebug("BaseType -> tok_binary");
+ $$ = g_type_binary;
+ }
| tok_slist
{
pdebug("BaseType -> tok_slist");
trans_.write(dat, 0, dat.length);
}
+ public void writeBinary(byte[] bin) throws TException {
+ writeI32(bin.length);
+ trans_.write(bin, 0, bin.length);
+ }
+
/**
* Reading methods.
*/
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;
+ }
+
}
public abstract void writeString(String str) throws TException;
+ public abstract void writeBinary(byte[] bin) throws TException;
+
/**
* Reading methods.
*/
public abstract String readString() throws TException;
+ public abstract byte[] readBinary() throws TException;
+
}