|
|
@ -237,54 +237,70 @@ bool PrintServerFactory(const ServiceDescriptor* service, Printer* out) { |
|
|
|
"Service", service->name()); |
|
|
|
"Service", service->name()); |
|
|
|
{ |
|
|
|
{ |
|
|
|
IndentScope raii_create_server_indent(out); |
|
|
|
IndentScope raii_create_server_indent(out); |
|
|
|
map<string, pair<string, string>> method_to_module_and_message; |
|
|
|
map<string, string> method_description_constructors; |
|
|
|
out->Print("method_implementations = {\n"); |
|
|
|
map<string, pair<string, string>> input_message_modules_and_classes; |
|
|
|
|
|
|
|
map<string, pair<string, string>> output_message_modules_and_classes; |
|
|
|
for (int i = 0; i < service->method_count(); ++i) { |
|
|
|
for (int i = 0; i < service->method_count(); ++i) { |
|
|
|
IndentScope raii_implementations_indent(out); |
|
|
|
const MethodDescriptor* method = service->method(i); |
|
|
|
const MethodDescriptor* meth = service->method(i); |
|
|
|
const string method_description_constructor = |
|
|
|
string meth_type = |
|
|
|
string(method->client_streaming() ? "stream_" : "unary_") + |
|
|
|
string(meth->client_streaming() ? "stream" : "unary") + |
|
|
|
string(method->server_streaming() ? "stream_" : "unary_") + |
|
|
|
string(meth->server_streaming() ? "_stream" : "_unary") + "_inline"; |
|
|
|
"service_description"; |
|
|
|
out->Print("\"$Method$\": utilities.$Type$(servicer.$Method$),\n", |
|
|
|
pair<string, string> input_message_module_and_class; |
|
|
|
"Method", meth->name(), |
|
|
|
if (!GetModuleAndMessagePath(method->input_type(), |
|
|
|
"Type", meth_type); |
|
|
|
&input_message_module_and_class)) { |
|
|
|
// Maintain information on the input type of the service method for later
|
|
|
|
|
|
|
|
// use in constructing the service assembly's activated fore link.
|
|
|
|
|
|
|
|
const Descriptor* input_type = meth->input_type(); |
|
|
|
|
|
|
|
pair<string, string> module_and_message; |
|
|
|
|
|
|
|
if (!GetModuleAndMessagePath(input_type, &module_and_message)) { |
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
method_to_module_and_message.insert( |
|
|
|
pair<string, string> output_message_module_and_class; |
|
|
|
make_pair(meth->name(), module_and_message)); |
|
|
|
if (!GetModuleAndMessagePath(method->output_type(), |
|
|
|
} |
|
|
|
&output_message_module_and_class)) { |
|
|
|
out->Print("}\n"); |
|
|
|
return false; |
|
|
|
// Ensure that we've imported all of the relevant messages.
|
|
|
|
} |
|
|
|
for (auto& meth_vals : method_to_module_and_message) { |
|
|
|
// Import the modules that define the messages used in RPCs.
|
|
|
|
out->Print("import $Module$\n", |
|
|
|
out->Print("import $Module$\n", "Module", |
|
|
|
"Module", meth_vals.second.first); |
|
|
|
input_message_module_and_class.first); |
|
|
|
} |
|
|
|
out->Print("import $Module$\n", "Module", |
|
|
|
out->Print("request_deserializers = {\n"); |
|
|
|
output_message_module_and_class.first); |
|
|
|
for (auto& meth_vals : method_to_module_and_message) { |
|
|
|
method_description_constructors.insert( |
|
|
|
IndentScope raii_serializers_indent(out); |
|
|
|
make_pair(method->name(), method_description_constructor)); |
|
|
|
string full_input_type_path = meth_vals.second.first + "." + |
|
|
|
input_message_modules_and_classes.insert( |
|
|
|
meth_vals.second.second; |
|
|
|
make_pair(method->name(), input_message_module_and_class)); |
|
|
|
out->Print("\"$Method$\": $Type$.FromString,\n", |
|
|
|
output_message_modules_and_classes.insert( |
|
|
|
"Method", meth_vals.first, |
|
|
|
make_pair(method->name(), output_message_module_and_class)); |
|
|
|
"Type", full_input_type_path); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
out->Print("}\n"); |
|
|
|
out->Print("method_service_descriptions = {\n"); |
|
|
|
out->Print("response_serializers = {\n"); |
|
|
|
for (auto& name_and_description_constructor : |
|
|
|
for (auto& meth_vals : method_to_module_and_message) { |
|
|
|
method_description_constructors) { |
|
|
|
IndentScope raii_serializers_indent(out); |
|
|
|
IndentScope raii_descriptions_indent(out); |
|
|
|
out->Print("\"$Method$\": lambda x: x.SerializeToString(),\n", |
|
|
|
const string method_name = name_and_description_constructor.first; |
|
|
|
"Method", meth_vals.first); |
|
|
|
auto input_message_module_and_class = |
|
|
|
|
|
|
|
input_message_modules_and_classes.find(method_name); |
|
|
|
|
|
|
|
auto output_message_module_and_class = |
|
|
|
|
|
|
|
output_message_modules_and_classes.find(method_name); |
|
|
|
|
|
|
|
out->Print("\"$Method$\": utilities.$Constructor$(\n", "Method", |
|
|
|
|
|
|
|
method_name, "Constructor", |
|
|
|
|
|
|
|
name_and_description_constructor.second); |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
IndentScope raii_description_arguments_indent(out); |
|
|
|
|
|
|
|
out->Print("servicer.$Method$,\n", "Method", method_name); |
|
|
|
|
|
|
|
out->Print( |
|
|
|
|
|
|
|
"$InputTypeModule$.$InputTypeClass$.FromString,\n", |
|
|
|
|
|
|
|
"InputTypeModule", input_message_module_and_class->second.first, |
|
|
|
|
|
|
|
"InputTypeClass", input_message_module_and_class->second.second); |
|
|
|
|
|
|
|
out->Print( |
|
|
|
|
|
|
|
"$OutputTypeModule$.$OutputTypeClass$.SerializeToString,\n", |
|
|
|
|
|
|
|
"OutputTypeModule", output_message_module_and_class->second.first, |
|
|
|
|
|
|
|
"OutputTypeClass", output_message_module_and_class->second.second); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
out->Print("),\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
out->Print("}\n"); |
|
|
|
out->Print("}\n"); |
|
|
|
out->Print("link = fore.activated_fore_link(port, request_deserializers, " |
|
|
|
// out->Print("return implementations.insecure_server("
|
|
|
|
"response_serializers, root_certificates, key_chain_pairs)\n"); |
|
|
|
// "method_service_descriptions, port)\n");
|
|
|
|
out->Print("return implementations.assemble_service(" |
|
|
|
out->Print( |
|
|
|
"method_implementations, link)\n"); |
|
|
|
"return implementations.secure_server(" |
|
|
|
|
|
|
|
"method_service_descriptions, port, root_certificates," |
|
|
|
|
|
|
|
" key_chain_pairs)\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
@ -296,66 +312,74 @@ bool PrintStubFactory(const ServiceDescriptor* service, Printer* out) { |
|
|
|
out->Print(dict, "def early_adopter_create_$Service$_stub(host, port):\n"); |
|
|
|
out->Print(dict, "def early_adopter_create_$Service$_stub(host, port):\n"); |
|
|
|
{ |
|
|
|
{ |
|
|
|
IndentScope raii_create_server_indent(out); |
|
|
|
IndentScope raii_create_server_indent(out); |
|
|
|
map<string, pair<string, string>> method_to_module_and_message; |
|
|
|
map<string, string> method_description_constructors; |
|
|
|
out->Print("method_implementations = {\n"); |
|
|
|
map<string, pair<string, string>> input_message_modules_and_classes; |
|
|
|
|
|
|
|
map<string, pair<string, string>> output_message_modules_and_classes; |
|
|
|
for (int i = 0; i < service->method_count(); ++i) { |
|
|
|
for (int i = 0; i < service->method_count(); ++i) { |
|
|
|
IndentScope raii_implementations_indent(out); |
|
|
|
const MethodDescriptor* method = service->method(i); |
|
|
|
const MethodDescriptor* meth = service->method(i); |
|
|
|
const string method_description_constructor = |
|
|
|
string meth_type = |
|
|
|
string(method->client_streaming() ? "stream_" : "unary_") + |
|
|
|
string(meth->client_streaming() ? "stream" : "unary") + |
|
|
|
string(method->server_streaming() ? "stream_" : "unary_") + |
|
|
|
string(meth->server_streaming() ? "_stream" : "_unary") + "_inline"; |
|
|
|
"invocation_description"; |
|
|
|
// TODO(atash): once the expected input to assemble_dynamic_inline_stub is
|
|
|
|
pair<string, string> input_message_module_and_class; |
|
|
|
// cleaned up, change this to the expected argument's dictionary values.
|
|
|
|
if (!GetModuleAndMessagePath(method->input_type(), |
|
|
|
out->Print("\"$Method$\": utilities.$Type$(None),\n", |
|
|
|
&input_message_module_and_class)) { |
|
|
|
"Method", meth->name(), |
|
|
|
|
|
|
|
"Type", meth_type); |
|
|
|
|
|
|
|
// Maintain information on the input type of the service method for later
|
|
|
|
|
|
|
|
// use in constructing the service assembly's activated fore link.
|
|
|
|
|
|
|
|
const Descriptor* output_type = meth->output_type(); |
|
|
|
|
|
|
|
pair<string, string> module_and_message; |
|
|
|
|
|
|
|
if (!GetModuleAndMessagePath(output_type, &module_and_message)) { |
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
method_to_module_and_message.insert( |
|
|
|
pair<string, string> output_message_module_and_class; |
|
|
|
make_pair(meth->name(), module_and_message)); |
|
|
|
if (!GetModuleAndMessagePath(method->output_type(), |
|
|
|
} |
|
|
|
&output_message_module_and_class)) { |
|
|
|
out->Print("}\n"); |
|
|
|
return false; |
|
|
|
// Ensure that we've imported all of the relevant messages.
|
|
|
|
} |
|
|
|
for (auto& meth_vals : method_to_module_and_message) { |
|
|
|
// Import the modules that define the messages used in RPCs.
|
|
|
|
out->Print("import $Module$\n", |
|
|
|
out->Print("import $Module$\n", "Module", |
|
|
|
"Module", meth_vals.second.first); |
|
|
|
input_message_module_and_class.first); |
|
|
|
} |
|
|
|
out->Print("import $Module$\n", "Module", |
|
|
|
out->Print("response_deserializers = {\n"); |
|
|
|
output_message_module_and_class.first); |
|
|
|
for (auto& meth_vals : method_to_module_and_message) { |
|
|
|
method_description_constructors.insert( |
|
|
|
IndentScope raii_serializers_indent(out); |
|
|
|
make_pair(method->name(), method_description_constructor)); |
|
|
|
string full_output_type_path = meth_vals.second.first + "." + |
|
|
|
input_message_modules_and_classes.insert( |
|
|
|
meth_vals.second.second; |
|
|
|
make_pair(method->name(), input_message_module_and_class)); |
|
|
|
out->Print("\"$Method$\": $Type$.FromString,\n", |
|
|
|
output_message_modules_and_classes.insert( |
|
|
|
"Method", meth_vals.first, |
|
|
|
make_pair(method->name(), output_message_module_and_class)); |
|
|
|
"Type", full_output_type_path); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
out->Print("}\n"); |
|
|
|
out->Print("method_invocation_descriptions = {\n"); |
|
|
|
out->Print("request_serializers = {\n"); |
|
|
|
for (auto& name_and_description_constructor : |
|
|
|
for (auto& meth_vals : method_to_module_and_message) { |
|
|
|
method_description_constructors) { |
|
|
|
IndentScope raii_serializers_indent(out); |
|
|
|
IndentScope raii_descriptions_indent(out); |
|
|
|
out->Print("\"$Method$\": lambda x: x.SerializeToString(),\n", |
|
|
|
const string method_name = name_and_description_constructor.first; |
|
|
|
"Method", meth_vals.first); |
|
|
|
auto input_message_module_and_class = |
|
|
|
|
|
|
|
input_message_modules_and_classes.find(method_name); |
|
|
|
|
|
|
|
auto output_message_module_and_class = |
|
|
|
|
|
|
|
output_message_modules_and_classes.find(method_name); |
|
|
|
|
|
|
|
out->Print("\"$Method$\": utilities.$Constructor$(\n", "Method", |
|
|
|
|
|
|
|
method_name, "Constructor", |
|
|
|
|
|
|
|
name_and_description_constructor.second); |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
IndentScope raii_description_arguments_indent(out); |
|
|
|
|
|
|
|
out->Print( |
|
|
|
|
|
|
|
"$InputTypeModule$.$InputTypeClass$.SerializeToString,\n", |
|
|
|
|
|
|
|
"InputTypeModule", input_message_module_and_class->second.first, |
|
|
|
|
|
|
|
"InputTypeClass", input_message_module_and_class->second.second); |
|
|
|
|
|
|
|
out->Print( |
|
|
|
|
|
|
|
"$OutputTypeModule$.$OutputTypeClass$.FromString,\n", |
|
|
|
|
|
|
|
"OutputTypeModule", output_message_module_and_class->second.first, |
|
|
|
|
|
|
|
"OutputTypeClass", output_message_module_and_class->second.second); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
out->Print("),\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
out->Print("}\n"); |
|
|
|
out->Print("}\n"); |
|
|
|
out->Print("link = rear.activated_rear_link(" |
|
|
|
out->Print( |
|
|
|
"host, port, request_serializers, response_deserializers)\n"); |
|
|
|
"return implementations.insecure_stub(" |
|
|
|
out->Print("return implementations.assemble_dynamic_inline_stub(" |
|
|
|
"method_invocation_descriptions, host, port)\n"); |
|
|
|
"method_implementations, link)\n"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool PrintPreamble(const FileDescriptor* file, Printer* out) { |
|
|
|
bool PrintPreamble(const FileDescriptor* file, Printer* out) { |
|
|
|
out->Print("import abc\n"); |
|
|
|
out->Print("import abc\n"); |
|
|
|
out->Print("from grpc._adapter import fore\n"); |
|
|
|
out->Print("from grpc.early_adopter import implementations\n"); |
|
|
|
out->Print("from grpc._adapter import rear\n"); |
|
|
|
out->Print("from grpc.early_adopter import utilities\n"); |
|
|
|
out->Print("from grpc.framework.assembly import implementations\n"); |
|
|
|
|
|
|
|
out->Print("from grpc.framework.assembly import utilities\n"); |
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|