mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 10:48:51 +00:00
Thrift generation for Java
Summary: Java works, benchmark roundtrip at around 3ms, so right in between C++ and PHP git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664775 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c29613f7ad
commit
78f58e2559
@ -35,9 +35,9 @@ BIN_DIR = bin/
|
|||||||
# Source files
|
# Source files
|
||||||
SRC_FILES = main.cc \
|
SRC_FILES = main.cc \
|
||||||
generate/t_generator.cc \
|
generate/t_generator.cc \
|
||||||
|
generate/t_java_generator.cc \
|
||||||
generate/t_php_generator.cc \
|
generate/t_php_generator.cc \
|
||||||
generate/t_cpp_generator.cc \
|
generate/t_cpp_generator.cc
|
||||||
generate/t_java_generator.cc
|
|
||||||
|
|
||||||
# Autogenerated files
|
# Autogenerated files
|
||||||
GEN_FILES = thrift.tab.hh \
|
GEN_FILES = thrift.tab.hh \
|
||||||
|
@ -667,15 +667,10 @@ void t_cpp_generator::generate_service_client(t_service* tservice) {
|
|||||||
f_service_ <<
|
f_service_ <<
|
||||||
indent() << "throw facebook::thrift::Exception(\"Unexpected message type, name, or id\");" << endl;
|
indent() << "throw facebook::thrift::Exception(\"Unexpected message type, name, or id\");" << endl;
|
||||||
indent_down();
|
indent_down();
|
||||||
f_service_ <<
|
|
||||||
indent() << "}" << endl;
|
|
||||||
|
|
||||||
f_service_ <<
|
f_service_ <<
|
||||||
endl <<
|
indent() << "}" << endl <<
|
||||||
indent() << resultname << " __result;" << endl;
|
indent() << resultname << " __result;" << endl <<
|
||||||
|
|
||||||
// Add a field to the return struct if non void
|
|
||||||
f_service_ <<
|
|
||||||
indent() << "read_struct_" << resultname << "(_iprot, _itrans, __result);" << endl <<
|
indent() << "read_struct_" << resultname << "(_iprot, _itrans, __result);" << endl <<
|
||||||
indent() << "_iprot->readMessageEnd(_itrans);" << endl <<
|
indent() << "_iprot->readMessageEnd(_itrans);" << endl <<
|
||||||
endl;
|
endl;
|
||||||
@ -727,21 +722,21 @@ void t_cpp_generator::generate_service_server(t_service* tservice) {
|
|||||||
|
|
||||||
// Generate the header portion
|
// Generate the header portion
|
||||||
f_header_ <<
|
f_header_ <<
|
||||||
"class " << service_name_ << "ServerIf : " <<
|
"class " << service_name_ << "Server : " <<
|
||||||
"public " << service_name_ << "If, " <<
|
"public " << service_name_ << "If, " <<
|
||||||
"public facebook::thrift::TProcessor {" << endl <<
|
"public facebook::thrift::TProcessor {" << endl <<
|
||||||
" public: " << endl;
|
" public: " << endl;
|
||||||
indent_up();
|
indent_up();
|
||||||
f_header_ <<
|
f_header_ <<
|
||||||
indent() <<
|
indent() <<
|
||||||
service_name_ << "ServerIf(boost::shared_ptr<const facebook::thrift::protocol::TProtocol> protocol) : " <<
|
service_name_ << "Server(boost::shared_ptr<const facebook::thrift::protocol::TProtocol> protocol) : " <<
|
||||||
"_iprot(protocol), _oprot(protocol) {}" << endl <<
|
"_iprot(protocol), _oprot(protocol) {}" << endl <<
|
||||||
indent() <<
|
indent() <<
|
||||||
service_name_ << "ServerIf(boost::shared_ptr<const facebook::thrift::protocol::TProtocol> iprot, boost::shared_ptr<const facebook::thrift::protocol::TProtocol> oprot) : " <<
|
service_name_ << "Server(boost::shared_ptr<const facebook::thrift::protocol::TProtocol> iprot, boost::shared_ptr<const facebook::thrift::protocol::TProtocol> oprot) : " <<
|
||||||
"_iprot(iprot), _oprot(oprot) {}" << endl <<
|
"_iprot(iprot), _oprot(oprot) {}" << endl <<
|
||||||
indent() << "bool process(boost::shared_ptr<facebook::thrift::transport::TTransport> _itrans, " <<
|
indent() << "bool process(boost::shared_ptr<facebook::thrift::transport::TTransport> _itrans, " <<
|
||||||
"boost::shared_ptr<facebook::thrift::transport::TTransport> _otrans);" << endl <<
|
"boost::shared_ptr<facebook::thrift::transport::TTransport> _otrans);" << endl <<
|
||||||
indent() << "virtual ~" << service_name_ << "ServerIf() {}" << endl;
|
indent() << "virtual ~" << service_name_ << "Server() {}" << endl;
|
||||||
indent_down();
|
indent_down();
|
||||||
|
|
||||||
// Protected data members
|
// Protected data members
|
||||||
@ -768,7 +763,7 @@ void t_cpp_generator::generate_service_server(t_service* tservice) {
|
|||||||
|
|
||||||
// Generate the server implementation
|
// Generate the server implementation
|
||||||
f_service_ <<
|
f_service_ <<
|
||||||
"bool " << service_name_ << "ServerIf::" <<
|
"bool " << service_name_ << "Server::" <<
|
||||||
"process(boost::shared_ptr<facebook::thrift::transport::TTransport> itrans, boost::shared_ptr<facebook::thrift::transport::TTransport> otrans) {" << endl;
|
"process(boost::shared_ptr<facebook::thrift::transport::TTransport> itrans, boost::shared_ptr<facebook::thrift::transport::TTransport> otrans) {" << endl;
|
||||||
indent_up();
|
indent_up();
|
||||||
|
|
||||||
@ -832,6 +827,10 @@ void t_cpp_generator::generate_service_server(t_service* tservice) {
|
|||||||
* @param tfunction The function
|
* @param tfunction The function
|
||||||
*/
|
*/
|
||||||
void t_cpp_generator::generate_function_helpers(t_function* tfunction) {
|
void t_cpp_generator::generate_function_helpers(t_function* tfunction) {
|
||||||
|
if (tfunction->is_async()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
t_struct result(tfunction->get_name() + "_result");
|
t_struct result(tfunction->get_name() + "_result");
|
||||||
t_field success(tfunction->get_returntype(), "success", 0);
|
t_field success(tfunction->get_returntype(), "success", 0);
|
||||||
if (!tfunction->get_returntype()->is_void()) {
|
if (!tfunction->get_returntype()->is_void()) {
|
||||||
@ -859,7 +858,7 @@ void t_cpp_generator::generate_process_function(t_service* tservice,
|
|||||||
t_function* tfunction) {
|
t_function* tfunction) {
|
||||||
// Open function
|
// Open function
|
||||||
f_service_ <<
|
f_service_ <<
|
||||||
"void " << tservice->get_name() << "ServerIf::" <<
|
"void " << tservice->get_name() << "Server::" <<
|
||||||
"process_" << tfunction->get_name() <<
|
"process_" << tfunction->get_name() <<
|
||||||
"(int32_t seqid, boost::shared_ptr<facebook::thrift::transport::TTransport> itrans, boost::shared_ptr<facebook::thrift::transport::TTransport> otrans)" << endl;
|
"(int32_t seqid, boost::shared_ptr<facebook::thrift::transport::TTransport> itrans, boost::shared_ptr<facebook::thrift::transport::TTransport> otrans)" << endl;
|
||||||
scope_up(f_service_);
|
scope_up(f_service_);
|
||||||
@ -871,13 +870,19 @@ void t_cpp_generator::generate_process_function(t_service* tservice,
|
|||||||
indent() << argsname << " __args;" << endl <<
|
indent() << argsname << " __args;" << endl <<
|
||||||
indent() << "read_struct_" << argsname << "(_iprot, itrans, __args);" << endl <<
|
indent() << "read_struct_" << argsname << "(_iprot, itrans, __args);" << endl <<
|
||||||
indent() << "_iprot->readMessageEnd(itrans);" << endl <<
|
indent() << "_iprot->readMessageEnd(itrans);" << endl <<
|
||||||
endl <<
|
endl;
|
||||||
indent() << resultname << " __result;" << endl;
|
|
||||||
|
|
||||||
t_struct* xs = tfunction->get_xceptions();
|
t_struct* xs = tfunction->get_xceptions();
|
||||||
const std::vector<t_field*>& xceptions = xs->get_members();
|
const std::vector<t_field*>& xceptions = xs->get_members();
|
||||||
vector<t_field*>::const_iterator x_iter;
|
vector<t_field*>::const_iterator x_iter;
|
||||||
|
|
||||||
|
// Declare result
|
||||||
|
if (!tfunction->is_async()) {
|
||||||
|
f_service_ <<
|
||||||
|
indent() << resultname << " __result;" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try block for functions with exceptions
|
||||||
if (xceptions.size() > 0) {
|
if (xceptions.size() > 0) {
|
||||||
f_service_ <<
|
f_service_ <<
|
||||||
indent() << "try {" << endl;
|
indent() << "try {" << endl;
|
||||||
@ -890,7 +895,7 @@ void t_cpp_generator::generate_process_function(t_service* tservice,
|
|||||||
vector<t_field*>::const_iterator f_iter;
|
vector<t_field*>::const_iterator f_iter;
|
||||||
|
|
||||||
f_service_ << indent();
|
f_service_ << indent();
|
||||||
if (!tfunction->get_returntype()->is_void()) {
|
if (!tfunction->is_async() && !tfunction->get_returntype()->is_void()) {
|
||||||
f_service_ << "__result.success = ";
|
f_service_ << "__result.success = ";
|
||||||
}
|
}
|
||||||
f_service_ <<
|
f_service_ <<
|
||||||
@ -907,26 +912,39 @@ void t_cpp_generator::generate_process_function(t_service* tservice,
|
|||||||
f_service_ << ");" << endl;
|
f_service_ << ");" << endl;
|
||||||
|
|
||||||
// Set isset on success field
|
// Set isset on success field
|
||||||
if (!tfunction->get_returntype()->is_void()) {
|
if (!tfunction->is_async() && !tfunction->get_returntype()->is_void()) {
|
||||||
f_service_ <<
|
f_service_ <<
|
||||||
indent() << "__result.__isset.success = true;" << endl;
|
indent() << "__result.__isset.success = true;" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xceptions.size() > 0) {
|
if (!tfunction->is_async() && xceptions.size() > 0) {
|
||||||
indent_down();
|
indent_down();
|
||||||
f_service_ << indent() << "}";
|
f_service_ << indent() << "}";
|
||||||
for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
|
for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
|
||||||
f_service_ << " catch (" << (*x_iter)->get_type()->get_name() << " &" << (*x_iter)->get_name() << ") {" << endl;
|
f_service_ << " catch (" << (*x_iter)->get_type()->get_name() << " &" << (*x_iter)->get_name() << ") {" << endl;
|
||||||
indent_up();
|
if (!tfunction->is_async()) {
|
||||||
f_service_ <<
|
indent_up();
|
||||||
indent() << "__result." << (*x_iter)->get_name() << " = " << (*x_iter)->get_name() << ";" << endl <<
|
f_service_ <<
|
||||||
indent() << "__result.__isset." << (*x_iter)->get_name() << " = true;" << endl;
|
indent() << "__result." << (*x_iter)->get_name() << " = " << (*x_iter)->get_name() << ";" << endl <<
|
||||||
indent_down();
|
indent() << "__result.__isset." << (*x_iter)->get_name() << " = true;" << endl;
|
||||||
f_service_ << indent() << "}";
|
indent_down();
|
||||||
|
f_service_ << indent() << "}";
|
||||||
|
} else {
|
||||||
|
f_service_ << "}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
f_service_ << endl;
|
f_service_ << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shortcut out here for async functions
|
||||||
|
if (tfunction->is_async()) {
|
||||||
|
f_service_ <<
|
||||||
|
indent() << "return;" << endl;
|
||||||
|
indent_down();
|
||||||
|
f_service_ << "}" << endl <<
|
||||||
|
endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Serialize the result into a struct
|
// Serialize the result into a struct
|
||||||
f_service_ <<
|
f_service_ <<
|
||||||
@ -977,6 +995,9 @@ void t_cpp_generator::generate_deserialize_field(t_field* tfield,
|
|||||||
case t_base_type::TYPE_STRING:
|
case t_base_type::TYPE_STRING:
|
||||||
f_service_ << "readString(itrans, " << name << ");";
|
f_service_ << "readString(itrans, " << name << ");";
|
||||||
break;
|
break;
|
||||||
|
case t_base_type::TYPE_BOOL:
|
||||||
|
f_service_ << "readBool(itrans, " << name << ");";
|
||||||
|
break;
|
||||||
case t_base_type::TYPE_BYTE:
|
case t_base_type::TYPE_BYTE:
|
||||||
f_service_ << "readByte(itrans, " << name << ");";
|
f_service_ << "readByte(itrans, " << name << ");";
|
||||||
break;
|
break;
|
||||||
@ -1172,6 +1193,9 @@ void t_cpp_generator::generate_serialize_field(t_field* tfield,
|
|||||||
case t_base_type::TYPE_STRING:
|
case t_base_type::TYPE_STRING:
|
||||||
f_service_ << "writeString(otrans, " << name << ");";
|
f_service_ << "writeString(otrans, " << name << ");";
|
||||||
break;
|
break;
|
||||||
|
case t_base_type::TYPE_BOOL:
|
||||||
|
f_service_ << "writeBool(otrans, " << name << ");";
|
||||||
|
break;
|
||||||
case t_base_type::TYPE_BYTE:
|
case t_base_type::TYPE_BYTE:
|
||||||
f_service_ << "writeByte(otrans, " << name << ");";
|
f_service_ << "writeByte(otrans, " << name << ");";
|
||||||
break;
|
break;
|
||||||
@ -1378,6 +1402,8 @@ string t_cpp_generator::base_type_name(t_base_type::t_base tbase) {
|
|||||||
return "void";
|
return "void";
|
||||||
case t_base_type::TYPE_STRING:
|
case t_base_type::TYPE_STRING:
|
||||||
return "std::string";
|
return "std::string";
|
||||||
|
case t_base_type::TYPE_BOOL:
|
||||||
|
return "bool";
|
||||||
case t_base_type::TYPE_BYTE:
|
case t_base_type::TYPE_BYTE:
|
||||||
return "int8_t";
|
return "int8_t";
|
||||||
case t_base_type::TYPE_I16:
|
case t_base_type::TYPE_I16:
|
||||||
@ -1413,6 +1439,9 @@ string t_cpp_generator::declare_field(t_field* tfield, bool init) {
|
|||||||
case t_base_type::TYPE_STRING:
|
case t_base_type::TYPE_STRING:
|
||||||
result += " = \"\"";
|
result += " = \"\"";
|
||||||
break;
|
break;
|
||||||
|
case t_base_type::TYPE_BOOL:
|
||||||
|
result += " = false";
|
||||||
|
break;
|
||||||
case t_base_type::TYPE_BYTE:
|
case t_base_type::TYPE_BYTE:
|
||||||
case t_base_type::TYPE_I16:
|
case t_base_type::TYPE_I16:
|
||||||
case t_base_type::TYPE_I32:
|
case t_base_type::TYPE_I32:
|
||||||
@ -1478,6 +1507,8 @@ string t_cpp_generator::type_to_enum(t_type* type) {
|
|||||||
throw "NO T_VOID CONSTRUCT";
|
throw "NO T_VOID CONSTRUCT";
|
||||||
case t_base_type::TYPE_STRING:
|
case t_base_type::TYPE_STRING:
|
||||||
return "facebook::thrift::protocol::T_STRING";
|
return "facebook::thrift::protocol::T_STRING";
|
||||||
|
case t_base_type::TYPE_BOOL:
|
||||||
|
return "facebook::thrift::protocol::T_BOOL";
|
||||||
case t_base_type::TYPE_BYTE:
|
case t_base_type::TYPE_BYTE:
|
||||||
return "facebook::thrift::protocol::T_BYTE";
|
return "facebook::thrift::protocol::T_BYTE";
|
||||||
case t_base_type::TYPE_I16:
|
case t_base_type::TYPE_I16:
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -31,52 +31,75 @@ class t_java_generator : public t_oop_generator {
|
|||||||
void generate_typedef (t_typedef* ttypedef);
|
void generate_typedef (t_typedef* ttypedef);
|
||||||
void generate_enum (t_enum* tenum);
|
void generate_enum (t_enum* tenum);
|
||||||
void generate_struct (t_struct* tstruct);
|
void generate_struct (t_struct* tstruct);
|
||||||
|
void generate_xception(t_struct* txception);
|
||||||
void generate_service (t_service* tservice);
|
void generate_service (t_service* tservice);
|
||||||
|
|
||||||
/** Service-level generation functions */
|
/** Service-level generation functions */
|
||||||
|
|
||||||
|
void generate_java_struct(t_struct* tstruct, bool is_exception);
|
||||||
|
|
||||||
|
void generate_java_struct_definition(std::ofstream& out, t_struct* tstruct, bool is_xception=false, bool in_class=false, bool is_result=false);
|
||||||
|
void generate_java_struct_reader(std::ofstream& out, t_struct* tstruct);
|
||||||
|
void generate_java_struct_result_writer(std::ofstream& out, t_struct* tstruct);
|
||||||
|
void generate_java_struct_writer(std::ofstream& out, t_struct* tstruct);
|
||||||
|
|
||||||
|
void generate_function_helpers(t_function* tfunction);
|
||||||
|
|
||||||
void generate_service_interface (t_service* tservice);
|
void generate_service_interface (t_service* tservice);
|
||||||
|
void generate_service_helpers (t_service* tservice);
|
||||||
void generate_service_client (t_service* tservice);
|
void generate_service_client (t_service* tservice);
|
||||||
void generate_service_server (t_service* tservice);
|
void generate_service_server (t_service* tservice);
|
||||||
void generate_process_function (t_service* tservice, t_function* tfunction);
|
void generate_process_function (t_service* tservice, t_function* tfunction);
|
||||||
|
|
||||||
/** Serialization constructs */
|
/** Serialization constructs */
|
||||||
|
|
||||||
void generate_deserialize_field (t_field* tfield,
|
void generate_deserialize_field (std::ofstream& out,
|
||||||
|
t_field* tfield,
|
||||||
std::string prefix="");
|
std::string prefix="");
|
||||||
|
|
||||||
void generate_deserialize_struct (t_struct* tstruct,
|
void generate_deserialize_struct (std::ofstream& out,
|
||||||
|
t_struct* tstruct,
|
||||||
std::string prefix="");
|
std::string prefix="");
|
||||||
|
|
||||||
void generate_deserialize_container (t_type* ttype,
|
void generate_deserialize_container (std::ofstream& out,
|
||||||
|
t_type* ttype,
|
||||||
std::string prefix="");
|
std::string prefix="");
|
||||||
|
|
||||||
void generate_deserialize_set_element (t_set* tset,
|
void generate_deserialize_set_element (std::ofstream& out,
|
||||||
|
t_set* tset,
|
||||||
std::string prefix="");
|
std::string prefix="");
|
||||||
|
|
||||||
void generate_deserialize_map_element (t_map* tmap,
|
void generate_deserialize_map_element (std::ofstream& out,
|
||||||
|
t_map* tmap,
|
||||||
std::string prefix="");
|
std::string prefix="");
|
||||||
|
|
||||||
void generate_deserialize_list_element (t_list* tlist,
|
void generate_deserialize_list_element (std::ofstream& out,
|
||||||
|
t_list* tlist,
|
||||||
std::string prefix="");
|
std::string prefix="");
|
||||||
|
|
||||||
void generate_serialize_field (t_field* tfield,
|
void generate_serialize_field (std::ofstream& out,
|
||||||
|
t_field* tfield,
|
||||||
std::string prefix="");
|
std::string prefix="");
|
||||||
|
|
||||||
void generate_serialize_struct (t_struct* tstruct,
|
void generate_serialize_struct (std::ofstream& out,
|
||||||
|
t_struct* tstruct,
|
||||||
std::string prefix="");
|
std::string prefix="");
|
||||||
|
|
||||||
void generate_serialize_container (t_type* ttype,
|
void generate_serialize_container (std::ofstream& out,
|
||||||
|
t_type* ttype,
|
||||||
std::string prefix="");
|
std::string prefix="");
|
||||||
|
|
||||||
void generate_serialize_map_element (t_map* tmap,
|
void generate_serialize_map_element (std::ofstream& out,
|
||||||
|
t_map* tmap,
|
||||||
std::string iter,
|
std::string iter,
|
||||||
std::string map);
|
std::string map);
|
||||||
|
|
||||||
void generate_serialize_set_element (t_set* tmap,
|
void generate_serialize_set_element (std::ofstream& out,
|
||||||
|
t_set* tmap,
|
||||||
std::string iter);
|
std::string iter);
|
||||||
|
|
||||||
void generate_serialize_list_element (t_list* tlist,
|
void generate_serialize_list_element (std::ofstream& out,
|
||||||
|
t_list* tlist,
|
||||||
std::string iter);
|
std::string iter);
|
||||||
|
|
||||||
/** Helper rendering functions */
|
/** Helper rendering functions */
|
||||||
@ -94,14 +117,9 @@ class t_java_generator : public t_oop_generator {
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
/** File streams */
|
/** File streams */
|
||||||
|
std::string package_name_;
|
||||||
|
|
||||||
std::ofstream f_types_;
|
|
||||||
std::ofstream f_header_;
|
|
||||||
std::ofstream f_service_;
|
std::ofstream f_service_;
|
||||||
|
|
||||||
std::ofstream f_client_;
|
|
||||||
std::ofstream f_server_;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -687,6 +687,11 @@ void t_php_generator::generate_deserialize_field(ofstream &out,
|
|||||||
indent() << "}" << endl <<
|
indent() << "}" << endl <<
|
||||||
indent() << "$" << name << " = " << itrans << "->readAll($_len);" << endl;
|
indent() << "$" << name << " = " << itrans << "->readAll($_len);" << endl;
|
||||||
break;
|
break;
|
||||||
|
case t_base_type::TYPE_BOOL:
|
||||||
|
out <<
|
||||||
|
indent() << "$" << name << " = unpack('c', " << itrans << "->readAll(1));" << endl <<
|
||||||
|
indent() << "$" << name << " = (bool)$" << name << "[1];" << endl;
|
||||||
|
break;
|
||||||
case t_base_type::TYPE_BYTE:
|
case t_base_type::TYPE_BYTE:
|
||||||
out <<
|
out <<
|
||||||
indent() << "$" << name << " = unpack('c', " << itrans << "->readAll(1));" << endl <<
|
indent() << "$" << name << " = unpack('c', " << itrans << "->readAll(1));" << endl <<
|
||||||
@ -748,6 +753,9 @@ void t_php_generator::generate_deserialize_field(ofstream &out,
|
|||||||
case t_base_type::TYPE_STRING:
|
case t_base_type::TYPE_STRING:
|
||||||
out << "readString($itrans, $" << name << ");";
|
out << "readString($itrans, $" << name << ");";
|
||||||
break;
|
break;
|
||||||
|
case t_base_type::TYPE_BOOL:
|
||||||
|
out << "readBool($itrans, $" << name << ");";
|
||||||
|
break;
|
||||||
case t_base_type::TYPE_BYTE:
|
case t_base_type::TYPE_BYTE:
|
||||||
out << "readByte($itrans, $" << name << ");";
|
out << "readByte($itrans, $" << name << ");";
|
||||||
break;
|
break;
|
||||||
@ -975,6 +983,10 @@ void t_php_generator::generate_serialize_field(ofstream &out,
|
|||||||
indent() << "$_output .= pack('N', strlen($" << name << "));" << endl <<
|
indent() << "$_output .= pack('N', strlen($" << name << "));" << endl <<
|
||||||
indent() << "$_output .= $" << name << ";" << endl;
|
indent() << "$_output .= $" << name << ";" << endl;
|
||||||
break;
|
break;
|
||||||
|
case t_base_type::TYPE_BOOL:
|
||||||
|
out <<
|
||||||
|
indent() << "$_output .= pack('c', $" << name << " ? 1 : 0);" << endl;
|
||||||
|
break;
|
||||||
case t_base_type::TYPE_BYTE:
|
case t_base_type::TYPE_BYTE:
|
||||||
out <<
|
out <<
|
||||||
indent() << "$_output .= pack('c', $" << name << ");" << endl;
|
indent() << "$_output .= pack('c', $" << name << ");" << endl;
|
||||||
@ -1013,6 +1025,9 @@ void t_php_generator::generate_serialize_field(ofstream &out,
|
|||||||
case t_base_type::TYPE_STRING:
|
case t_base_type::TYPE_STRING:
|
||||||
out << "writeString($otrans, $" << name << ");";
|
out << "writeString($otrans, $" << name << ");";
|
||||||
break;
|
break;
|
||||||
|
case t_base_type::TYPE_BOOL:
|
||||||
|
out << "writeBool($otrans, $" << name << ");";
|
||||||
|
break;
|
||||||
case t_base_type::TYPE_BYTE:
|
case t_base_type::TYPE_BYTE:
|
||||||
out << "writeByte($otrans, $" << name << ");";
|
out << "writeByte($otrans, $" << name << ");";
|
||||||
break;
|
break;
|
||||||
@ -1225,6 +1240,8 @@ string t_php_generator::base_type_name(t_base_type::t_base tbase) {
|
|||||||
return "void";
|
return "void";
|
||||||
case t_base_type::TYPE_STRING:
|
case t_base_type::TYPE_STRING:
|
||||||
return "TString";
|
return "TString";
|
||||||
|
case t_base_type::TYPE_BOOL:
|
||||||
|
return "bool";
|
||||||
case t_base_type::TYPE_BYTE:
|
case t_base_type::TYPE_BYTE:
|
||||||
return "UInt8";
|
return "UInt8";
|
||||||
case t_base_type::TYPE_I16:
|
case t_base_type::TYPE_I16:
|
||||||
@ -1258,6 +1275,9 @@ string t_php_generator::declare_field(t_field* tfield, bool init, bool obj) {
|
|||||||
case t_base_type::TYPE_STRING:
|
case t_base_type::TYPE_STRING:
|
||||||
result += " = ''";
|
result += " = ''";
|
||||||
break;
|
break;
|
||||||
|
case t_base_type::TYPE_BOOL:
|
||||||
|
result += " = false";
|
||||||
|
break;
|
||||||
case t_base_type::TYPE_BYTE:
|
case t_base_type::TYPE_BYTE:
|
||||||
case t_base_type::TYPE_I16:
|
case t_base_type::TYPE_I16:
|
||||||
case t_base_type::TYPE_I32:
|
case t_base_type::TYPE_I32:
|
||||||
@ -1330,6 +1350,8 @@ string t_php_generator ::type_to_enum(t_type* type) {
|
|||||||
throw "NO T_VOID CONSTRUCT";
|
throw "NO T_VOID CONSTRUCT";
|
||||||
case t_base_type::TYPE_STRING:
|
case t_base_type::TYPE_STRING:
|
||||||
return "TType::STRING";
|
return "TType::STRING";
|
||||||
|
case t_base_type::TYPE_BOOL:
|
||||||
|
return "TType::BOOL";
|
||||||
case t_base_type::TYPE_BYTE:
|
case t_base_type::TYPE_BYTE:
|
||||||
return "TType::BYTE";
|
return "TType::BYTE";
|
||||||
case t_base_type::TYPE_I16:
|
case t_base_type::TYPE_I16:
|
||||||
|
@ -41,7 +41,7 @@ class t_php_generator : public t_oop_generator {
|
|||||||
|
|
||||||
|
|
||||||
void generate_php_struct(t_struct* tstruct, bool is_exception);
|
void generate_php_struct(t_struct* tstruct, bool is_exception);
|
||||||
void generate_php_struct_definition(std::ofstream& out, t_struct* tstruct, bool is_xception);
|
void generate_php_struct_definition(std::ofstream& out, t_struct* tstruct, bool is_xception=false);
|
||||||
void generate_php_struct_reader(std::ofstream& out, t_struct* tstruct);
|
void generate_php_struct_reader(std::ofstream& out, t_struct* tstruct);
|
||||||
void generate_php_struct_writer(std::ofstream& out, t_struct* tstruct);
|
void generate_php_struct_writer(std::ofstream& out, t_struct* tstruct);
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ class t_base_type : public t_type {
|
|||||||
enum t_base {
|
enum t_base {
|
||||||
TYPE_VOID,
|
TYPE_VOID,
|
||||||
TYPE_STRING,
|
TYPE_STRING,
|
||||||
|
TYPE_BOOL,
|
||||||
TYPE_BYTE,
|
TYPE_BYTE,
|
||||||
TYPE_I16,
|
TYPE_I16,
|
||||||
TYPE_I32,
|
TYPE_I32,
|
||||||
|
@ -32,6 +32,7 @@ class t_program {
|
|||||||
name_(name), namespace_() {
|
name_(name), namespace_() {
|
||||||
type_void = new t_base_type("void", t_base_type::TYPE_VOID);
|
type_void = new t_base_type("void", t_base_type::TYPE_VOID);
|
||||||
type_string = new t_base_type("string", t_base_type::TYPE_STRING);
|
type_string = new t_base_type("string", t_base_type::TYPE_STRING);
|
||||||
|
type_bool = new t_base_type("bool", t_base_type::TYPE_BOOL);
|
||||||
type_byte = new t_base_type("byte", t_base_type::TYPE_BYTE);
|
type_byte = new t_base_type("byte", t_base_type::TYPE_BYTE);
|
||||||
type_i16 = new t_base_type("i16", t_base_type::TYPE_I16);
|
type_i16 = new t_base_type("i16", t_base_type::TYPE_I16);
|
||||||
type_i32 = new t_base_type("i32", t_base_type::TYPE_I32);
|
type_i32 = new t_base_type("i32", t_base_type::TYPE_I32);
|
||||||
@ -40,6 +41,7 @@ class t_program {
|
|||||||
|
|
||||||
~t_program() {
|
~t_program() {
|
||||||
delete type_string;
|
delete type_string;
|
||||||
|
delete type_bool;
|
||||||
delete type_byte;
|
delete type_byte;
|
||||||
delete type_i16;
|
delete type_i16;
|
||||||
delete type_i32;
|
delete type_i32;
|
||||||
@ -62,6 +64,7 @@ class t_program {
|
|||||||
// Accessors for global types
|
// Accessors for global types
|
||||||
t_type* get_void_type() const { return type_void; }
|
t_type* get_void_type() const { return type_void; }
|
||||||
t_type* get_string_type() const { return type_string; }
|
t_type* get_string_type() const { return type_string; }
|
||||||
|
t_type* get_bool_type() const { return type_byte; }
|
||||||
t_type* get_byte_type() const { return type_byte; }
|
t_type* get_byte_type() const { return type_byte; }
|
||||||
t_type* get_i16_type() const { return type_i16; }
|
t_type* get_i16_type() const { return type_i16; }
|
||||||
t_type* get_i32_type() const { return type_i32; }
|
t_type* get_i32_type() const { return type_i32; }
|
||||||
@ -122,6 +125,7 @@ class t_program {
|
|||||||
// Global base types
|
// Global base types
|
||||||
t_type* type_void;
|
t_type* type_void;
|
||||||
t_type* type_string;
|
t_type* type_string;
|
||||||
|
t_type* type_bool;
|
||||||
t_type* type_byte;
|
t_type* type_byte;
|
||||||
t_type* type_i16;
|
t_type* type_i16;
|
||||||
t_type* type_i32;
|
t_type* type_i32;
|
||||||
|
@ -36,6 +36,7 @@ symbol ([\,\{\}\(\)\=<>])
|
|||||||
"namespace" { return tok_namespace; }
|
"namespace" { return tok_namespace; }
|
||||||
|
|
||||||
"void" { return tok_void; }
|
"void" { return tok_void; }
|
||||||
|
"bool" { return tok_bool; }
|
||||||
"byte" { return tok_byte; }
|
"byte" { return tok_byte; }
|
||||||
"i16" { return tok_i16; }
|
"i16" { return tok_i16; }
|
||||||
"i32" { return tok_i32; }
|
"i32" { return tok_i32; }
|
||||||
|
@ -39,6 +39,7 @@ int y_field_val = -1;
|
|||||||
%token tok_namespace
|
%token tok_namespace
|
||||||
|
|
||||||
/** Base datatypes */
|
/** Base datatypes */
|
||||||
|
%token tok_bool
|
||||||
%token tok_byte
|
%token tok_byte
|
||||||
%token tok_string
|
%token tok_string
|
||||||
%token tok_i16
|
%token tok_i16
|
||||||
@ -368,6 +369,11 @@ BaseType:
|
|||||||
pdebug("BaseType -> tok_string");
|
pdebug("BaseType -> tok_string");
|
||||||
$$ = g_program->get_string_type();
|
$$ = g_program->get_string_type();
|
||||||
}
|
}
|
||||||
|
| tok_bool
|
||||||
|
{
|
||||||
|
pdebug("BaseType -> tok_bool");
|
||||||
|
$$ = g_program->get_bool_type();
|
||||||
|
}
|
||||||
| tok_byte
|
| tok_byte
|
||||||
{
|
{
|
||||||
pdebug("BaseType -> tok_byte");
|
pdebug("BaseType -> tok_byte");
|
||||||
|
@ -200,10 +200,15 @@ class TProtocol {
|
|||||||
*/
|
*/
|
||||||
uint32_t skip(shared_ptr<TTransport> in, TType type) const {
|
uint32_t skip(shared_ptr<TTransport> in, TType type) const {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case T_BOOL:
|
||||||
|
{
|
||||||
|
bool boolv;
|
||||||
|
return readBool(in, boolv);
|
||||||
|
}
|
||||||
case T_BYTE:
|
case T_BYTE:
|
||||||
{
|
{
|
||||||
int8_t byte;
|
int8_t bytev;
|
||||||
return readByte(in, byte);
|
return readByte(in, bytev);
|
||||||
}
|
}
|
||||||
case T_I16:
|
case T_I16:
|
||||||
{
|
{
|
||||||
|
@ -9,13 +9,23 @@ import com.facebook.thrift.transport.TTransport;
|
|||||||
* @author Mark Slee <mcslee@facebook.com>
|
* @author Mark Slee <mcslee@facebook.com>
|
||||||
*/
|
*/
|
||||||
public class TBinaryProtocol implements TProtocol {
|
public class TBinaryProtocol implements TProtocol {
|
||||||
|
|
||||||
|
public void writeMessageBegin(TTransport out, TMessage message) throws TException {
|
||||||
|
writeString(out, message.name);
|
||||||
|
writeByte(out, message.type);
|
||||||
|
writeI32(out, message.seqid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeMessageEnd(TTransport out) throws TException {}
|
||||||
|
|
||||||
|
|
||||||
public void writeStructBegin(TTransport out, TStruct struct) throws TException {}
|
public void writeStructBegin(TTransport out, TStruct struct) throws TException {}
|
||||||
|
|
||||||
public void writeStructEnd(TTransport out) throws TException {}
|
public void writeStructEnd(TTransport out) throws TException {}
|
||||||
|
|
||||||
public void writeFieldBegin(TTransport out, TField field) throws TException {
|
public void writeFieldBegin(TTransport out, TField field) throws TException {
|
||||||
writeByte(out, field.type);
|
writeByte(out, field.type);
|
||||||
writeI32(out, field.id);
|
writeI16(out, field.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeFieldEnd(TTransport out) throws TException {}
|
public void writeFieldEnd(TTransport out) throws TException {}
|
||||||
@ -46,14 +56,21 @@ public class TBinaryProtocol implements TProtocol {
|
|||||||
|
|
||||||
public void writeSetEnd(TTransport out) throws TException {}
|
public void writeSetEnd(TTransport out) throws TException {}
|
||||||
|
|
||||||
|
public void writeBool(TTransport out, boolean b) throws TException {
|
||||||
|
writeByte(out, b ? (byte)1 : (byte)0);
|
||||||
|
}
|
||||||
|
|
||||||
byte[] bout = new byte[1];
|
byte[] bout = new byte[1];
|
||||||
public void writeByte(TTransport out, byte b) throws TException {
|
public void writeByte(TTransport out, byte b) throws TException {
|
||||||
bout[0] = b;
|
bout[0] = b;
|
||||||
out.write(bout, 0, 1);
|
out.write(bout, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeU32(TTransport out, int u32) throws TException {
|
byte[] i16out = new byte[2];
|
||||||
writeI32(out, u32);
|
public void writeI16(TTransport out, short i16) throws TException {
|
||||||
|
i16out[0] = (byte)(0xff & (i16 >> 8));
|
||||||
|
i16out[1] = (byte)(0xff & (i16));
|
||||||
|
out.write(i16out, 0, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] i32out = new byte[4];
|
byte[] i32out = new byte[4];
|
||||||
@ -65,10 +82,6 @@ public class TBinaryProtocol implements TProtocol {
|
|||||||
out.write(i32out, 0, 4);
|
out.write(i32out, 0, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeU64(TTransport out, long u64) throws TException {
|
|
||||||
writeI64(out, u64);
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] i64out = new byte[8];
|
byte[] i64out = new byte[8];
|
||||||
public void writeI64(TTransport out, long i64) throws TException {
|
public void writeI64(TTransport out, long i64) throws TException {
|
||||||
i64out[0] = (byte)(0xff & (i64 >> 56));
|
i64out[0] = (byte)(0xff & (i64 >> 56));
|
||||||
@ -92,6 +105,16 @@ public class TBinaryProtocol implements TProtocol {
|
|||||||
* Reading methods.
|
* Reading methods.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
public TMessage readMessageBegin(TTransport in) throws TException {
|
||||||
|
TMessage message = new TMessage();
|
||||||
|
message.name = readString(in);
|
||||||
|
message.type = readByte(in);
|
||||||
|
message.seqid = readI32(in);
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readMessageEnd(TTransport in) throws TException {}
|
||||||
|
|
||||||
public TStruct readStructBegin(TTransport in) throws TException {
|
public TStruct readStructBegin(TTransport in) throws TException {
|
||||||
return new TStruct();
|
return new TStruct();
|
||||||
}
|
}
|
||||||
@ -102,7 +125,7 @@ public class TBinaryProtocol implements TProtocol {
|
|||||||
TField field = new TField();
|
TField field = new TField();
|
||||||
field.type = readByte(in);
|
field.type = readByte(in);
|
||||||
if (field.type != TType.STOP) {
|
if (field.type != TType.STOP) {
|
||||||
field.id = readI32(in);
|
field.id = readI16(in);
|
||||||
}
|
}
|
||||||
return field;
|
return field;
|
||||||
}
|
}
|
||||||
@ -137,14 +160,23 @@ public class TBinaryProtocol implements TProtocol {
|
|||||||
|
|
||||||
public void readSetEnd(TTransport in) throws TException {}
|
public void readSetEnd(TTransport in) throws TException {}
|
||||||
|
|
||||||
|
public boolean readBool(TTransport in) throws TException {
|
||||||
|
return (readByte(in) == 1);
|
||||||
|
}
|
||||||
|
|
||||||
byte[] bin = new byte[1];
|
byte[] bin = new byte[1];
|
||||||
public byte readByte(TTransport in) throws TException {
|
public byte readByte(TTransport in) throws TException {
|
||||||
in.readAll(bin, 0, 1);
|
in.readAll(bin, 0, 1);
|
||||||
return bin[0];
|
return bin[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int readU32(TTransport in) throws TException {
|
byte[] i16rd = new byte[2];
|
||||||
return readI32(in);
|
public short readI16(TTransport in) throws TException {
|
||||||
|
in.readAll(i16rd, 0, 2);
|
||||||
|
return
|
||||||
|
(short)
|
||||||
|
(((i16rd[0] & 0xff) << 8) |
|
||||||
|
((i16rd[1] & 0xff)));
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] i32rd = new byte[4];
|
byte[] i32rd = new byte[4];
|
||||||
@ -156,11 +188,7 @@ public class TBinaryProtocol implements TProtocol {
|
|||||||
((i32rd[2] & 0xff) << 8) |
|
((i32rd[2] & 0xff) << 8) |
|
||||||
((i32rd[3] & 0xff));
|
((i32rd[3] & 0xff));
|
||||||
}
|
}
|
||||||
|
|
||||||
public long readU64(TTransport in) throws TException {
|
|
||||||
return readI64(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] i64rd = new byte[8];
|
byte[] i64rd = new byte[8];
|
||||||
public long readI64(TTransport in) throws TException {
|
public long readI64(TTransport in) throws TException {
|
||||||
in.readAll(i64rd, 0, 8);
|
in.readAll(i64rd, 0, 8);
|
||||||
|
@ -8,7 +8,7 @@ package com.facebook.thrift.protocol;
|
|||||||
public class TField {
|
public class TField {
|
||||||
public TField() {}
|
public TField() {}
|
||||||
|
|
||||||
public TField(String n, byte t, int i) {
|
public TField(String n, byte t, short i) {
|
||||||
name = n;
|
name = n;
|
||||||
type = t;
|
type = t;
|
||||||
id = i;
|
id = i;
|
||||||
@ -16,5 +16,5 @@ public class TField {
|
|||||||
|
|
||||||
public String name = "";
|
public String name = "";
|
||||||
public byte type = TType.STOP;
|
public byte type = TType.STOP;
|
||||||
public int id = 0;
|
public short id = 0;
|
||||||
}
|
}
|
||||||
|
20
lib/java/src/protocol/TMessage.java
Normal file
20
lib/java/src/protocol/TMessage.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package com.facebook.thrift.protocol;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper class that encapsulates struct metadata.
|
||||||
|
*
|
||||||
|
* @author Mark Slee <mcslee@facebook.com>
|
||||||
|
*/
|
||||||
|
public class TMessage {
|
||||||
|
public TMessage() {}
|
||||||
|
|
||||||
|
public TMessage(String n, byte t, int s) {
|
||||||
|
name = n;
|
||||||
|
type = t;
|
||||||
|
seqid = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String name = "";
|
||||||
|
public byte type;
|
||||||
|
public int seqid;
|
||||||
|
}
|
11
lib/java/src/protocol/TMessageType.java
Normal file
11
lib/java/src/protocol/TMessageType.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package com.facebook.thrift.protocol;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Message type constants in the Thrift protocol.
|
||||||
|
*
|
||||||
|
* @author Mark Slee <mcslee@facebook.com>
|
||||||
|
*/
|
||||||
|
public final class TMessageType {
|
||||||
|
public static final byte CALL = 1;
|
||||||
|
public static final byte REPLY = 2;
|
||||||
|
}
|
@ -14,6 +14,11 @@ public interface TProtocol {
|
|||||||
* Writing methods.
|
* Writing methods.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
public void writeMessageBegin(TTransport out,
|
||||||
|
TMessage message) throws TException;
|
||||||
|
|
||||||
|
public void writeMessageEnd (TTransport out) throws TException;
|
||||||
|
|
||||||
public void writeStructBegin (TTransport out,
|
public void writeStructBegin (TTransport out,
|
||||||
TStruct struct) throws TException;
|
TStruct struct) throws TException;
|
||||||
|
|
||||||
@ -41,18 +46,18 @@ public interface TProtocol {
|
|||||||
|
|
||||||
public void writeSetEnd (TTransport out) throws TException;
|
public void writeSetEnd (TTransport out) throws TException;
|
||||||
|
|
||||||
|
public void writeBool (TTransport out,
|
||||||
|
boolean b) throws TException;
|
||||||
|
|
||||||
public void writeByte (TTransport out,
|
public void writeByte (TTransport out,
|
||||||
byte b) throws TException;
|
byte b) throws TException;
|
||||||
|
|
||||||
public void writeU32 (TTransport out,
|
public void writeI16 (TTransport out,
|
||||||
int u32) throws TException;
|
short i16) throws TException;
|
||||||
|
|
||||||
public void writeI32 (TTransport out,
|
public void writeI32 (TTransport out,
|
||||||
int i32) throws TException;
|
int i32) throws TException;
|
||||||
|
|
||||||
public void writeU64 (TTransport out,
|
|
||||||
long u64) throws TException;
|
|
||||||
|
|
||||||
public void writeI64 (TTransport out,
|
public void writeI64 (TTransport out,
|
||||||
long i64) throws TException;
|
long i64) throws TException;
|
||||||
|
|
||||||
@ -63,36 +68,40 @@ public interface TProtocol {
|
|||||||
* Reading methods.
|
* Reading methods.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public TStruct readStructBegin (TTransport in) throws TException;
|
public TMessage readMessageBegin (TTransport in) throws TException;
|
||||||
|
|
||||||
public void readStructEnd (TTransport in) throws TException;
|
public void readMessageEnd (TTransport in) throws TException;
|
||||||
|
|
||||||
public TField readFieldBegin (TTransport in) throws TException;
|
public TStruct readStructBegin (TTransport in) throws TException;
|
||||||
|
|
||||||
|
public void readStructEnd (TTransport in) throws TException;
|
||||||
|
|
||||||
|
public TField readFieldBegin (TTransport in) throws TException;
|
||||||
|
|
||||||
public void readFieldEnd (TTransport in) throws TException;
|
public void readFieldEnd (TTransport in) throws TException;
|
||||||
|
|
||||||
public TMap readMapBegin (TTransport in) throws TException;
|
public TMap readMapBegin (TTransport in) throws TException;
|
||||||
|
|
||||||
public void readMapEnd (TTransport in) throws TException;
|
public void readMapEnd (TTransport in) throws TException;
|
||||||
|
|
||||||
public TList readListBegin (TTransport in) throws TException;
|
public TList readListBegin (TTransport in) throws TException;
|
||||||
|
|
||||||
public void readListEnd (TTransport in) throws TException;
|
public void readListEnd (TTransport in) throws TException;
|
||||||
|
|
||||||
public TSet readSetBegin (TTransport in) throws TException;
|
public TSet readSetBegin (TTransport in) throws TException;
|
||||||
|
|
||||||
public void readSetEnd (TTransport in) throws TException;
|
public void readSetEnd (TTransport in) throws TException;
|
||||||
|
|
||||||
public byte readByte (TTransport in) throws TException;
|
public boolean readBool (TTransport in) throws TException;
|
||||||
|
|
||||||
public int readU32 (TTransport in) throws TException;
|
public byte readByte (TTransport in) throws TException;
|
||||||
|
|
||||||
public int readI32 (TTransport in) throws TException;
|
public short readI16 (TTransport in) throws TException;
|
||||||
|
|
||||||
public long readU64 (TTransport in) throws TException;
|
public int readI32 (TTransport in) throws TException;
|
||||||
|
|
||||||
public long readI64 (TTransport in) throws TException;
|
public long readI64 (TTransport in) throws TException;
|
||||||
|
|
||||||
public String readString (TTransport in) throws TException;
|
public String readString (TTransport in) throws TException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,16 +14,22 @@ public class TProtocolUtil {
|
|||||||
throws TException {
|
throws TException {
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case TType.BOOL:
|
||||||
|
{
|
||||||
|
prot.readBool(in);
|
||||||
|
}
|
||||||
case TType.BYTE:
|
case TType.BYTE:
|
||||||
{
|
{
|
||||||
prot.readByte(in);
|
prot.readByte(in);
|
||||||
}
|
}
|
||||||
case TType.U32:
|
case TType.I16:
|
||||||
|
{
|
||||||
|
prot.readI16(in);
|
||||||
|
}
|
||||||
case TType.I32:
|
case TType.I32:
|
||||||
{
|
{
|
||||||
prot.readI32(in);
|
prot.readI32(in);
|
||||||
}
|
}
|
||||||
case TType.U64:
|
|
||||||
case TType.I64:
|
case TType.I64:
|
||||||
{
|
{
|
||||||
prot.readI64(in);
|
prot.readI64(in);
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
package com.facebook.thrift.protocol;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper around String so that you can pass this object to a function and
|
|
||||||
* have it set the internal string value.
|
|
||||||
*
|
|
||||||
* @author Mark Slee <mcslee@facebook.com>
|
|
||||||
*/
|
|
||||||
public class TString {
|
|
||||||
public TString() {}
|
|
||||||
|
|
||||||
public TString(String v) {
|
|
||||||
value = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String value = "";
|
|
||||||
}
|
|
@ -6,17 +6,16 @@ package com.facebook.thrift.protocol;
|
|||||||
* @author Mark Slee <mcslee@facebook.com>
|
* @author Mark Slee <mcslee@facebook.com>
|
||||||
*/
|
*/
|
||||||
public final class TType {
|
public final class TType {
|
||||||
public static final byte STOP = 1;
|
public static final byte STOP = 0;
|
||||||
public static final byte BYTE = 2;
|
public static final byte VOID = 1;
|
||||||
public static final byte U16 = 3;
|
public static final byte BOOL = 2;
|
||||||
public static final byte I16 = 4;
|
public static final byte BYTE = 3;
|
||||||
public static final byte U32 = 5;
|
public static final byte I16 = 6;
|
||||||
public static final byte I32 = 6;
|
public static final byte I32 = 8;
|
||||||
public static final byte U64 = 7;
|
public static final byte I64 = 10;
|
||||||
public static final byte I64 = 8;
|
public static final byte STRING = 11;
|
||||||
public static final byte STRING = 9;
|
public static final byte STRUCT = 12;
|
||||||
public static final byte STRUCT = 10;
|
public static final byte MAP = 13;
|
||||||
public static final byte MAP = 11;
|
public static final byte SET = 14;
|
||||||
public static final byte SET = 12;
|
public static final byte LIST = 15;
|
||||||
public static final byte LIST = 13;
|
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,8 @@ abstract class TProtocol {
|
|||||||
|
|
||||||
public abstract function writeSetEnd($out);
|
public abstract function writeSetEnd($out);
|
||||||
|
|
||||||
|
public abstract function writeBool($out, $bool);
|
||||||
|
|
||||||
public abstract function writeByte($out, $byte);
|
public abstract function writeByte($out, $byte);
|
||||||
|
|
||||||
public abstract function writeI16($out, $i16);
|
public abstract function writeI16($out, $i16);
|
||||||
@ -127,6 +129,8 @@ abstract class TProtocol {
|
|||||||
|
|
||||||
public abstract function readSetEnd($in);
|
public abstract function readSetEnd($in);
|
||||||
|
|
||||||
|
public abstract function readBool($in, &$bool);
|
||||||
|
|
||||||
public abstract function readByte($in, &$byte);
|
public abstract function readByte($in, &$byte);
|
||||||
|
|
||||||
public abstract function readI16($in, &$i16);
|
public abstract function readI16($in, &$i16);
|
||||||
@ -146,6 +150,8 @@ abstract class TProtocol {
|
|||||||
*/
|
*/
|
||||||
public function skip($in, $type) {
|
public function skip($in, $type) {
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
|
case TType::BOOL:
|
||||||
|
return $this->readBool($in, $bool);
|
||||||
case TType::BYTE:
|
case TType::BYTE:
|
||||||
return $this->readByte($in, $byte);
|
return $this->readByte($in, $byte);
|
||||||
case TType::I16;
|
case TType::I16;
|
||||||
|
@ -11,22 +11,22 @@
|
|||||||
* Data types that can be sent via Thrift
|
* Data types that can be sent via Thrift
|
||||||
*/
|
*/
|
||||||
class TType {
|
class TType {
|
||||||
const STOP = 0;
|
const STOP = 0;
|
||||||
const VOID = 1;
|
const VOID = 1;
|
||||||
const BOOL = 2;
|
const BOOL = 2;
|
||||||
const BYTE = 3;
|
const BYTE = 3;
|
||||||
const I08 = 4;
|
const I08 = 4;
|
||||||
const I16 = 6;
|
const I16 = 6;
|
||||||
const I32 = 8;
|
const I32 = 8;
|
||||||
const I64 = 10;
|
const I64 = 10;
|
||||||
const STRING = 11;
|
const STRING = 11;
|
||||||
const UTF7 = 11;
|
const UTF7 = 11;
|
||||||
const STRUCT = 12;
|
const STRUCT = 12;
|
||||||
const MAP = 13;
|
const MAP = 13;
|
||||||
const SET = 14;
|
const SET = 14;
|
||||||
const LST = 15; // N.B. cannot use LIST keyword in PHP!
|
const LST = 15; // N.B. cannot use LIST keyword in PHP!
|
||||||
const UTF8 = 16;
|
const UTF8 = 16;
|
||||||
const UTF16 = 17;
|
const UTF16 = 17;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,7 +34,7 @@ class TType {
|
|||||||
*/
|
*/
|
||||||
class TMessageType {
|
class TMessageType {
|
||||||
const CALL = 1;
|
const CALL = 1;
|
||||||
const REPLY = 2;
|
const REPLY = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -19,10 +19,10 @@ using namespace facebook::thrift::server;
|
|||||||
|
|
||||||
using namespace thrift::test;
|
using namespace thrift::test;
|
||||||
|
|
||||||
class TestServer : public ThriftTestServerIf {
|
class TestServer : public ThriftTestServer {
|
||||||
public:
|
public:
|
||||||
TestServer(shared_ptr<TProtocol> protocol) :
|
TestServer(shared_ptr<TProtocol> protocol) :
|
||||||
ThriftTestServerIf(protocol) {}
|
ThriftTestServer(protocol) {}
|
||||||
|
|
||||||
void testVoid() {
|
void testVoid() {
|
||||||
printf("testVoid()\n");
|
printf("testVoid()\n");
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
<target name="generate">
|
<target name="generate">
|
||||||
<exec executable="thrift">
|
<exec executable="thrift">
|
||||||
<arg line="-java ../ThriftTest.thrift" />
|
<arg line="--java ../ThriftTest.thrift" />
|
||||||
</exec>
|
</exec>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
@ -23,6 +23,11 @@
|
|||||||
<javac srcdir="${src}" destdir="${build}" classpath="${cpath}:${gen}" />
|
<javac srcdir="${src}" destdir="${build}" classpath="${cpath}:${gen}" />
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
<target name="compileonly">
|
||||||
|
<javac srcdir="${gen}" destdir="${build}" classpath="${cpath}" />
|
||||||
|
<javac srcdir="${src}" destdir="${build}" classpath="${cpath}:${gen}" />
|
||||||
|
</target>
|
||||||
|
|
||||||
<target name="test" depends="compile">
|
<target name="test" depends="compile">
|
||||||
<jar jarfile="thrifttest.jar" basedir="${build}"/>
|
<jar jarfile="thrifttest.jar" basedir="${build}"/>
|
||||||
</target>
|
</target>
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.facebook.thrift.test;
|
package com.facebook.thrift.test;
|
||||||
|
|
||||||
import ThriftTest.*;
|
// Generated code
|
||||||
import com.facebook.thrift.types.*;
|
import thrift.test.*;
|
||||||
|
|
||||||
import com.facebook.thrift.transport.TSocket;
|
import com.facebook.thrift.transport.TSocket;
|
||||||
import com.facebook.thrift.transport.TTransportException;
|
import com.facebook.thrift.transport.TTransportException;
|
||||||
import com.facebook.thrift.protocol.TBinaryProtocol;
|
import com.facebook.thrift.protocol.TBinaryProtocol;
|
||||||
import com.facebook.thrift.protocol.TString;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -39,8 +39,8 @@ public class TestClient {
|
|||||||
new TSocket(host, port);
|
new TSocket(host, port);
|
||||||
TBinaryProtocol binaryProtocol =
|
TBinaryProtocol binaryProtocol =
|
||||||
new TBinaryProtocol();
|
new TBinaryProtocol();
|
||||||
ThriftTestClient testClient =
|
ThriftTest.Client testClient =
|
||||||
new ThriftTestClient(tSocket, binaryProtocol);
|
new ThriftTest.Client(tSocket, binaryProtocol);
|
||||||
|
|
||||||
for (int test = 0; test < numTests; ++test) {
|
for (int test = 0; test < numTests; ++test) {
|
||||||
|
|
||||||
@ -69,154 +69,154 @@ public class TestClient {
|
|||||||
* STRING TEST
|
* STRING TEST
|
||||||
*/
|
*/
|
||||||
System.out.print("testString(\"Test\")");
|
System.out.print("testString(\"Test\")");
|
||||||
TString s = testClient.testString(new TString("Test"));
|
String s = testClient.testString("Test");
|
||||||
System.out.print(" = \"" + s.value + "\"\n");
|
System.out.print(" = \"" + s + "\"\n");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BYTE TEST
|
* BYTE TEST
|
||||||
*/
|
*/
|
||||||
System.out.print("testByte(1)");
|
System.out.print("testByte(1)");
|
||||||
UInt8 u8 = testClient.testByte(new UInt8((short)1));
|
byte i8 = testClient.testByte((byte)1);
|
||||||
System.out.print(" = " + u8.get() + "\n");
|
System.out.print(" = " + i8 + "\n");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* I32 TEST
|
* I32 TEST
|
||||||
*/
|
*/
|
||||||
System.out.print("testI32(-1)");
|
System.out.print("testI32(-1)");
|
||||||
Int32 i32 = testClient.testI32(new Int32(-1));
|
int i32 = testClient.testI32(-1);
|
||||||
System.out.print(" = " + i32.get() + "\n");
|
System.out.print(" = " + i32 + "\n");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* I64 TEST
|
* I64 TEST
|
||||||
*/
|
*/
|
||||||
System.out.print("testI64(-34359738368)");
|
System.out.print("testI64(-34359738368)");
|
||||||
Int64 i64 = testClient.testI64(new Int64(-34359738368L));
|
long i64 = testClient.testI64(-34359738368L);
|
||||||
System.out.print(" = " + i64.get() + "\n");
|
System.out.print(" = " + i64 + "\n");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* STRUCT TEST
|
* STRUCT TEST
|
||||||
*/
|
*/
|
||||||
System.out.print("testStruct({\"Zero\", 1, -3, -5})");
|
System.out.print("testStruct({\"Zero\", 1, -3, -5})");
|
||||||
Xtruct out = new Xtruct();
|
Xtruct out = new Xtruct();
|
||||||
out.string_thing.value = "Zero";
|
out.string_thing = "Zero";
|
||||||
out.byte_thing.set((short)1);
|
out.byte_thing = (byte) 1;
|
||||||
out.i32_thing.set(-3);
|
out.i32_thing = -3;
|
||||||
out.i64_thing.set(-5);
|
out.i64_thing = -5;
|
||||||
Xtruct in = testClient.testStruct(out);
|
Xtruct in = testClient.testStruct(out);
|
||||||
System.out.print(" = {" +
|
System.out.print(" = {" +
|
||||||
"\"" + in.string_thing.value + "\", " +
|
"\"" + in.string_thing + "\", " +
|
||||||
in.byte_thing.get() + ", " +
|
in.byte_thing + ", " +
|
||||||
in.i32_thing.get() + ", " +
|
in.i32_thing + ", " +
|
||||||
in.i64_thing.get() + "}\n");
|
in.i64_thing + "}\n");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NESTED STRUCT TEST
|
* NESTED STRUCT TEST
|
||||||
*/
|
*/
|
||||||
System.out.print("testNest({1, {\"Zero\", 1, -3, -5}), 5}");
|
System.out.print("testNest({1, {\"Zero\", 1, -3, -5}), 5}");
|
||||||
Xtruct2 out2 = new Xtruct2();
|
Xtruct2 out2 = new Xtruct2();
|
||||||
out2.byte_thing.set((short)1);
|
out2.byte_thing = (short)1;
|
||||||
out2.struct_thing = out;
|
out2.struct_thing = out;
|
||||||
out2.i32_thing.set(5);
|
out2.i32_thing = 5;
|
||||||
Xtruct2 in2 = testClient.testNest(out2);
|
Xtruct2 in2 = testClient.testNest(out2);
|
||||||
in = in2.struct_thing;
|
in = in2.struct_thing;
|
||||||
System.out.print(" = {" +
|
System.out.print(" = {" +
|
||||||
in2.byte_thing.get() + ", {" +
|
in2.byte_thing + ", {" +
|
||||||
"\"" + in.string_thing.value + "\", " +
|
"\"" + in.string_thing + "\", " +
|
||||||
in.byte_thing.get() + ", " +
|
in.byte_thing + ", " +
|
||||||
in.i32_thing.get() + ", " +
|
in.i32_thing + ", " +
|
||||||
in.i64_thing.get() + "}, " +
|
in.i64_thing + "}, " +
|
||||||
in2.i32_thing.get() + "}\n");
|
in2.i32_thing + "}\n");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MAP TEST
|
* MAP TEST
|
||||||
*/
|
*/
|
||||||
HashMap<Int32,Int32> mapout = new HashMap<Int32,Int32>();
|
HashMap<Integer,Integer> mapout = new HashMap<Integer,Integer>();
|
||||||
for (int i = 0; i < 5; ++i) {
|
for (int i = 0; i < 5; ++i) {
|
||||||
mapout.put(new Int32(i), new Int32(i-10));
|
mapout.put(i, i-10);
|
||||||
}
|
}
|
||||||
System.out.print("testMap({");
|
System.out.print("testMap({");
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (Int32 key : mapout.keySet()) {
|
for (int key : mapout.keySet()) {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
System.out.print(", ");
|
System.out.print(", ");
|
||||||
}
|
}
|
||||||
System.out.print(key.get() + " => " + mapout.get(key).get());
|
System.out.print(key + " => " + mapout.get(key));
|
||||||
}
|
}
|
||||||
System.out.print("})");
|
System.out.print("})");
|
||||||
HashMap<Int32,Int32> mapin = testClient.testMap(mapout);
|
HashMap<Integer,Integer> mapin = testClient.testMap(mapout);
|
||||||
System.out.print(" = {");
|
System.out.print(" = {");
|
||||||
first = true;
|
first = true;
|
||||||
for (Int32 key : mapin.keySet()) {
|
for (int key : mapin.keySet()) {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
System.out.print(", ");
|
System.out.print(", ");
|
||||||
}
|
}
|
||||||
System.out.print(key.get() + " => " + mapout.get(key).get());
|
System.out.print(key + " => " + mapout.get(key));
|
||||||
}
|
}
|
||||||
System.out.print("}\n");
|
System.out.print("}\n");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SET TEST
|
* SET TEST
|
||||||
*/
|
*/
|
||||||
HashSet<Int32> setout = new HashSet<Int32>();
|
HashSet<Integer> setout = new HashSet<Integer>();
|
||||||
for (int i = -2; i < 3; ++i) {
|
for (int i = -2; i < 3; ++i) {
|
||||||
setout.add(new Int32(i));
|
setout.add(i);
|
||||||
}
|
}
|
||||||
System.out.print("testSet({");
|
System.out.print("testSet({");
|
||||||
first = true;
|
first = true;
|
||||||
for (Int32 elem : setout) {
|
for (int elem : setout) {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
System.out.print(", ");
|
System.out.print(", ");
|
||||||
}
|
}
|
||||||
System.out.print(elem.get());
|
System.out.print(elem);
|
||||||
}
|
}
|
||||||
System.out.print("})");
|
System.out.print("})");
|
||||||
HashSet<Int32> setin = testClient.testSet(setout);
|
HashSet<Integer> setin = testClient.testSet(setout);
|
||||||
System.out.print(" = {");
|
System.out.print(" = {");
|
||||||
first = true;
|
first = true;
|
||||||
for (Int32 elem : setin) {
|
for (int elem : setin) {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
System.out.print(", ");
|
System.out.print(", ");
|
||||||
}
|
}
|
||||||
System.out.print(elem.get());
|
System.out.print(elem);
|
||||||
}
|
}
|
||||||
System.out.print("}\n");
|
System.out.print("}\n");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LIST TEST
|
* LIST TEST
|
||||||
*/
|
*/
|
||||||
ArrayList<Int32> listout = new ArrayList<Int32>();
|
ArrayList<Integer> listout = new ArrayList<Integer>();
|
||||||
for (int i = -2; i < 3; ++i) {
|
for (int i = -2; i < 3; ++i) {
|
||||||
listout.add(new Int32(i));
|
listout.add(i);
|
||||||
}
|
}
|
||||||
System.out.print("testList({");
|
System.out.print("testList({");
|
||||||
first = true;
|
first = true;
|
||||||
for (Int32 elem : listout) {
|
for (int elem : listout) {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
System.out.print(", ");
|
System.out.print(", ");
|
||||||
}
|
}
|
||||||
System.out.print(elem.get());
|
System.out.print(elem);
|
||||||
}
|
}
|
||||||
System.out.print("})");
|
System.out.print("})");
|
||||||
ArrayList<Int32> listin = testClient.testList(listout);
|
ArrayList<Integer> listin = testClient.testList(listout);
|
||||||
System.out.print(" = {");
|
System.out.print(" = {");
|
||||||
first = true;
|
first = true;
|
||||||
for (Int32 elem : listin) {
|
for (int elem : listin) {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
System.out.print(", ");
|
System.out.print(", ");
|
||||||
}
|
}
|
||||||
System.out.print(elem.get());
|
System.out.print(elem);
|
||||||
}
|
}
|
||||||
System.out.print("}\n");
|
System.out.print("}\n");
|
||||||
|
|
||||||
@ -224,44 +224,44 @@ public class TestClient {
|
|||||||
* ENUM TEST
|
* ENUM TEST
|
||||||
*/
|
*/
|
||||||
System.out.print("testEnum(ONE)");
|
System.out.print("testEnum(ONE)");
|
||||||
Int32 ret = testClient.testEnum(Numberz.ONE);
|
int ret = testClient.testEnum(Numberz.ONE);
|
||||||
System.out.print(" = " + ret.get() + "\n");
|
System.out.print(" = " + ret + "\n");
|
||||||
|
|
||||||
System.out.print("testEnum(TWO)");
|
System.out.print("testEnum(TWO)");
|
||||||
ret = testClient.testEnum(Numberz.TWO);
|
ret = testClient.testEnum(Numberz.TWO);
|
||||||
System.out.print(" = " + ret.get() + "\n");
|
System.out.print(" = " + ret + "\n");
|
||||||
|
|
||||||
System.out.print("testEnum(THREE)");
|
System.out.print("testEnum(THREE)");
|
||||||
ret = testClient.testEnum(Numberz.THREE);
|
ret = testClient.testEnum(Numberz.THREE);
|
||||||
System.out.print(" = " + ret.get() + "\n");
|
System.out.print(" = " + ret + "\n");
|
||||||
|
|
||||||
System.out.print("testEnum(FIVE)");
|
System.out.print("testEnum(FIVE)");
|
||||||
ret = testClient.testEnum(Numberz.FIVE);
|
ret = testClient.testEnum(Numberz.FIVE);
|
||||||
System.out.print(" = " + ret.get() + "\n");
|
System.out.print(" = " + ret + "\n");
|
||||||
|
|
||||||
System.out.print("testEnum(EIGHT)");
|
System.out.print("testEnum(EIGHT)");
|
||||||
ret = testClient.testEnum(Numberz.EIGHT);
|
ret = testClient.testEnum(Numberz.EIGHT);
|
||||||
System.out.print(" = " + ret.get() + "\n");
|
System.out.print(" = " + ret + "\n");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TYPEDEF TEST
|
* TYPEDEF TEST
|
||||||
*/
|
*/
|
||||||
System.out.print("testTypedef(309858235082523)");
|
System.out.print("testTypedef(309858235082523)");
|
||||||
Int64 uid = testClient.testTypedef(new Int64(309858235082523L));
|
long uid = testClient.testTypedef(309858235082523L);
|
||||||
System.out.print(" = " + uid.get() + "\n");
|
System.out.print(" = " + uid + "\n");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NESTED MAP TEST
|
* NESTED MAP TEST
|
||||||
*/
|
*/
|
||||||
System.out.print("testMapMap(1)");
|
System.out.print("testMapMap(1)");
|
||||||
HashMap<Int32,HashMap<Int32,Int32>> mm =
|
HashMap<Integer,HashMap<Integer,Integer>> mm =
|
||||||
testClient.testMapMap(new Int32(1));
|
testClient.testMapMap(1);
|
||||||
System.out.print(" = {");
|
System.out.print(" = {");
|
||||||
for (Int32 key : mm.keySet()) {
|
for (int key : mm.keySet()) {
|
||||||
System.out.print(key.get() + " => {");
|
System.out.print(key + " => {");
|
||||||
HashMap<Int32,Int32> m2 = mm.get(key);
|
HashMap<Integer,Integer> m2 = mm.get(key);
|
||||||
for (Int32 k2 : m2.keySet()) {
|
for (int k2 : m2.keySet()) {
|
||||||
System.out.print(k2.get() + " => " + m2.get(k2).get() + ", ");
|
System.out.print(k2 + " => " + m2.get(k2) + ", ");
|
||||||
}
|
}
|
||||||
System.out.print("}, ");
|
System.out.print("}, ");
|
||||||
}
|
}
|
||||||
@ -271,29 +271,29 @@ public class TestClient {
|
|||||||
* INSANITY TEST
|
* INSANITY TEST
|
||||||
*/
|
*/
|
||||||
Insanity insane = new Insanity();
|
Insanity insane = new Insanity();
|
||||||
insane.userMap.put(Numberz.FIVE, new Int64(5000));
|
insane.userMap.put(Numberz.FIVE, (long)5000);
|
||||||
Xtruct truck = new Xtruct();
|
Xtruct truck = new Xtruct();
|
||||||
truck.string_thing.value = "Truck";
|
truck.string_thing = "Truck";
|
||||||
truck.byte_thing.set((short)8);
|
truck.byte_thing = (byte)8;
|
||||||
truck.i32_thing.set(8);
|
truck.i32_thing = 8;
|
||||||
truck.i64_thing.set(8);
|
truck.i64_thing = 8;
|
||||||
insane.xtructs.add(truck);
|
insane.xtructs.add(truck);
|
||||||
System.out.print("testInsanity()");
|
System.out.print("testInsanity()");
|
||||||
HashMap<Int64,HashMap<Int32,Insanity>> whoa =
|
HashMap<Long,HashMap<Integer,Insanity>> whoa =
|
||||||
testClient.testInsanity(insane);
|
testClient.testInsanity(insane);
|
||||||
System.out.print(" = {");
|
System.out.print(" = {");
|
||||||
for (Int64 key : whoa.keySet()) {
|
for (long key : whoa.keySet()) {
|
||||||
HashMap<Int32,Insanity> val = whoa.get(key);
|
HashMap<Integer,Insanity> val = whoa.get(key);
|
||||||
System.out.print(key.get() + " => {");
|
System.out.print(key + " => {");
|
||||||
|
|
||||||
for (Int32 k2 : val.keySet()) {
|
for (int k2 : val.keySet()) {
|
||||||
Insanity v2 = val.get(k2);
|
Insanity v2 = val.get(k2);
|
||||||
System.out.print(k2.get() + " => {");
|
System.out.print(k2 + " => {");
|
||||||
HashMap<Int32, Int64> userMap = v2.userMap;
|
HashMap<Integer, Long> userMap = v2.userMap;
|
||||||
System.out.print("{");
|
System.out.print("{");
|
||||||
for (Int32 k3 : userMap.keySet()) {
|
for (int k3 : userMap.keySet()) {
|
||||||
System.out.print(k3.get() + " => " +
|
System.out.print(k3 + " => " +
|
||||||
userMap.get(k3).get() + ", ");
|
userMap.get(k3) + ", ");
|
||||||
}
|
}
|
||||||
System.out.print("}, ");
|
System.out.print("}, ");
|
||||||
|
|
||||||
@ -301,10 +301,10 @@ public class TestClient {
|
|||||||
System.out.print("{");
|
System.out.print("{");
|
||||||
for (Xtruct x : xtructs) {
|
for (Xtruct x : xtructs) {
|
||||||
System.out.print("{" +
|
System.out.print("{" +
|
||||||
"\"" + x.string_thing.value + "\", " +
|
"\"" + x.string_thing + "\", " +
|
||||||
x.byte_thing.get() + ", " +
|
x.byte_thing + ", " +
|
||||||
x.i32_thing.get() + ", "+
|
x.i32_thing + ", "+
|
||||||
x.i64_thing.get() + "}, ");
|
x.i64_thing + "}, ");
|
||||||
}
|
}
|
||||||
System.out.print("}");
|
System.out.print("}");
|
||||||
|
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
package com.facebook.thrift.test;
|
package com.facebook.thrift.test;
|
||||||
|
|
||||||
import com.facebook.thrift.types.*;
|
import com.facebook.thrift.TException;
|
||||||
import com.facebook.thrift.protocol.TBinaryProtocol;
|
import com.facebook.thrift.protocol.TBinaryProtocol;
|
||||||
import com.facebook.thrift.protocol.TProtocol;
|
import com.facebook.thrift.protocol.TProtocol;
|
||||||
import com.facebook.thrift.protocol.TString;
|
|
||||||
import com.facebook.thrift.server.TServer;
|
import com.facebook.thrift.server.TServer;
|
||||||
import com.facebook.thrift.server.TSimpleServer;
|
import com.facebook.thrift.server.TSimpleServer;
|
||||||
import com.facebook.thrift.transport.TServerSocket;
|
import com.facebook.thrift.transport.TServerSocket;
|
||||||
import com.facebook.thrift.transport.TServerTransport;
|
import com.facebook.thrift.transport.TServerTransport;
|
||||||
|
|
||||||
import ThriftTest.*;
|
// Generated code
|
||||||
|
import thrift.test.*;
|
||||||
|
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
public class TestServer extends ThriftTestServerIf {
|
public class TestServer extends ThriftTest.Server {
|
||||||
public TestServer(TProtocol prot) {
|
public TestServer(TProtocol prot) {
|
||||||
super(prot);
|
super(prot);
|
||||||
}
|
}
|
||||||
@ -25,159 +25,199 @@ public class TestServer extends ThriftTestServerIf {
|
|||||||
System.out.print("testVoid()\n");
|
System.out.print("testVoid()\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
public TString testString(TString thing) {
|
public String testString(String thing) {
|
||||||
System.out.print("testString(\"" + thing.value + "\")\n");
|
System.out.print("testString(\"" + thing + "\")\n");
|
||||||
return thing;
|
return thing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UInt8 testByte(UInt8 thing) {
|
public byte testByte(byte thing) {
|
||||||
System.out.print("testByte(" + thing.get() + ")\n");
|
System.out.print("testByte(" + thing + ")\n");
|
||||||
return thing;
|
return thing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Int32 testI32(Int32 thing) {
|
public int testI32(int thing) {
|
||||||
System.out.print("testI32(" + thing.get() + ")\n");
|
System.out.print("testI32(" + thing + ")\n");
|
||||||
return thing;
|
return thing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Int64 testI64(Int64 thing) {
|
public long testI64(long thing) {
|
||||||
System.out.print("testI64(" + thing.get() + ")\n");
|
System.out.print("testI64(" + thing + ")\n");
|
||||||
return thing;
|
return thing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Xtruct testStruct(Xtruct thing) {
|
public Xtruct testStruct(Xtruct thing) {
|
||||||
System.out.print("testStruct({" +
|
System.out.print("testStruct({" +
|
||||||
"\"" + thing.string_thing.value + "\", " +
|
"\"" + thing.string_thing + "\", " +
|
||||||
thing.byte_thing.get() + ", " +
|
thing.byte_thing + ", " +
|
||||||
thing.i32_thing.get() + ", " +
|
thing.i32_thing + ", " +
|
||||||
thing.i64_thing.get() + "})\n");
|
thing.i64_thing + "})\n");
|
||||||
return thing;
|
return thing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Xtruct2 testNest(Xtruct2 nest) {
|
public Xtruct2 testNest(Xtruct2 nest) {
|
||||||
Xtruct thing = nest.struct_thing;
|
Xtruct thing = nest.struct_thing;
|
||||||
System.out.print("testNest({" +
|
System.out.print("testNest({" +
|
||||||
nest.byte_thing.get() + ", {" +
|
nest.byte_thing + ", {" +
|
||||||
"\"" + thing.string_thing.value + "\", " +
|
"\"" + thing.string_thing + "\", " +
|
||||||
thing.byte_thing.get() + ", " +
|
thing.byte_thing + ", " +
|
||||||
thing.i32_thing.get() + ", " +
|
thing.i32_thing + ", " +
|
||||||
thing.i64_thing.get() + "}, " +
|
thing.i64_thing + "}, " +
|
||||||
nest.i32_thing.get() + "})\n");
|
nest.i32_thing + "})\n");
|
||||||
return nest;
|
return nest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<Int32,Int32> testMap(HashMap<Int32,Int32> thing) {
|
public HashMap<Integer,Integer> testMap(HashMap<Integer,Integer> thing) {
|
||||||
System.out.print("testMap({");
|
System.out.print("testMap({");
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (Int32 key : thing.keySet()) {
|
for (int key : thing.keySet()) {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
System.out.print(", ");
|
System.out.print(", ");
|
||||||
}
|
}
|
||||||
System.out.print(key.get() + " => " + thing.get(key).get());
|
System.out.print(key + " => " + thing.get(key));
|
||||||
}
|
}
|
||||||
System.out.print("})\n");
|
System.out.print("})\n");
|
||||||
return thing;
|
return thing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashSet<Int32> testSet(HashSet<Int32> thing) {
|
public HashSet<Integer> testSet(HashSet<Integer> thing) {
|
||||||
System.out.print("testSet({");
|
System.out.print("testSet({");
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (Int32 elem : thing) {
|
for (int elem : thing) {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
System.out.print(", ");
|
System.out.print(", ");
|
||||||
}
|
}
|
||||||
System.out.print(elem.get());
|
System.out.print(elem);
|
||||||
}
|
}
|
||||||
System.out.print("})\n");
|
System.out.print("})\n");
|
||||||
return thing;
|
return thing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Int32> testList(ArrayList<Int32> thing) {
|
public ArrayList<Integer> testList(ArrayList<Integer> thing) {
|
||||||
System.out.print("testList({");
|
System.out.print("testList({");
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (Int32 elem : thing) {
|
for (int elem : thing) {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
System.out.print(", ");
|
System.out.print(", ");
|
||||||
}
|
}
|
||||||
System.out.print(elem.get());
|
System.out.print(elem);
|
||||||
}
|
}
|
||||||
System.out.print("})\n");
|
System.out.print("})\n");
|
||||||
return thing;
|
return thing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Int32 testEnum(Int32 thing) {
|
public int testEnum(int thing) {
|
||||||
System.out.print("testEnum(" + thing.get() + ")\n");
|
System.out.print("testEnum(" + thing + ")\n");
|
||||||
return thing;
|
return thing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Int64 testTypedef(Int64 thing) {
|
public long testTypedef(long thing) {
|
||||||
System.out.print("testTypedef(" + thing.get() + ")\n");
|
System.out.print("testTypedef(" + thing + ")\n");
|
||||||
return thing;
|
return thing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<Int32,HashMap<Int32,Int32>> testMapMap(Int32 hello) {
|
public HashMap<Integer,HashMap<Integer,Integer>> testMapMap(int hello) {
|
||||||
System.out.print("testMapMap(" + hello.get() + ")\n");
|
System.out.print("testMapMap(" + hello + ")\n");
|
||||||
HashMap<Int32,HashMap<Int32,Int32>> mapmap =
|
HashMap<Integer,HashMap<Integer,Integer>> mapmap =
|
||||||
new HashMap<Int32,HashMap<Int32,Int32>>();
|
new HashMap<Integer,HashMap<Integer,Integer>>();
|
||||||
|
|
||||||
HashMap<Int32,Int32> pos = new HashMap<Int32,Int32>();
|
HashMap<Integer,Integer> pos = new HashMap<Integer,Integer>();
|
||||||
HashMap<Int32,Int32> neg = new HashMap<Int32,Int32>();
|
HashMap<Integer,Integer> neg = new HashMap<Integer,Integer>();
|
||||||
for (int i = 1; i < 5; i++) {
|
for (int i = 1; i < 5; i++) {
|
||||||
pos.put(new Int32(i), new Int32(i));
|
pos.put(i, i);
|
||||||
neg.put(new Int32(-i), new Int32(-i));
|
neg.put(-i, -i);
|
||||||
}
|
}
|
||||||
|
|
||||||
mapmap.put(new Int32(4), pos);
|
mapmap.put(4, pos);
|
||||||
mapmap.put(new Int32(-4), neg);
|
mapmap.put(-4, neg);
|
||||||
|
|
||||||
return mapmap;
|
return mapmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<Int64, HashMap<Int32,Insanity>> testInsanity(Insanity argument) {
|
public HashMap<Long, HashMap<Integer,Insanity>> testInsanity(Insanity argument) {
|
||||||
System.out.print("testInsanity()\n");
|
System.out.print("testInsanity()\n");
|
||||||
|
|
||||||
Xtruct hello = new Xtruct();
|
Xtruct hello = new Xtruct();
|
||||||
hello.string_thing.value = "Hello2";
|
hello.string_thing = "Hello2";
|
||||||
hello.byte_thing.set((short)2);
|
hello.byte_thing = 2;
|
||||||
hello.i32_thing.set(2);
|
hello.i32_thing = 2;
|
||||||
hello.i64_thing.set(2);
|
hello.i64_thing = 2;
|
||||||
|
|
||||||
Xtruct goodbye = new Xtruct();
|
Xtruct goodbye = new Xtruct();
|
||||||
goodbye.string_thing.value = "Goodbye4";
|
goodbye.string_thing = "Goodbye4";
|
||||||
goodbye.byte_thing.set((short)4);
|
goodbye.byte_thing = (byte)4;
|
||||||
goodbye.i32_thing.set(4);
|
goodbye.i32_thing = 4;
|
||||||
goodbye.i64_thing.set(4);
|
goodbye.i64_thing = (long)4;
|
||||||
|
|
||||||
Insanity crazy = new Insanity();
|
Insanity crazy = new Insanity();
|
||||||
crazy.userMap.put(Numberz.EIGHT, new Int64(8));
|
crazy.userMap.put(Numberz.EIGHT, (long)8);
|
||||||
crazy.xtructs.add(goodbye);
|
crazy.xtructs.add(goodbye);
|
||||||
|
|
||||||
Insanity looney = new Insanity();
|
Insanity looney = new Insanity();
|
||||||
crazy.userMap.put(Numberz.FIVE, new Int64(5));
|
crazy.userMap.put(Numberz.FIVE, (long)5);
|
||||||
crazy.xtructs.add(hello);
|
crazy.xtructs.add(hello);
|
||||||
|
|
||||||
HashMap<Int32,Insanity> first_map = new HashMap<Int32, Insanity>();
|
HashMap<Integer,Insanity> first_map = new HashMap<Integer, Insanity>();
|
||||||
HashMap<Int32,Insanity> second_map = new HashMap<Int32, Insanity>();;
|
HashMap<Integer,Insanity> second_map = new HashMap<Integer, Insanity>();;
|
||||||
|
|
||||||
first_map.put(Numberz.TWO, crazy);
|
first_map.put(Numberz.TWO, crazy);
|
||||||
first_map.put(Numberz.THREE, crazy);
|
first_map.put(Numberz.THREE, crazy);
|
||||||
|
|
||||||
second_map.put(Numberz.SIX, looney);
|
second_map.put(Numberz.SIX, looney);
|
||||||
|
|
||||||
HashMap<Int64,HashMap<Int32,Insanity>> insane =
|
HashMap<Long,HashMap<Integer,Insanity>> insane =
|
||||||
new HashMap<Int64, HashMap<Int32,Insanity>>();
|
new HashMap<Long, HashMap<Integer,Insanity>>();
|
||||||
insane.put(new Int64(1), first_map);
|
insane.put((long)1, first_map);
|
||||||
insane.put(new Int64(2), second_map);
|
insane.put((long)2, second_map);
|
||||||
|
|
||||||
return insane;
|
return insane;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Xtruct testMulti(byte arg0, int arg1, long arg2, HashMap<Short,String> arg3, int arg4, long arg5) {
|
||||||
|
System.out.print("testMulti()\n");
|
||||||
|
|
||||||
|
Xtruct hello = new Xtruct();;
|
||||||
|
hello.string_thing = "Hello2";
|
||||||
|
hello.byte_thing = arg0;
|
||||||
|
hello.i32_thing = arg1;
|
||||||
|
hello.i64_thing = arg2;
|
||||||
|
return hello;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testException(String arg) throws Xception {
|
||||||
|
System.out.print("testException("+arg+")\n");
|
||||||
|
if (arg.equals("Xception")) {
|
||||||
|
Xception x = new Xception();
|
||||||
|
x.errorCode = 1001;
|
||||||
|
x.message = "This is an Xception";
|
||||||
|
throw x;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Xtruct testMultiException(String arg0, String arg1) throws Xception, Xception2 {
|
||||||
|
System.out.print("testMultiException(" + arg0 + ", " + arg1 + ")\n");
|
||||||
|
if (arg0.equals("Xception")) {
|
||||||
|
Xception x = new Xception();
|
||||||
|
x.errorCode = 1001;
|
||||||
|
x.message = "This is an Xception";
|
||||||
|
} else if (arg0.equals("Xception2")) {
|
||||||
|
Xception2 x = new Xception2();
|
||||||
|
x.errorCode = 2002;
|
||||||
|
x.struct_thing.string_thing = "This is an Xception2";
|
||||||
|
}
|
||||||
|
|
||||||
|
Xtruct result = new Xtruct();
|
||||||
|
result.string_thing = arg1;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void main(String [] args) {
|
public static void main(String [] args) {
|
||||||
try {
|
try {
|
||||||
int port = 9090;
|
int port = 9090;
|
||||||
|
Loading…
Reference in New Issue
Block a user