bool format_go_output(const string &file_path);
const string default_thrift_import = "git.apache.org/thrift.git/lib/go/thrift";
+static std::string package_flag;
/**
* Go code generator.
if (iter != parsed_options.end()) {
gen_thrift_import_ = (iter->second);
}
+
+ iter = parsed_options.find("package");
+
+ if (iter != parsed_options.end()) {
+ package_flag = (iter->second);
+ }
}
/**
void generate_go_struct(t_struct* tstruct, bool is_exception);
void generate_go_struct_definition(std::ofstream& out, t_struct* tstruct, bool is_xception = false, bool is_result = false, bool is_args = false);
+ void generate_go_struct_initializer(std::ofstream& out, t_struct* tstruct, bool is_args_or_result = false);
void generate_isset_helpers(std::ofstream& out, t_struct* tstruct, const string& tstruct_name, bool is_result = false);
void generate_go_struct_reader(std::ofstream& out, t_struct* tstruct, const string& tstruct_name, bool is_result = false);
void generate_go_struct_writer(std::ofstream& out, t_struct* tstruct, const string& tstruct_name, bool is_result = false);
std::string prefix = "",
bool inclass = false,
bool coerceData = false,
- bool inkey = false);
+ bool inkey = false,
+ bool in_container = false);
void generate_deserialize_struct(std::ofstream &out,
t_struct* tstruct,
+ bool is_pointer_field,
bool declare,
std::string prefix = "");
void generate_deserialize_container(std::ofstream &out,
t_type* ttype,
- bool optional_field,
+ bool pointer_field,
bool declare,
std::string prefix = "");
void generate_serialize_container(std::ofstream &out,
t_type* ttype,
- bool optional_field,
+ bool pointer_field,
std::string prefix = "");
void generate_serialize_map_element(std::ofstream &out,
std::string function_signature_if(t_function* tfunction, std::string prefix = "", bool addError = false);
std::string argument_list(t_struct* tstruct);
std::string type_to_enum(t_type* ttype);
- std::string type_to_go_type(t_type* ttype);
- std::string type_to_go_type_with_opt(t_type* ttype, bool optional_field);
+ std::string type_to_go_type(t_type* ttype, bool is_container_value = false);
+ std::string type_to_go_type_with_opt(t_type* ttype, bool optional_field, bool is_container_value = false);
std::string type_to_go_key_type(t_type* ttype);
std::string type_to_spec_args(t_type* ttype);
static std::string get_real_go_module(const t_program* program) {
+
+ if (!package_flag.empty()) {
+ return package_flag;
+ }
std::string real_module = program->get_namespace("go");
if (real_module.empty()) {
static std::string new_prefix(const std::string& value);
static std::string privatize(const std::string& value);
static std::string variable_name_to_go_name(const std::string& value);
- static bool can_be_nil(t_type* value);
-
+ static bool is_pointer_field(t_field* tfield, bool in_container = false);
+ static bool omit_initialization(t_field* tfield);
};
+//returns true if field initialization can be omitted since it has corresponding go type zero value
+//or default value is not set
+bool t_go_generator::omit_initialization(t_field* tfield) {
+ t_const_value* value = tfield->get_value();
+ if (!value) {
+ return true;
+ }
+ t_type* type = tfield->get_type()->get_true_type();
+ if (type->is_base_type()) {
+ t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
+
+ switch (tbase) {
+ case t_base_type::TYPE_VOID:
+ throw "";
+
+ case t_base_type::TYPE_STRING:
+ if (((t_base_type*)type)->is_binary()) {
+ //[]byte are always inline
+ return false;
+ }
+ //strings are pointers if has no default
+ return value->get_string().empty();
+
+ case t_base_type::TYPE_BOOL:
+ case t_base_type::TYPE_BYTE:
+ case t_base_type::TYPE_I16:
+ case t_base_type::TYPE_I32:
+ case t_base_type::TYPE_I64:
+ return value->get_integer()==0;
+ case t_base_type::TYPE_DOUBLE:
+ if (value->get_type() == t_const_value::CV_INTEGER) {
+ return value->get_integer()==0;
+ } else {
+ return value->get_double()==0.;
+ }
+ }
+ }
+ return false;
+}
+
+//Returns true if the type need a reference if used as optional without default
+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_string() && ((t_base_type*)type)->is_binary() )) {
+ return false;
+ }
+ return true;
+}
+
+//returns false if field could not use comparison to default value as !IsSet*
+bool t_go_generator::is_pointer_field(t_field* tfield, bool in_container_value) {
+ if (tfield->annotations_.count("cpp.ref")!=0) {
+ return true;
+ }
+ t_type* type = tfield->get_type()->get_true_type();
+ //Structs in containers are pointers
+ if (in_container_value && type->is_struct()) {
+ return true;
+ }
+ if (!(tfield->get_req() == t_field::T_OPTIONAL)) {
+ return false;
+ }
+
+ bool has_default = tfield->get_value();
+ if (type->is_base_type()) {
+ t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
+
+ switch (tbase) {
+ case t_base_type::TYPE_VOID:
+ throw "";
+
+ case t_base_type::TYPE_STRING:
+ if (((t_base_type*)type)->is_binary()) {
+ //[]byte are always inline
+ return false;
+ }
+ //strings are pointers if has no default
+ return !has_default;
+
+ case t_base_type::TYPE_BOOL:
+ case t_base_type::TYPE_BYTE:
+ case t_base_type::TYPE_I16:
+ case t_base_type::TYPE_I32:
+ case t_base_type::TYPE_I64:
+ case t_base_type::TYPE_DOUBLE:
+ return !has_default;
+ }
+ } else if (type->is_enum()) {
+ return !has_default;
+ } else if (type->is_struct() || type->is_xception()) {
+ return true;
+ } else if (type->is_map()) {
+ return has_default;
+ } else if (type->is_set()) {
+ return has_default;
+ } else if (type->is_list()) {
+ return has_default;
+ } else if (type->is_typedef()) {
+ return has_default;
+ }
+
+ throw "INVALID TYPE IN type_to_go_type: " + type->get_name();
+}
std::string t_go_generator::publicize(const std::string& value, bool is_args_or_result)
{
{
return
string("import (\n"
- "\t\"fmt\"\n"
+ "\t\"bytes\"\n"
+ "\t\"fmt\"\n"
"\t\"" + gen_thrift_import_ + "\"\n");
}
")\n\n"
"// (needed to ensure safety because of naive import list construction.)\n"
"var _ = thrift.ZERO\n"
- "var _ = fmt.Printf\n\n");
+ "var _ = fmt.Printf\n"
+ "var _ = bytes.Equal\n\n");
}
/**
t_type* vtype = ((t_map*)type)->get_val_type();
const map<t_const_value*, t_const_value*>& val = value->get_map();
out <<
- "map[" << type_to_go_type(ktype) << "]" << type_to_go_type(vtype) << "{" << endl;
+ "map[" << type_to_go_type(ktype) << "]" << type_to_go_type(vtype, true) << "{" << endl;
indent_up();
map<t_const_value*, t_const_value*>::const_iterator v_iter;
*OUT_def_value = tfield->get_value();
}
+void t_go_generator::generate_go_struct_initializer(ofstream& out,
+ t_struct* tstruct,
+ bool is_args_or_result)
+{
+ out << publicize(type_name(tstruct), is_args_or_result) << "{";
+ const vector<t_field*>& members = tstruct->get_members();
+ for (vector<t_field*>::const_iterator m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
+ bool pointer_field = is_pointer_field(*m_iter);
+ string publicized_name;
+ t_const_value* def_value;
+ get_publicized_name_and_def_value(*m_iter, &publicized_name, &def_value);
+ if (!pointer_field && def_value != NULL && !omit_initialization(*m_iter)) {
+ out << endl << indent() << publicized_name << ": " << render_field_initial_value(*m_iter, (*m_iter)->get_name(), pointer_field) << "," << endl;
+ }
+ }
+
+ out << "}" << endl;
+}
/**
* Generates a struct definition for a thrift data type.
}
t_type* fieldType = (*m_iter)->get_type();
- bool optional_field = ((*m_iter)->get_req() == t_field::T_OPTIONAL);
- string goType = type_to_go_type_with_opt(fieldType, optional_field);
+ string goType = type_to_go_type_with_opt(fieldType, is_pointer_field(*m_iter));
indent(out) << publicize(variable_name_to_go_name((*m_iter)->get_name())) << " "
<< goType << " `thrift:\""
out <<
indent() << "}" << endl << endl <<
indent() << "func New" << tstruct_name << "() *" << tstruct_name << " {" << endl <<
- indent() << " rval := &" << tstruct_name << "{";
-
+ indent() << " return &";
+ generate_go_struct_initializer(out, tstruct, is_result || is_args);
+ out <<
+ indent() << "}" << endl << endl;
+ // Default values for optional fields
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- bool optional_field = ((*m_iter)->get_req() == t_field::T_OPTIONAL);
-
- // Initialize struct fields, assigning defaults for non-optional (i.e.,
- // non-pointer) fields.
string publicized_name;
t_const_value* def_value;
get_publicized_name_and_def_value(*m_iter, &publicized_name, &def_value);
- if (def_value != NULL) {
- out << endl << indent() << publicized_name << ": " << render_field_initial_value(*m_iter, (*m_iter)->get_name(), optional_field) << "," << endl;
- }
- }
-
- out << "}" << endl;
-
- // Assign actual default values for optional fields in a second pass. See
- // the comment in render_field_initial_value for context and motivation.
- for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- if ((*m_iter)->get_req() == t_field::T_OPTIONAL) {
- string publicized_name;
- t_const_value* def_value;
- get_publicized_name_and_def_value(*m_iter, &publicized_name, &def_value);
+ t_type* fieldType = (*m_iter)->get_type();
+ string goType = type_to_go_type_with_opt(fieldType, false);
+ string def_var_name = tstruct_name + "_" + publicized_name + "_DEFAULT";
+ if ((*m_iter)->get_req() == t_field::T_OPTIONAL || is_pointer_field(*m_iter)) {
+ out << indent() << "var " << def_var_name <<" "<<goType ;
if (def_value != NULL) {
- // XXX
- // t_type* ttype = get_true_type((*m_iter)->get_type());
- t_type* ttype = (*m_iter)->get_type();
- out << indent() << "*(rval." << publicized_name << ") = " << render_const_value(ttype, def_value, (*m_iter)->get_name()) << endl;
+ out << " = " << render_const_value(fieldType, def_value, (*m_iter)->get_name()) ;
}
+ out <<endl;
+ }
+ if (is_pointer_field(*m_iter)) {
+ string goOptType = type_to_go_type_with_opt(fieldType, true);
+ string maybepointer = goOptType!=goType?"*":"";
+ out <<indent() << "func (p *" << tstruct_name << ") Get" << publicized_name << "() "<< goType<<" {" << endl
+ <<indent() << " if !p.IsSet" <<publicized_name <<"() {" <<endl
+ <<indent() << " return " <<def_var_name <<endl
+ <<indent() << " }" <<endl
+ <<indent() << "return "<<maybepointer <<"p." <<publicized_name <<endl
+ <<indent() << "}" <<endl;
+ } else {
+ out <<endl
+ <<indent() << "func (p *" << tstruct_name << ") Get" << publicized_name << "() "<< goType<<" {" << endl
+ <<indent() << "return p." <<publicized_name <<endl
+ <<indent() << "}" <<endl;
+
}
}
- out << "return rval" << endl;
-
- out << "}" << endl << endl;
generate_isset_helpers(out, tstruct, tstruct_name, is_result);
generate_go_struct_reader(out, tstruct, tstruct_name, is_result);
generate_go_struct_writer(out, tstruct, tstruct_name, is_result);
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
const string field_name(publicize(variable_name_to_go_name(escape_string((*f_iter)->get_name()))));
- if ((*f_iter)->get_req() == t_field::T_OPTIONAL) {
+ if ((*f_iter)->get_req() == t_field::T_OPTIONAL || is_pointer_field(*f_iter)) {
out <<
indent() << "func (p *" << tstruct_name << ") IsSet" << field_name << "() bool {" << endl;
indent_up();
- out <<
- indent() << "return p." << field_name << " != nil" << endl;
+ t_type* ttype = (*f_iter)->get_type()->get_true_type();
+ bool is_byteslice = ttype->is_base_type() && ((t_base_type*)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) {
+ out <<
+ indent() << "return p." << field_name << " != nil" << endl;
+ } else {
+ string def_var_name = tstruct_name + "_" + field_name + "_DEFAULT";
+ if (is_byteslice) {
+ out << indent() << "return !bytes.Equal(p." << field_name << ", "<<def_var_name << ")" << endl;
+ } else {
+ out << indent() << "return p." << field_name << " != "<<def_var_name << endl;
+ }
+ }
indent_down();
out <<
indent() << "}" << endl << endl;
string escape_field_name;
//t_const_value* field_default_value;
t_field::e_req field_required;
- bool field_can_be_nil = false;
int32_t field_id = -1;
- if (is_result && fields.size()) {
- out <<
- indent() << "switch {" << endl;
- vector<t_field*>::const_reverse_iterator fr_iter;
-
- for (fr_iter = fields.rbegin(); fr_iter != fields.rend(); ++fr_iter) {
- string field_method_prefix("writeField");
- field_name = (*fr_iter)->get_name();
- field_id = (*fr_iter)->get_key();
-
- if (field_id < 0) {
- field_method_prefix += "_";
- field_id *= -1;
- }
+ for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
+ string field_method_prefix("writeField");
+ field_name = (*f_iter)->get_name();
+ escape_field_name = escape_string(field_name);
+ field_id = (*f_iter)->get_key();
- if (can_be_nil((*fr_iter)->get_type()) && field_id != 0) {
- out <<
- indent() << "case p." << publicize(variable_name_to_go_name(field_name)) << " != nil:" << endl <<
- indent() << " if err := p." << field_method_prefix << field_id << "(oprot); err != nil { return err }" << endl;
- } else {
- out <<
- indent() << "default:" << endl <<
- indent() << " if err := p." << field_method_prefix << field_id << "(oprot); err != nil { return err }" << endl;
- }
+ if (field_id < 0) {
+ field_method_prefix += "_";
+ field_id *= -1;
}
out <<
- indent() << "}" << endl;
- } else {
- for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- string field_method_prefix("writeField");
- field_name = (*f_iter)->get_name();
- escape_field_name = escape_string(field_name);
- field_id = (*f_iter)->get_key();
-
- if (field_id < 0) {
- field_method_prefix += "_";
- field_id *= -1;
- }
-
- out <<
- indent() << "if err := p." << field_method_prefix << field_id << "(oprot); err != nil { return err }" << endl;
+ indent() << "if err := p." << field_method_prefix << field_id << "(oprot); err != nil { return err }" << endl;
- }
}
// Write the struct map
escape_field_name = escape_string(field_name);
//field_default_value = (*f_iter)->get_value();
field_required = (*f_iter)->get_req();
- field_can_be_nil = can_be_nil((*f_iter)->get_type());
if (field_id < 0) {
field_method_prefix += "_";
indent() << "func (p *" << tstruct_name << ") " << field_method_prefix << field_id << "(oprot thrift.TProtocol) (err error) {" << endl;
indent_up();
- // Write field header
- if (field_can_be_nil) {
- out <<
- indent() << "if p." << publicize(variable_name_to_go_name(field_name)) << " != nil {" << endl;
- indent_up();
- }
-
if (field_required == t_field::T_OPTIONAL) {
out <<
indent() << "if p.IsSet" << publicize(variable_name_to_go_name(field_name)) << "() {" << endl;
indent() << "}" << endl;
}
- if (field_can_be_nil) {
- indent_down();
- out <<
- indent() << "}" << endl;
- }
-
indent_down();
out <<
indent() << " return err" << endl <<
if (!tfunction->is_oneway()) {
t_struct result(program_, tfunction->get_name() + "_result");
t_field success(tfunction->get_returntype(), "success", 0);
+ success.set_req(t_field::T_OPTIONAL);
if (!tfunction->get_returntype()->is_void()) {
result.append(&success);
vector<t_field*>::const_iterator f_iter;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- result.append(*f_iter);
+ t_field* f = *f_iter;
+ f->set_req(t_field::T_OPTIONAL);
+ result.append(f);
}
generate_go_struct_definition(f_service_, &result, false, true);
indent_up();
std::string argsname = publicize((*f_iter)->get_name() + "_args",true);
// Serialize the request header
- string args(tmp("args"));
f_service_ <<
indent() << "oprot := p.OutputProtocol" << endl <<
indent() << "if oprot == nil {" << endl <<
indent_down();
f_service_ <<
indent() << "}" << endl <<
- indent() << args << " := New" << argsname << "()" << endl;
+ indent() << "args := " << argsname << "{" << endl;
for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
f_service_ <<
- indent() << args << "." << publicize(variable_name_to_go_name((*fld_iter)->get_name())) << " = " << variable_name_to_go_name((*fld_iter)->get_name()) << endl;
+ indent() << publicize(variable_name_to_go_name((*fld_iter)->get_name())) << " : " << variable_name_to_go_name((*fld_iter)->get_name()) << ","<< endl;
}
+ f_service_ <<
+ indent() << "}" << endl;
// Write to the stream
f_service_ <<
- indent() << "if err = " << args << ".Write(oprot); err != nil {" << endl;
+ indent() << "if err = args.Write(oprot); err != nil {" << endl;
indent_up();
f_service_ <<
indent() << "return" << endl;
"err error) {" << endl;
indent_up();
// TODO(mcslee): Validate message reply here, seq ids etc.
- string result(tmp("result"));
string error(tmp("error"));
string error2(tmp("error"));
f_service_ <<
indent() << " err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, \"" << (*f_iter)->get_name() << " failed: out of sequence response\")" << endl <<
indent() << " return" << endl <<
indent() << "}" << endl <<
- indent() << result << " := New" << resultname << "()" << endl <<
- indent() << "if err = " << result << ".Read(iprot); err != nil {" << endl <<
+ indent() << "result := " << resultname << "{}" << endl <<
+ indent() << "if err = result.Read(iprot); err != nil {" << endl <<
indent() << " return" << endl <<
indent() << "}" << endl <<
indent() << "if err = iprot.ReadMessageEnd(); err != nil {" << endl <<
const std::string pubname = publicize(varname);
f_service_ <<
- indent() << "if " << result << "." << pubname << " != nil {" << endl <<
- indent() << "err = " << result << "." << pubname << endl <<
+ indent() << "if result." << pubname << " != nil {" << endl <<
+ indent() << "err = result." << pubname << endl <<
indent() << "return " << endl <<
indent() << "}";
// Careful, only return _result if not a void function
if (!(*f_iter)->get_returntype()->is_void()) {
f_service_ <<
- indent() << "value = " << result << ".Success" << endl;
+ indent() << "value = result.GetSuccess()" << endl;
}
f_service_ <<
indent() << "func (p *" << processorName << ") Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {" << endl;
indent_up();
f_service_ <<
- indent() << "args := New" << argsname << "()" << endl <<
+ indent() << "args := " << argsname << "{}" << endl <<
indent() << "if err = args.Read(iprot); err != nil {" << endl <<
indent() << " iprot.ReadMessageEnd()" << endl;
if (!tfunction->is_oneway()) {
if (!tfunction->is_oneway()) {
f_service_ <<
- indent() << "result := New" << resultname << "()" << endl;
+ indent() << "result := " << resultname << "{}" << endl;
+ }
+ bool need_reference = type_need_reference(tfunction->get_returntype());
+ if (need_reference && !tfunction->is_oneway() && !tfunction->get_returntype()->is_void()) {
+ f_service_ << "var retval " <<type_to_go_type(tfunction->get_returntype()) <<endl;
}
f_service_ <<
if (!tfunction->is_oneway()) {
if (!tfunction->get_returntype()->is_void()) {
- f_service_ << "result.Success, ";
+ if( need_reference) {
+ f_service_ << "retval, ";
+ } else {
+ f_service_ << "result.Success, ";
+ }
}
}
for (xf_iter = x_fields.begin(); xf_iter != x_fields.end(); ++xf_iter) {
f_service_ <<
- indent() << " case *" << type_name((*xf_iter)->get_type()) << ":" << endl <<
+ indent() << " case *" << type_to_go_type(((*xf_iter)->get_type())) << ":" << endl <<
indent() << "result." << publicize(variable_name_to_go_name((*xf_iter)->get_name())) << " = v" << endl;
}
indent() << "}" << endl;
if (!tfunction->is_oneway()) {
+ if (need_reference && !tfunction->get_returntype()->is_void()) {
+ f_service_ << "result.Success = &retval" << endl;
+ }
f_service_ <<
indent() << "if err2 = oprot.WriteMessageBegin(\"" << escape_string(tfunction->get_name()) <<
"\", thrift.REPLY, seqId); err2 != nil {" << endl <<
string prefix,
bool inclass,
bool coerceData,
- bool inkey)
+ bool inkey,
+ bool in_container_value)
{
t_type* orig_type = tfield->get_type();
t_type* type = get_true_type(orig_type);
if (type->is_struct() || type->is_xception()) {
generate_deserialize_struct(out,
(t_struct*)type,
+ is_pointer_field(tfield, in_container_value),
declare,
name);
} else if (type->is_container()) {
generate_deserialize_container(out,
orig_type,
- tfield->get_req() == t_field::T_OPTIONAL,
+ is_pointer_field(tfield),
declare,
name);
} else if (type->is_base_type() || type->is_enum()) {
wrap = "int8";
}
- string maybe_address = ((tfield->get_req() == t_field::T_OPTIONAL) ? "&" : "");
+ string maybe_address = (is_pointer_field(tfield) ? "&" : "");
if (wrap == "") {
indent(out) << name << " = " << maybe_address << "v" << endl;
} else {
*/
void t_go_generator::generate_deserialize_struct(ofstream &out,
t_struct* tstruct,
+ bool pointer_field,
bool declare,
string prefix)
{
- string eq(" := ");
-
- if (!declare) {
- eq = " = ";
- }
+ string eq(declare ? " := " : " = ");
+ out << indent() << prefix << eq <<(pointer_field?"&":"");
+ generate_go_struct_initializer(out, tstruct);
out <<
- indent() << prefix << eq << new_prefix(type_name(tstruct)) << "()" << endl <<
indent() << "if err := " << prefix << ".Read(iprot); err != nil {" << endl <<
indent() << " return fmt.Errorf(\"%T error reading struct: %s\", " << prefix << ", err)" << endl <<
indent() << "}" << endl;
*/
void t_go_generator::generate_deserialize_container(ofstream &out,
t_type* orig_type,
- bool optional_field,
+ bool pointer_field,
bool declare,
string prefix)
{
indent() << " return fmt.Errorf(\"error reading map begin: %s\", err)" << endl <<
indent() << "}" << endl <<
indent() << "tMap := make(" << type_to_go_type(orig_type) << ", size)" << endl <<
- indent() << prefix << eq << " " << (optional_field ? "&" : "") << "tMap" << endl;
+ indent() << prefix << eq << " " << (pointer_field ? "&" : "") << "tMap" << endl;
} else if (ttype->is_set()) {
t_set* t = (t_set*)ttype;
out <<
indent() << " return fmt.Errorf(\"error reading set begin: %s\", err)" << endl <<
indent() << "}" << endl <<
indent() << "tSet := make(map[" << type_to_go_key_type(t->get_elem_type()) << "]bool, size)" << endl <<
- indent() << prefix << eq << " " << (optional_field ? "&" : "") << "tSet" << endl;
+ indent() << prefix << eq << " " << (pointer_field ? "&" : "") << "tSet" << endl;
} else if (ttype->is_list()) {
out <<
indent() << "_, size, err := iprot.ReadListBegin()" << endl <<
indent() << " return fmt.Errorf(\"error reading list begin: %s\", err)" << endl <<
indent() << "}" << endl <<
indent() << "tSlice := make(" << type_to_go_type(orig_type) << ", 0, size)" << endl <<
- indent() << prefix << eq << " " << (optional_field ? "&" : "") << "tSlice" << endl;
+ indent() << prefix << eq << " " << (pointer_field ? "&" : "") << "tSlice" << endl;
} else {
throw "INVALID TYPE IN generate_deserialize_container '" + ttype->get_name() + "' for prefix '" + prefix + "'";
}
indent() << "for i := 0; i < size; i ++ {" << endl;
indent_up();
- if (optional_field) {
+ if (pointer_field) {
prefix = "(*" + prefix + ")";
}
if (ttype->is_map()) {
fkey.set_req(t_field::T_OPT_IN_REQ_OUT);
fval.set_req(t_field::T_OPT_IN_REQ_OUT);
generate_deserialize_field(out, &fkey, true, "", false, false, true);
- generate_deserialize_field(out, &fval, true);
+ generate_deserialize_field(out, &fval, true, "", false, false, false, true);
indent(out) <<
prefix << "[" << key << "] = " << val << endl;
string elem = tmp("_elem");
t_field felem(((t_list*)tlist)->get_elem_type(), elem);
felem.set_req(t_field::T_OPT_IN_REQ_OUT);
- generate_deserialize_field(out, &felem, true, "");
+ generate_deserialize_field(out, &felem, true, "", false, false, false, true);
indent(out) <<
prefix << " = append(" << prefix << ", " << elem << ")" << endl;
}
} else if (type->is_container()) {
generate_serialize_container(out,
type,
- tfield->get_req() == t_field::T_OPTIONAL,
+ is_pointer_field(tfield),
name);
} else if (type->is_base_type() || type->is_enum()) {
indent(out) <<
"if err := oprot.";
- if (tfield->get_req() == t_field::T_OPTIONAL) {
+ if (is_pointer_field(tfield)) {
name = "*" + name;
}
void t_go_generator::generate_serialize_container(ofstream &out,
t_type* ttype,
- bool optional_field,
+ bool pointer_field,
string prefix)
{
- if (optional_field) {
+ if (pointer_field) {
prefix = "*" + prefix;
}
if (ttype->is_map()) {
/**
* Converts the parse type to a go type
*/
-string t_go_generator::type_to_go_type(t_type* type) {
- return type_to_go_type_with_opt(type, false);
+string t_go_generator::type_to_go_type(t_type* type, bool is_container_value) {
+ return type_to_go_type_with_opt(type, false, is_container_value);
}
/**
* Converts the parse type to a go type, taking into account whether the field
* associated with the type is T_OPTIONAL.
*/
-string t_go_generator::type_to_go_type_with_opt(t_type* type, bool optional_field)
+string t_go_generator::type_to_go_type_with_opt(t_type* type, bool optional_field, bool is_container_value)
{
- string maybe_pointer = (optional_field ? "*" : "");
+ string maybe_pointer(optional_field ? "*" : "");
if (type->is_base_type()) {
t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
} else if (type->is_enum()) {
return maybe_pointer + publicize(type_name(type));
} else if (type->is_struct() || type->is_xception()) {
- // Note that we always have a pointer type for the is_struct() or
- // is_xception() cases, regardless of optional_field.
- return string("*") + publicize(type_name(type));
+ if (is_container_value) {
+ maybe_pointer = "*";
+ }
+ return maybe_pointer + publicize(type_name(type));
} else if (type->is_map()) {
t_map* t = (t_map*)type;
string keyType = type_to_go_key_type(t->get_key_type());
- string valueType = type_to_go_type(t->get_val_type());
+ string valueType = type_to_go_type(t->get_val_type(), true);
return maybe_pointer + string("map[") + keyType + "]" + valueType;
} else if (type->is_set()) {
t_set* t = (t_set*)type;
return maybe_pointer + string("map[") + elemType + string("]bool");
} else if (type->is_list()) {
t_list* t = (t_list*)type;
- string elemType = type_to_go_type(t->get_elem_type());
+ string elemType = type_to_go_type(t->get_elem_type(), true);
return maybe_pointer + string("[]") + elemType;
} else if (type->is_typedef()) {
return maybe_pointer + publicize(type_name(type));
throw "INVALID TYPE IN type_to_go_type: " + type->get_name();
}
-
-/**
- * Converts the parse type to a go tyoe
- */
-bool t_go_generator::can_be_nil(t_type* type)
-{
- type = get_true_type(type);
-
- if (type->is_base_type()) {
- t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
-
- switch (tbase) {
- case t_base_type::TYPE_VOID:
- throw "Invalid Type for can_be_nil";
-
- case t_base_type::TYPE_BOOL:
- case t_base_type::TYPE_BYTE:
- case t_base_type::TYPE_I16:
- case t_base_type::TYPE_I32:
- case t_base_type::TYPE_I64:
- case t_base_type::TYPE_DOUBLE:
- return false;
-
- case t_base_type::TYPE_STRING:
- return (((t_base_type*)type)->is_binary());
- }
- } else if (type->is_enum()) {
- return false;
- } else if (type->is_struct() || type->is_xception()) {
- return true;
- } else if (type->is_map()) {
- return true;
- } else if (type->is_set()) {
- return true;
- } else if (type->is_list()) {
- return true;
- }
-
- throw "INVALID TYPE IN can_be_nil: " + type->get_name();
-}
-
-
-
/** See the comment inside generate_go_struct_definition for what this is. */
string t_go_generator::type_to_spec_args(t_type* ttype)
{
THRIFT_REGISTER_GENERATOR(go, "Go",
" package_prefix= Package prefix for generated files.\n" \
- " thrift_import= Override thrift package import path (default:" + default_thrift_import + ")\n")
+ " thrift_import= Override thrift package import path (default:" + default_thrift_import + ")\n" \
+ " package= Package name (default: inferred from thrift file name)\n")
IncludesTest.thrift \
NamespacedTest.thrift \
MultiplexedProtocolTest.thrift \
- OnewayTest.thrift
+ OnewayTest.thrift \
+ OptionalFieldsTest.thrift \
+ ServicesTest.thrift \
+ TypedefFieldTest.thrift \
+ RefAnnotationFieldsTest.thrift
mkdir -p gopath/src
- grep -v list.*map.*list.*map $(THRIFTTEST) > ThriftTest.thrift
+ grep -v list.*map.*list.*map $(THRIFTTEST) | grep -v 'set<Insanity>' > ThriftTest.thrift
$(THRIFT) -r IncludesTest.thrift
$(THRIFT) BinaryKeyTest.thrift
$(THRIFT) MultiplexedProtocolTest.thrift
$(THRIFT) OnewayTest.thrift
+ $(THRIFT) OptionalFieldsTest.thrift
+ $(THRIFT) ServicesTest.thrift
+ $(THRIFT) TypedefFieldTest.thrift
+ $(THRIFT) RefAnnotationFieldsTest.thrift
+ GOPATH=`pwd`/gopath $(GO) get code.google.com/p/gomock/gomock
ln -nfs ../../../thrift gopath/src/thrift
ln -nfs ../../tests gopath/src/tests
touch gopath
check: gopath
- GOPATH=`pwd`/gopath $(GO) build IncludesTest BinaryKeyTest
+ GOPATH=`pwd`/gopath $(GO) build \
+ IncludesTest \
+ BinaryKeyTest \
+ ServicesTest \
+ TypedefFieldTest \
+ RefAnnotationFieldsTest
GOPATH=`pwd`/gopath $(GO) test thrift tests
clean-local:
--- /dev/null
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+struct structA {
+ 1: required i64 sa_i
+}
+
+struct all_optional {
+ 1: optional string s = "DEFAULT",
+ 2: optional i64 i = 42,
+ 3: optional bool b = false,
+ 4: optional string s2,
+ 5: optional i64 i2,
+ 6: optional bool b2,
+ 7: optional structA aa,
+ 9: optional list<i64> l,
+ 10: optional list<i64> l2 = [1, 2],
+ 11: optional map<i64, i64> m,
+ 12: optional map<i64, i64> m2 = {1:2, 3:4},
+ 13: optional binary bin,
+ 14: optional binary bin2 = "asdf",
+}
+
+struct structB {
+ 1: required structA required_struct_thing
+ 2: optional structA optional_struct_thing
+}
--- /dev/null
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+struct structA {
+ 1: required i64 sa_i
+}
+
+struct all_referenced {
+ 1: optional string s = "DEFAULT" (cpp.ref = ""),
+ 2: optional i64 i = 42 (cpp.ref = ""),
+ 3: optional bool b = false (cpp.ref = ""),
+ 4: optional string s2 (cpp.ref = ""),
+ 5: optional i64 i2 (cpp.ref = ""),
+ 6: optional bool b2 (cpp.ref = ""),
+ 7: optional structA aa (cpp.ref = ""),
+ 9: optional list<i64> l (cpp.ref = ""),
+ 10: optional list<i64> l2 = [1, 2] (cpp.ref = ""),
+ 11: optional map<i64, i64> m (cpp.ref = ""),
+ 12: optional map<i64, i64> m2 = {1:2, 3:4} (cpp.ref = ""),
+ 13: optional binary bin (cpp.ref = ""),
+ 14: optional binary bin2 = "asdf" (cpp.ref = ""),
+
+ 15: required string ref_s = "DEFAULT" (cpp.ref = ""),
+ 16: required i64 ref_i = 42 (cpp.ref = ""),
+ 17: required bool ref_b = false (cpp.ref = ""),
+ 18: required string ref_s2 (cpp.ref = ""),
+ 19: required i64 ref_i2 (cpp.ref = ""),
+ 20: required bool ref_b2 (cpp.ref = ""),
+ 21: required structA ref_aa (cpp.ref = ""),
+ 22: required list<i64> ref_l (cpp.ref = ""),
+ 23: required list<i64> ref_l2 = [1, 2] (cpp.ref = ""),
+ 24: required map<i64, i64> ref_m (cpp.ref = ""),
+ 25: required map<i64, i64> ref_m2 = {1:2, 3:4} (cpp.ref = ""),
+ 26: required binary ref_bin (cpp.ref = ""),
+ 27: required binary ref_bin2 = "asdf" (cpp.ref = ""),
+
+}
+
+struct structB {
+ 1: required structA required_struct_thing
+ 2: optional structA optional_struct_thing
+}
--- /dev/null
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# We are only testing that generated code compiles, no correctness checking is done
+
+exception moderate_disaster {
+ 1: i32 errorCode,
+ 2: string message
+}
+
+exception total_disaster {
+ 1: string message
+ 2: optional bool president_was_woken_up = false
+}
+
+struct struct_a {
+ 1: required i64 whatever
+}
+
+service a_serv {
+ void voidfunc(),
+ void void_with_1ex() throws(1: moderate_disaster err1)
+ void void_with_2ex() throws(1: moderate_disaster err1, 2:total_disaster err2)
+
+ string stringfunc()
+ string stringfunc_1ex() throws(1: moderate_disaster err1)
+ string stringfunc_2ex() throws(1: moderate_disaster err1, 2:total_disaster err2)
+
+ i64 i64func()
+ i64 i64func_1ex() throws(1: moderate_disaster err1)
+ i64 i64func_2ex() throws(1: moderate_disaster err1, 2:total_disaster err2)
+
+ list<string> list_of_strings_func()
+ list<string> list_of_strings_func_1ex() throws(1: moderate_disaster err1)
+ list<string> list_of_strings_func_2ex() throws(1: moderate_disaster err1, 2:total_disaster err2)
+
+ map<i64,string> map_func()
+ map<i64,string> map_func_1ex() throws(1: moderate_disaster err1)
+ map<i64,string> map_func_2ex() throws(1: moderate_disaster err1, 2:total_disaster err2)
+
+ struct_a struct_a_func()
+ struct_a struct_a_func_1ex() throws(1: moderate_disaster err1)
+ struct_a struct_a_func_2ex() throws(1: moderate_disaster err1, 2:total_disaster err2)
+
+ void voidfunc_1int(1: i64 i),
+ void void_with_1ex_1int(1: i64 i) throws(1: moderate_disaster err1)
+ void void_with_2ex_1int(1: i64 i) throws(1: moderate_disaster err1, 2:total_disaster err2)
+
+ string stringfunc_1int(1: i64 i)
+ string stringfunc_1ex_1int(1: i64 i) throws(1: moderate_disaster err1)
+ string stringfunc_2ex_1int(1: i64 i) throws(1: moderate_disaster err1, 2:total_disaster err2)
+
+ i64 i64func_1int(1: i64 i)
+ i64 i64func_1ex_1int(1: i64 i) throws(1: moderate_disaster err1)
+ i64 i64func_2ex_1int(1: i64 i) throws(1: moderate_disaster err1, 2:total_disaster err2)
+
+ list<string> list_of_strings_func_1int(1: i64 i)
+ list<string> list_of_strings_func_1ex_1int(1: i64 i) throws(1: moderate_disaster err1)
+ list<string> list_of_strings_func_2ex_1int(1: i64 i) throws(1: moderate_disaster err1, 2:total_disaster err2)
+
+ map<i64,string> map_func_1int(1: i64 i)
+ map<i64,string> map_func_1ex_1int(1: i64 i) throws(1: moderate_disaster err1)
+ map<i64,string> map_func_2ex_1int(1: i64 i) throws(1: moderate_disaster err1, 2:total_disaster err2)
+
+ struct_a struct_a_func_1int(1: i64 i)
+ struct_a struct_a_func_1ex_1int(1: i64 i) throws(1: moderate_disaster err1)
+ struct_a struct_a_func_2ex_1int(1: i64 i) throws(1: moderate_disaster err1, 2:total_disaster err2)
+
+ void voidfunc_1int_1s(1: i64 i, 2: string s),
+ void void_with_1ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1)
+ void void_with_2ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1, 2:total_disaster err2)
+
+ string stringfunc_1int_1s(1: i64 i, 2: string s)
+ string stringfunc_1ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1)
+ string stringfunc_2ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1, 2:total_disaster err2)
+
+ i64 i64func_1int_1s(1: i64 i, 2: string s)
+ i64 i64func_1ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1)
+ i64 i64func_2ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1, 2:total_disaster err2)
+
+ list<string> list_of_strings_func_1int_1s(1: i64 i, 2: string s)
+ list<string> list_of_strings_func_1ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1)
+ list<string> list_of_strings_func_2ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1, 2:total_disaster err2)
+
+ map<i64,string> map_func_1int_1s(1: i64 i, 2: string s)
+ map<i64,string> map_func_1ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1)
+ map<i64,string> map_func_2ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1, 2:total_disaster err2)
+
+ struct_a struct_a_func_1int_1s(1: i64 i, 2: string s)
+ struct_a struct_a_func_1ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1)
+ struct_a struct_a_func_2ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1, 2:total_disaster err2)
+
+}
--- /dev/null
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# We are only testing that generated code compiles, no correctness checking is done
+
+enum Details {
+ Everything = 0
+ StateOnly = 1
+ StateAndOptions = 2
+ SomethingElse = 3
+}
+
+typedef list< Details> DetailsWanted
+
+struct BaseRequest {
+ 1 : optional string RequestID
+}
+
+struct GetMyDetails {
+ 1 : required BaseRequest base_
+ 2 : required string ObjectID
+ 3 : optional DetailsWanted DetailsWanted
+}
--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package tests
+
+import (
+ "OptionalFieldsTest"
+ "bytes"
+ gomock "code.google.com/p/gomock/gomock"
+ "testing"
+ "thrift"
+)
+
+func TestIsSetReturnFalseOnCreation(t *testing.T) {
+ ao := OptionalFieldsTest.NewAllOptional()
+ if ao.IsSetS() {
+ t.Errorf("Optional field S is set on initialization")
+ }
+ if ao.IsSetI() {
+ t.Errorf("Optional field I is set on initialization")
+ }
+ if ao.IsSetB() {
+ t.Errorf("Optional field B is set on initialization")
+ }
+ if ao.IsSetS2() {
+ t.Errorf("Optional field S2 is set on initialization")
+ }
+ if ao.IsSetI2() {
+ t.Errorf("Optional field I2 is set on initialization")
+ }
+ if ao.IsSetB2() {
+ t.Errorf("Optional field B2 is set on initialization")
+ }
+ if ao.IsSetAa() {
+ t.Errorf("Optional field Aa is set on initialization")
+ }
+ if ao.IsSetL() {
+ t.Errorf("Optional field L is set on initialization")
+ }
+ if ao.IsSetL2() {
+ t.Errorf("Optional field L2 is set on initialization")
+ }
+ if ao.IsSetM() {
+ t.Errorf("Optional field M is set on initialization")
+ }
+ if ao.IsSetM2() {
+ t.Errorf("Optional field M2 is set on initialization")
+ }
+ if ao.IsSetBin() {
+ t.Errorf("Optional field Bin is set on initialization")
+ }
+ if ao.IsSetBin2() {
+ t.Errorf("Optional field Bin2 is set on initialization")
+ }
+}
+
+func TestDefaultValuesOnCreation(t *testing.T) {
+ ao := OptionalFieldsTest.NewAllOptional()
+ if ao.GetS() != "DEFAULT" {
+ t.Errorf("Unexpected default value %#v for field S", ao.GetS())
+ }
+ if ao.GetI() != 42 {
+ t.Errorf("Unexpected default value %#v for field I", ao.GetI())
+ }
+ if ao.GetB() != false {
+ t.Errorf("Unexpected default value %#v for field B", ao.GetB())
+ }
+ if ao.GetS2() != "" {
+ t.Errorf("Unexpected default value %#v for field S2", ao.GetS2())
+ }
+ if ao.GetI2() != 0 {
+ t.Errorf("Unexpected default value %#v for field I2", ao.GetI2())
+ }
+ if ao.GetB2() != false {
+ t.Errorf("Unexpected default value %#v for field B2", ao.GetB2())
+ }
+ if l := ao.GetL(); len(l) != 0 {
+ t.Errorf("Unexpected default value %#v for field L", l)
+ }
+ if l := ao.GetL2(); len(l) != 2 || l[0] != 1 || l[1] != 2 {
+ t.Errorf("Unexpected default value %#v for field L2", l)
+ }
+ //FIXME: should we return empty map here?
+ if m := ao.GetM(); m != nil {
+ t.Errorf("Unexpected default value %#v for field M", m)
+ }
+ if m := ao.GetM2(); len(m) != 2 || m[1] != 2 || m[3] != 4 {
+ t.Errorf("Unexpected default value %#v for field M2", m)
+ }
+ if bv := ao.GetBin(); bv != nil {
+ t.Errorf("Unexpected default value %#v for field Bin", bv)
+ }
+ if bv := ao.GetBin2(); !bytes.Equal(bv, []byte("asdf")) {
+ t.Errorf("Unexpected default value %#v for field Bin2", bv)
+ }
+}
+
+func TestInitialValuesOnCreation(t *testing.T) {
+ ao := OptionalFieldsTest.NewAllOptional()
+ if ao.S != "DEFAULT" {
+ t.Errorf("Unexpected initial value %#v for field S", ao.S)
+ }
+ if ao.I != 42 {
+ t.Errorf("Unexpected initial value %#v for field I", ao.I)
+ }
+ if ao.B != false {
+ t.Errorf("Unexpected initial value %#v for field B", ao.B)
+ }
+ if ao.S2 != nil {
+ t.Errorf("Unexpected initial value %#v for field S2", ao.S2)
+ }
+ if ao.I2 != nil {
+ t.Errorf("Unexpected initial value %#v for field I2", ao.I2)
+ }
+ if ao.B2 != nil {
+ t.Errorf("Unexpected initial value %#v for field B2", ao.B2)
+ }
+ if ao.L != nil || len(ao.L) != 0 {
+ t.Errorf("Unexpected initial value %#v for field L", ao.L)
+ }
+ if ao.L2 != nil {
+ t.Errorf("Unexpected initial value %#v for field L2", ao.L2)
+ }
+ if ao.M != nil {
+ t.Errorf("Unexpected initial value %#v for field M", ao.M)
+ }
+ if ao.M2 != nil {
+ t.Errorf("Unexpected initial value %#v for field M2", ao.M2)
+ }
+ if ao.Bin != nil || len(ao.Bin) != 0 {
+ t.Errorf("Unexpected initial value %#v for field Bin", ao.Bin)
+ }
+ if !bytes.Equal(ao.Bin2, []byte("asdf")) {
+ t.Errorf("Unexpected initial value %#v for field Bin2", ao.Bin2)
+ }
+}
+
+func TestIsSetReturnTrueAfterUpdate(t *testing.T) {
+ ao := OptionalFieldsTest.NewAllOptional()
+ ao.S = "somevalue"
+ ao.I = 123
+ ao.B = true
+ ao.Aa = OptionalFieldsTest.NewStructA()
+ if !ao.IsSetS() {
+ t.Errorf("Field S should be set")
+ }
+ if !ao.IsSetI() {
+ t.Errorf("Field I should be set")
+ }
+ if !ao.IsSetB() {
+ t.Errorf("Field B should be set")
+ }
+ if !ao.IsSetAa() {
+ t.Errorf("Field aa should be set")
+ }
+}
+
+func TestListNotEmpty(t *testing.T) {
+ ao := OptionalFieldsTest.NewAllOptional()
+ ao.L = []int64{1, 2, 3}
+ if !ao.IsSetL() {
+ t.Errorf("Field L should be set")
+ }
+}
+
+//Make sure that optional fields are not being serialized
+func TestNoOptionalUnsetFieldsOnWire(t *testing.T) {
+ mockCtrl := gomock.NewController(t)
+ defer mockCtrl.Finish()
+ proto := NewMockTProtocol(mockCtrl)
+ gomock.InOrder(
+ proto.EXPECT().WriteStructBegin("all_optional").Return(nil),
+ proto.EXPECT().WriteFieldStop().Return(nil),
+ proto.EXPECT().WriteStructEnd().Return(nil),
+ )
+ ao := OptionalFieldsTest.NewAllOptional()
+ ao.Write(proto)
+}
+
+func TestNoSetToDefaultFieldsOnWire(t *testing.T) {
+ mockCtrl := gomock.NewController(t)
+ defer mockCtrl.Finish()
+ proto := NewMockTProtocol(mockCtrl)
+ gomock.InOrder(
+ proto.EXPECT().WriteStructBegin("all_optional").Return(nil),
+ proto.EXPECT().WriteFieldStop().Return(nil),
+ proto.EXPECT().WriteStructEnd().Return(nil),
+ )
+ ao := OptionalFieldsTest.NewAllOptional()
+ ao.I = 42
+ ao.Write(proto)
+}
+
+//Make sure that only one field is being serialized when set to non-default
+func TestOneISetFieldOnWire(t *testing.T) {
+ mockCtrl := gomock.NewController(t)
+ defer mockCtrl.Finish()
+ proto := NewMockTProtocol(mockCtrl)
+ gomock.InOrder(
+ proto.EXPECT().WriteStructBegin("all_optional").Return(nil),
+ proto.EXPECT().WriteFieldBegin("i", thrift.TType(thrift.I64), int16(2)).Return(nil),
+ proto.EXPECT().WriteI64(int64(123)).Return(nil),
+ proto.EXPECT().WriteFieldEnd().Return(nil),
+ proto.EXPECT().WriteFieldStop().Return(nil),
+ proto.EXPECT().WriteStructEnd().Return(nil),
+ )
+ ao := OptionalFieldsTest.NewAllOptional()
+ ao.I = 123
+ ao.Write(proto)
+}
+
+func TestOneLSetFieldOnWire(t *testing.T) {
+ mockCtrl := gomock.NewController(t)
+ defer mockCtrl.Finish()
+ proto := NewMockTProtocol(mockCtrl)
+ gomock.InOrder(
+ proto.EXPECT().WriteStructBegin("all_optional").Return(nil),
+ proto.EXPECT().WriteFieldBegin("l", thrift.TType(thrift.LIST), int16(9)).Return(nil),
+ proto.EXPECT().WriteListBegin(thrift.TType(thrift.I64), 2).Return(nil),
+ proto.EXPECT().WriteI64(int64(1)).Return(nil),
+ proto.EXPECT().WriteI64(int64(2)).Return(nil),
+ proto.EXPECT().WriteListEnd().Return(nil),
+ proto.EXPECT().WriteFieldEnd().Return(nil),
+ proto.EXPECT().WriteFieldStop().Return(nil),
+ proto.EXPECT().WriteStructEnd().Return(nil),
+ )
+ ao := OptionalFieldsTest.NewAllOptional()
+ ao.L = []int64{1, 2}
+ ao.Write(proto)
+}
+
+func TestOneBinSetFieldOnWire(t *testing.T) {
+ mockCtrl := gomock.NewController(t)
+ defer mockCtrl.Finish()
+ proto := NewMockTProtocol(mockCtrl)
+ gomock.InOrder(
+ proto.EXPECT().WriteStructBegin("all_optional").Return(nil),
+ proto.EXPECT().WriteFieldBegin("bin", thrift.TType(thrift.STRING), int16(13)).Return(nil),
+ proto.EXPECT().WriteBinary([]byte("somebytestring")).Return(nil),
+ proto.EXPECT().WriteFieldEnd().Return(nil),
+ proto.EXPECT().WriteFieldStop().Return(nil),
+ proto.EXPECT().WriteStructEnd().Return(nil),
+ )
+ ao := OptionalFieldsTest.NewAllOptional()
+ ao.Bin = []byte("somebytestring")
+ ao.Write(proto)
+}
+
+func TestOneEmptyBinSetFieldOnWire(t *testing.T) {
+ mockCtrl := gomock.NewController(t)
+ defer mockCtrl.Finish()
+ proto := NewMockTProtocol(mockCtrl)
+ gomock.InOrder(
+ proto.EXPECT().WriteStructBegin("all_optional").Return(nil),
+ proto.EXPECT().WriteFieldBegin("bin", thrift.TType(thrift.STRING), int16(13)).Return(nil),
+ proto.EXPECT().WriteBinary([]byte{}).Return(nil),
+ proto.EXPECT().WriteFieldEnd().Return(nil),
+ proto.EXPECT().WriteFieldStop().Return(nil),
+ proto.EXPECT().WriteStructEnd().Return(nil),
+ )
+ ao := OptionalFieldsTest.NewAllOptional()
+ ao.Bin = []byte{}
+ ao.Write(proto)
+}
--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// Automatically generated by MockGen. DO NOT EDIT!
+// Source: thrift (interfaces: TProtocol)
+
+package tests
+
+import (
+ thrift "thrift"
+ gomock "code.google.com/p/gomock/gomock"
+)
+
+// Mock of TProtocol interface
+type MockTProtocol struct {
+ ctrl *gomock.Controller
+ recorder *_MockTProtocolRecorder
+}
+
+// Recorder for MockTProtocol (not exported)
+type _MockTProtocolRecorder struct {
+ mock *MockTProtocol
+}
+
+func NewMockTProtocol(ctrl *gomock.Controller) *MockTProtocol {
+ mock := &MockTProtocol{ctrl: ctrl}
+ mock.recorder = &_MockTProtocolRecorder{mock}
+ return mock
+}
+
+func (_m *MockTProtocol) EXPECT() *_MockTProtocolRecorder {
+ return _m.recorder
+}
+
+func (_m *MockTProtocol) Flush() error {
+ ret := _m.ctrl.Call(_m, "Flush")
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) Flush() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "Flush")
+}
+
+func (_m *MockTProtocol) ReadBinary() ([]byte, error) {
+ ret := _m.ctrl.Call(_m, "ReadBinary")
+ ret0, _ := ret[0].([]byte)
+ ret1, _ := ret[1].(error)
+ return ret0, ret1
+}
+
+func (_mr *_MockTProtocolRecorder) ReadBinary() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadBinary")
+}
+
+func (_m *MockTProtocol) ReadBool() (bool, error) {
+ ret := _m.ctrl.Call(_m, "ReadBool")
+ ret0, _ := ret[0].(bool)
+ ret1, _ := ret[1].(error)
+ return ret0, ret1
+}
+
+func (_mr *_MockTProtocolRecorder) ReadBool() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadBool")
+}
+
+func (_m *MockTProtocol) ReadByte() (byte, error) {
+ ret := _m.ctrl.Call(_m, "ReadByte")
+ ret0, _ := ret[0].(byte)
+ ret1, _ := ret[1].(error)
+ return ret0, ret1
+}
+
+func (_mr *_MockTProtocolRecorder) ReadByte() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadByte")
+}
+
+func (_m *MockTProtocol) ReadDouble() (float64, error) {
+ ret := _m.ctrl.Call(_m, "ReadDouble")
+ ret0, _ := ret[0].(float64)
+ ret1, _ := ret[1].(error)
+ return ret0, ret1
+}
+
+func (_mr *_MockTProtocolRecorder) ReadDouble() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadDouble")
+}
+
+func (_m *MockTProtocol) ReadFieldBegin() (string, thrift.TType, int16, error) {
+ ret := _m.ctrl.Call(_m, "ReadFieldBegin")
+ ret0, _ := ret[0].(string)
+ ret1, _ := ret[1].(thrift.TType)
+ ret2, _ := ret[2].(int16)
+ ret3, _ := ret[3].(error)
+ return ret0, ret1, ret2, ret3
+}
+
+func (_mr *_MockTProtocolRecorder) ReadFieldBegin() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadFieldBegin")
+}
+
+func (_m *MockTProtocol) ReadFieldEnd() error {
+ ret := _m.ctrl.Call(_m, "ReadFieldEnd")
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) ReadFieldEnd() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadFieldEnd")
+}
+
+func (_m *MockTProtocol) ReadI16() (int16, error) {
+ ret := _m.ctrl.Call(_m, "ReadI16")
+ ret0, _ := ret[0].(int16)
+ ret1, _ := ret[1].(error)
+ return ret0, ret1
+}
+
+func (_mr *_MockTProtocolRecorder) ReadI16() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadI16")
+}
+
+func (_m *MockTProtocol) ReadI32() (int32, error) {
+ ret := _m.ctrl.Call(_m, "ReadI32")
+ ret0, _ := ret[0].(int32)
+ ret1, _ := ret[1].(error)
+ return ret0, ret1
+}
+
+func (_mr *_MockTProtocolRecorder) ReadI32() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadI32")
+}
+
+func (_m *MockTProtocol) ReadI64() (int64, error) {
+ ret := _m.ctrl.Call(_m, "ReadI64")
+ ret0, _ := ret[0].(int64)
+ ret1, _ := ret[1].(error)
+ return ret0, ret1
+}
+
+func (_mr *_MockTProtocolRecorder) ReadI64() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadI64")
+}
+
+func (_m *MockTProtocol) ReadListBegin() (thrift.TType, int, error) {
+ ret := _m.ctrl.Call(_m, "ReadListBegin")
+ ret0, _ := ret[0].(thrift.TType)
+ ret1, _ := ret[1].(int)
+ ret2, _ := ret[2].(error)
+ return ret0, ret1, ret2
+}
+
+func (_mr *_MockTProtocolRecorder) ReadListBegin() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadListBegin")
+}
+
+func (_m *MockTProtocol) ReadListEnd() error {
+ ret := _m.ctrl.Call(_m, "ReadListEnd")
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) ReadListEnd() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadListEnd")
+}
+
+func (_m *MockTProtocol) ReadMapBegin() (thrift.TType, thrift.TType, int, error) {
+ ret := _m.ctrl.Call(_m, "ReadMapBegin")
+ ret0, _ := ret[0].(thrift.TType)
+ ret1, _ := ret[1].(thrift.TType)
+ ret2, _ := ret[2].(int)
+ ret3, _ := ret[3].(error)
+ return ret0, ret1, ret2, ret3
+}
+
+func (_mr *_MockTProtocolRecorder) ReadMapBegin() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadMapBegin")
+}
+
+func (_m *MockTProtocol) ReadMapEnd() error {
+ ret := _m.ctrl.Call(_m, "ReadMapEnd")
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) ReadMapEnd() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadMapEnd")
+}
+
+func (_m *MockTProtocol) ReadMessageBegin() (string, thrift.TMessageType, int32, error) {
+ ret := _m.ctrl.Call(_m, "ReadMessageBegin")
+ ret0, _ := ret[0].(string)
+ ret1, _ := ret[1].(thrift.TMessageType)
+ ret2, _ := ret[2].(int32)
+ ret3, _ := ret[3].(error)
+ return ret0, ret1, ret2, ret3
+}
+
+func (_mr *_MockTProtocolRecorder) ReadMessageBegin() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadMessageBegin")
+}
+
+func (_m *MockTProtocol) ReadMessageEnd() error {
+ ret := _m.ctrl.Call(_m, "ReadMessageEnd")
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) ReadMessageEnd() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadMessageEnd")
+}
+
+func (_m *MockTProtocol) ReadSetBegin() (thrift.TType, int, error) {
+ ret := _m.ctrl.Call(_m, "ReadSetBegin")
+ ret0, _ := ret[0].(thrift.TType)
+ ret1, _ := ret[1].(int)
+ ret2, _ := ret[2].(error)
+ return ret0, ret1, ret2
+}
+
+func (_mr *_MockTProtocolRecorder) ReadSetBegin() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadSetBegin")
+}
+
+func (_m *MockTProtocol) ReadSetEnd() error {
+ ret := _m.ctrl.Call(_m, "ReadSetEnd")
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) ReadSetEnd() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadSetEnd")
+}
+
+func (_m *MockTProtocol) ReadString() (string, error) {
+ ret := _m.ctrl.Call(_m, "ReadString")
+ ret0, _ := ret[0].(string)
+ ret1, _ := ret[1].(error)
+ return ret0, ret1
+}
+
+func (_mr *_MockTProtocolRecorder) ReadString() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadString")
+}
+
+func (_m *MockTProtocol) ReadStructBegin() (string, error) {
+ ret := _m.ctrl.Call(_m, "ReadStructBegin")
+ ret0, _ := ret[0].(string)
+ ret1, _ := ret[1].(error)
+ return ret0, ret1
+}
+
+func (_mr *_MockTProtocolRecorder) ReadStructBegin() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadStructBegin")
+}
+
+func (_m *MockTProtocol) ReadStructEnd() error {
+ ret := _m.ctrl.Call(_m, "ReadStructEnd")
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) ReadStructEnd() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadStructEnd")
+}
+
+func (_m *MockTProtocol) Skip(_param0 thrift.TType) error {
+ ret := _m.ctrl.Call(_m, "Skip", _param0)
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) Skip(arg0 interface{}) *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "Skip", arg0)
+}
+
+func (_m *MockTProtocol) Transport() thrift.TTransport {
+ ret := _m.ctrl.Call(_m, "Transport")
+ ret0, _ := ret[0].(thrift.TTransport)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) Transport() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "Transport")
+}
+
+func (_m *MockTProtocol) WriteBinary(_param0 []byte) error {
+ ret := _m.ctrl.Call(_m, "WriteBinary", _param0)
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) WriteBinary(arg0 interface{}) *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteBinary", arg0)
+}
+
+func (_m *MockTProtocol) WriteBool(_param0 bool) error {
+ ret := _m.ctrl.Call(_m, "WriteBool", _param0)
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) WriteBool(arg0 interface{}) *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteBool", arg0)
+}
+
+func (_m *MockTProtocol) WriteByte(_param0 byte) error {
+ ret := _m.ctrl.Call(_m, "WriteByte", _param0)
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) WriteByte(arg0 interface{}) *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteByte", arg0)
+}
+
+func (_m *MockTProtocol) WriteDouble(_param0 float64) error {
+ ret := _m.ctrl.Call(_m, "WriteDouble", _param0)
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) WriteDouble(arg0 interface{}) *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteDouble", arg0)
+}
+
+func (_m *MockTProtocol) WriteFieldBegin(_param0 string, _param1 thrift.TType, _param2 int16) error {
+ ret := _m.ctrl.Call(_m, "WriteFieldBegin", _param0, _param1, _param2)
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) WriteFieldBegin(arg0, arg1, arg2 interface{}) *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteFieldBegin", arg0, arg1, arg2)
+}
+
+func (_m *MockTProtocol) WriteFieldEnd() error {
+ ret := _m.ctrl.Call(_m, "WriteFieldEnd")
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) WriteFieldEnd() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteFieldEnd")
+}
+
+func (_m *MockTProtocol) WriteFieldStop() error {
+ ret := _m.ctrl.Call(_m, "WriteFieldStop")
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) WriteFieldStop() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteFieldStop")
+}
+
+func (_m *MockTProtocol) WriteI16(_param0 int16) error {
+ ret := _m.ctrl.Call(_m, "WriteI16", _param0)
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) WriteI16(arg0 interface{}) *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteI16", arg0)
+}
+
+func (_m *MockTProtocol) WriteI32(_param0 int32) error {
+ ret := _m.ctrl.Call(_m, "WriteI32", _param0)
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) WriteI32(arg0 interface{}) *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteI32", arg0)
+}
+
+func (_m *MockTProtocol) WriteI64(_param0 int64) error {
+ ret := _m.ctrl.Call(_m, "WriteI64", _param0)
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) WriteI64(arg0 interface{}) *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteI64", arg0)
+}
+
+func (_m *MockTProtocol) WriteListBegin(_param0 thrift.TType, _param1 int) error {
+ ret := _m.ctrl.Call(_m, "WriteListBegin", _param0, _param1)
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) WriteListBegin(arg0, arg1 interface{}) *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteListBegin", arg0, arg1)
+}
+
+func (_m *MockTProtocol) WriteListEnd() error {
+ ret := _m.ctrl.Call(_m, "WriteListEnd")
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) WriteListEnd() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteListEnd")
+}
+
+func (_m *MockTProtocol) WriteMapBegin(_param0 thrift.TType, _param1 thrift.TType, _param2 int) error {
+ ret := _m.ctrl.Call(_m, "WriteMapBegin", _param0, _param1, _param2)
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) WriteMapBegin(arg0, arg1, arg2 interface{}) *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteMapBegin", arg0, arg1, arg2)
+}
+
+func (_m *MockTProtocol) WriteMapEnd() error {
+ ret := _m.ctrl.Call(_m, "WriteMapEnd")
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) WriteMapEnd() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteMapEnd")
+}
+
+func (_m *MockTProtocol) WriteMessageBegin(_param0 string, _param1 thrift.TMessageType, _param2 int32) error {
+ ret := _m.ctrl.Call(_m, "WriteMessageBegin", _param0, _param1, _param2)
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) WriteMessageBegin(arg0, arg1, arg2 interface{}) *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteMessageBegin", arg0, arg1, arg2)
+}
+
+func (_m *MockTProtocol) WriteMessageEnd() error {
+ ret := _m.ctrl.Call(_m, "WriteMessageEnd")
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) WriteMessageEnd() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteMessageEnd")
+}
+
+func (_m *MockTProtocol) WriteSetBegin(_param0 thrift.TType, _param1 int) error {
+ ret := _m.ctrl.Call(_m, "WriteSetBegin", _param0, _param1)
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) WriteSetBegin(arg0, arg1 interface{}) *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteSetBegin", arg0, arg1)
+}
+
+func (_m *MockTProtocol) WriteSetEnd() error {
+ ret := _m.ctrl.Call(_m, "WriteSetEnd")
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) WriteSetEnd() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteSetEnd")
+}
+
+func (_m *MockTProtocol) WriteString(_param0 string) error {
+ ret := _m.ctrl.Call(_m, "WriteString", _param0)
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) WriteString(arg0 interface{}) *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteString", arg0)
+}
+
+func (_m *MockTProtocol) WriteStructBegin(_param0 string) error {
+ ret := _m.ctrl.Call(_m, "WriteStructBegin", _param0)
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) WriteStructBegin(arg0 interface{}) *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteStructBegin", arg0)
+}
+
+func (_m *MockTProtocol) WriteStructEnd() error {
+ ret := _m.ctrl.Call(_m, "WriteStructEnd")
+ ret0, _ := ret[0].(error)
+ return ret0
+}
+
+func (_mr *_MockTProtocolRecorder) WriteStructEnd() *gomock.Call {
+ return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteStructEnd")
+}
func StringPtr(v string) *string { return &v }
func Uint32Ptr(v uint32) *uint32 { return &v }
func Uint64Ptr(v uint64) *uint64 { return &v }
+func BoolPtr(v bool) *bool { return &v }
+func ByteSlicePtr(v []byte) *[]byte { return &v }