Merge pull request #7721 from murgatroid99/node_codegen_nested_message_backport

Make Node code generator work properly with nested types
pull/7671/head
Nicolas Noble 8 years ago committed by GitHub
commit c5b7347302
  1. 34
      src/compiler/node_generator.cc

@ -103,16 +103,19 @@ grpc::string GetRelativePath(const grpc::string& from_file,
/* Finds all message types used in all services in the file, and returns them /* Finds all message types used in all services in the file, and returns them
* as a map of fully qualified message type name to message descriptor */ * as a map of fully qualified message type name to message descriptor */
map<grpc::string, const Descriptor*> GetAllMessages(const FileDescriptor *file) { map<grpc::string, const Descriptor *> GetAllMessages(
map<grpc::string, const Descriptor*> message_types; const FileDescriptor *file) {
for (int service_num = 0; service_num < file->service_count(); service_num++) { map<grpc::string, const Descriptor *> message_types;
const ServiceDescriptor* service = file->service(service_num); for (int service_num = 0; service_num < file->service_count();
for (int method_num = 0; method_num < service->method_count(); method_num++) { service_num++) {
const MethodDescriptor* method = service->method(method_num); const ServiceDescriptor *service = file->service(service_num);
const Descriptor* input_type = method->input_type(); for (int method_num = 0; method_num < service->method_count();
const Descriptor* output_type = method->output_type(); method_num++) {
message_types[input_type->name()] = input_type; const MethodDescriptor *method = service->method(method_num);
message_types[output_type->name()] = output_type; const Descriptor *input_type = method->input_type();
const Descriptor *output_type = method->output_type();
message_types[input_type->full_name()] = input_type;
message_types[output_type->full_name()] = output_type;
} }
} }
return message_types; return message_types;
@ -124,7 +127,7 @@ grpc::string MessageIdentifierName(const grpc::string& name) {
grpc::string NodeObjectPath(const Descriptor *descriptor) { grpc::string NodeObjectPath(const Descriptor *descriptor) {
grpc::string module_alias = ModuleAlias(descriptor->file()->name()); grpc::string module_alias = ModuleAlias(descriptor->file()->name());
grpc::string name = descriptor->name(); grpc::string name = descriptor->full_name();
grpc_generator::StripPrefix(&name, descriptor->file()->package() + "."); grpc_generator::StripPrefix(&name, descriptor->file()->package() + ".");
return module_alias + "." + name; return module_alias + "." + name;
} }
@ -132,8 +135,9 @@ grpc::string NodeObjectPath(const Descriptor *descriptor) {
// Prints out the message serializer and deserializer functions // Prints out the message serializer and deserializer functions
void PrintMessageTransformer(const Descriptor *descriptor, Printer *out) { void PrintMessageTransformer(const Descriptor *descriptor, Printer *out) {
map<grpc::string, grpc::string> template_vars; map<grpc::string, grpc::string> template_vars;
template_vars["identifier_name"] = MessageIdentifierName(descriptor->name()); grpc::string full_name = descriptor->full_name();
template_vars["name"] = descriptor->name(); template_vars["identifier_name"] = MessageIdentifierName(full_name);
template_vars["name"] = full_name;
template_vars["node_name"] = NodeObjectPath(descriptor); template_vars["node_name"] = NodeObjectPath(descriptor);
// Print the serializer // Print the serializer
out->Print(template_vars, "function serialize_$identifier_name$(arg) {\n"); out->Print(template_vars, "function serialize_$identifier_name$(arg) {\n");
@ -166,9 +170,9 @@ void PrintMethod(const MethodDescriptor *method, Printer *out) {
vars["service_name"] = method->service()->full_name(); vars["service_name"] = method->service()->full_name();
vars["name"] = method->name(); vars["name"] = method->name();
vars["input_type"] = NodeObjectPath(input_type); vars["input_type"] = NodeObjectPath(input_type);
vars["input_type_id"] = MessageIdentifierName(input_type->name()); vars["input_type_id"] = MessageIdentifierName(input_type->full_name());
vars["output_type"] = NodeObjectPath(output_type); vars["output_type"] = NodeObjectPath(output_type);
vars["output_type_id"] = MessageIdentifierName(output_type->name()); vars["output_type_id"] = MessageIdentifierName(output_type->full_name());
vars["client_stream"] = method->client_streaming() ? "true" : "false"; vars["client_stream"] = method->client_streaming() ? "true" : "false";
vars["server_stream"] = method->server_streaming() ? "true" : "false"; vars["server_stream"] = method->server_streaming() ? "true" : "false";
out->Print("{\n"); out->Print("{\n");

Loading…
Cancel
Save