Upgrade linux protobuf

This commit is contained in:
John Colvin committed 2021-12-12 15:56:55 -05:00
1 parent 79f2f356d5
commit 0f3130fb47
689 files changed
+141922 -132057

No files matched your search

@@ -47,15 +47,16 @@ namespace compiler {
namespace java {
ServiceGenerator::ServiceGenerator(const ServiceDescriptor* descriptor)
: descriptor_(descriptor) {}
: descriptor_(descriptor) {}
ServiceGenerator::~ServiceGenerator() {}
// ===================================================================
ImmutableServiceGenerator::ImmutableServiceGenerator(
const ServiceDescriptor* descriptor, Context* context)
: ServiceGenerator(descriptor), context_(context),
name_resolver_(context->GetNameResolver()) {}
: ServiceGenerator(descriptor),
context_(context),
name_resolver_(context->GetNameResolver()) {}
ImmutableServiceGenerator::~ImmutableServiceGenerator() {}
@@ -65,15 +66,13 @@ void ImmutableServiceGenerator::Generate(io::Printer* printer) {
MaybePrintGeneratedAnnotation(context_, printer, descriptor_,
/* immutable = */ true);
printer->Print(
"public $static$ abstract class $classname$\n"
" implements com.google.protobuf.Service {\n",
"static", is_own_file ? "" : "static",
"classname", descriptor_->name());
"public $static$ abstract class $classname$\n"
" implements com.google.protobuf.Service {\n",
"static", is_own_file ? "" : "static", "classname", descriptor_->name());
printer->Indent();
printer->Print(
"protected $classname$() {}\n\n",
"classname", descriptor_->name());
printer->Print("protected $classname$() {}\n\n", "classname",
descriptor_->name());
GenerateInterface(printer);
@@ -84,13 +83,13 @@ void ImmutableServiceGenerator::Generate(io::Printer* printer) {
// Generate getDescriptor() and getDescriptorForType().
printer->Print(
"public static final\n"
" com.google.protobuf.Descriptors.ServiceDescriptor\n"
" getDescriptor() {\n"
" return $file$.getDescriptor().getServices().get($index$);\n"
"}\n",
"file", name_resolver_->GetImmutableClassName(descriptor_->file()),
"index", SimpleItoa(descriptor_->index()));
"public static final\n"
" com.google.protobuf.Descriptors.ServiceDescriptor\n"
" getDescriptor() {\n"
" return $file$.getDescriptor().getServices().get($index$);\n"
"}\n",
"file", name_resolver_->GetImmutableClassName(descriptor_->file()),
"index", StrCat(descriptor_->index()));
GenerateGetDescriptorForType(printer);
// Generate more stuff.
@@ -102,9 +101,9 @@ void ImmutableServiceGenerator::Generate(io::Printer* printer) {
// Add an insertion point.
printer->Print(
"\n"
"// @@protoc_insertion_point(class_scope:$full_name$)\n",
"full_name", descriptor_->full_name());
"\n"
"// @@protoc_insertion_point(class_scope:$full_name$)\n",
"full_name", descriptor_->full_name());
printer->Outdent();
printer->Print("}\n\n");
@@ -113,10 +112,10 @@ void ImmutableServiceGenerator::Generate(io::Printer* printer) {
void ImmutableServiceGenerator::GenerateGetDescriptorForType(
io::Printer* printer) {
printer->Print(
"public final com.google.protobuf.Descriptors.ServiceDescriptor\n"
" getDescriptorForType() {\n"
" return getDescriptor();\n"
"}\n");
"public final com.google.protobuf.Descriptors.ServiceDescriptor\n"
" getDescriptorForType() {\n"
" return getDescriptor();\n"
"}\n");
}
void ImmutableServiceGenerator::GenerateInterface(io::Printer* printer) {
@@ -130,10 +129,10 @@ void ImmutableServiceGenerator::GenerateInterface(io::Printer* printer) {
void ImmutableServiceGenerator::GenerateNewReflectiveServiceMethod(
io::Printer* printer) {
printer->Print(
"public static com.google.protobuf.Service newReflectiveService(\n"
" final Interface impl) {\n"
" return new $classname$() {\n",
"classname", descriptor_->name());
"public static com.google.protobuf.Service newReflectiveService(\n"
" final Interface impl) {\n"
" return new $classname$() {\n",
"classname", descriptor_->name());
printer->Indent();
printer->Indent();
@@ -142,10 +141,10 @@ void ImmutableServiceGenerator::GenerateNewReflectiveServiceMethod(
printer->Print("@java.lang.Override\n");
GenerateMethodSignature(printer, method, IS_CONCRETE);
printer->Print(
" {\n"
" impl.$method$(controller, request, done);\n"
"}\n\n",
"method", UnderscoresToCamelCase(method));
" {\n"
" impl.$method$(controller, request, done);\n"
"}\n\n",
"method", UnderscoresToCamelCase(method));
}
printer->Outdent();
@@ -157,9 +156,9 @@ void ImmutableServiceGenerator::GenerateNewReflectiveServiceMethod(
void ImmutableServiceGenerator::GenerateNewReflectiveBlockingServiceMethod(
io::Printer* printer) {
printer->Print(
"public static com.google.protobuf.BlockingService\n"
" newReflectiveBlockingService(final BlockingInterface impl) {\n"
" return new com.google.protobuf.BlockingService() {\n");
"public static com.google.protobuf.BlockingService\n"
" newReflectiveBlockingService(final BlockingInterface impl) {\n"
" return new com.google.protobuf.BlockingService() {\n");
printer->Indent();
printer->Indent();
@@ -184,167 +183,170 @@ void ImmutableServiceGenerator::GenerateAbstractMethods(io::Printer* printer) {
}
}
string ImmutableServiceGenerator::GetOutput(const MethodDescriptor* method) {
std::string ImmutableServiceGenerator::GetOutput(
const MethodDescriptor* method) {
return name_resolver_->GetImmutableClassName(method->output_type());
}
void ImmutableServiceGenerator::GenerateCallMethod(io::Printer* printer) {
printer->Print(
"\n"
"public final void callMethod(\n"
" com.google.protobuf.Descriptors.MethodDescriptor method,\n"
" com.google.protobuf.RpcController controller,\n"
" com.google.protobuf.Message request,\n"
" com.google.protobuf.RpcCallback<\n"
" com.google.protobuf.Message> done) {\n"
" if (method.getService() != getDescriptor()) {\n"
" throw new java.lang.IllegalArgumentException(\n"
" \"Service.callMethod() given method descriptor for wrong \" +\n"
" \"service type.\");\n"
" }\n"
" switch(method.getIndex()) {\n");
"\n"
"public final void callMethod(\n"
" com.google.protobuf.Descriptors.MethodDescriptor method,\n"
" com.google.protobuf.RpcController controller,\n"
" com.google.protobuf.Message request,\n"
" com.google.protobuf.RpcCallback<\n"
" com.google.protobuf.Message> done) {\n"
" if (method.getService() != getDescriptor()) {\n"
" throw new java.lang.IllegalArgumentException(\n"
" \"Service.callMethod() given method descriptor for wrong \" +\n"
" \"service type.\");\n"
" }\n"
" switch(method.getIndex()) {\n");
printer->Indent();
printer->Indent();
for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
std::map<string, string> vars;
vars["index"] = SimpleItoa(i);
std::map<std::string, std::string> vars;
vars["index"] = StrCat(i);
vars["method"] = UnderscoresToCamelCase(method);
vars["input"] = name_resolver_->GetImmutableClassName(
method->input_type());
vars["input"] = name_resolver_->GetImmutableClassName(method->input_type());
vars["output"] = GetOutput(method);
printer->Print(vars,
"case $index$:\n"
" this.$method$(controller, ($input$)request,\n"
" com.google.protobuf.RpcUtil.<$output$>specializeCallback(\n"
" done));\n"
" return;\n");
printer->Print(
vars,
"case $index$:\n"
" this.$method$(controller, ($input$)request,\n"
" com.google.protobuf.RpcUtil.<$output$>specializeCallback(\n"
" done));\n"
" return;\n");
}
printer->Print(
"default:\n"
" throw new java.lang.AssertionError(\"Can't get here.\");\n");
"default:\n"
" throw new java.lang.AssertionError(\"Can't get here.\");\n");
printer->Outdent();
printer->Outdent();
printer->Print(
" }\n"
"}\n"
"\n");
" }\n"
"}\n"
"\n");
}
void ImmutableServiceGenerator::GenerateCallBlockingMethod(
io::Printer* printer) {
printer->Print(
"\n"
"public final com.google.protobuf.Message callBlockingMethod(\n"
" com.google.protobuf.Descriptors.MethodDescriptor method,\n"
" com.google.protobuf.RpcController controller,\n"
" com.google.protobuf.Message request)\n"
" throws com.google.protobuf.ServiceException {\n"
" if (method.getService() != getDescriptor()) {\n"
" throw new java.lang.IllegalArgumentException(\n"
" \"Service.callBlockingMethod() given method descriptor for \" +\n"
" \"wrong service type.\");\n"
" }\n"
" switch(method.getIndex()) {\n");
"\n"
"public final com.google.protobuf.Message callBlockingMethod(\n"
" com.google.protobuf.Descriptors.MethodDescriptor method,\n"
" com.google.protobuf.RpcController controller,\n"
" com.google.protobuf.Message request)\n"
" throws com.google.protobuf.ServiceException {\n"
" if (method.getService() != getDescriptor()) {\n"
" throw new java.lang.IllegalArgumentException(\n"
" \"Service.callBlockingMethod() given method descriptor for \" +\n"
" \"wrong service type.\");\n"
" }\n"
" switch(method.getIndex()) {\n");
printer->Indent();
printer->Indent();
for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
std::map<string, string> vars;
vars["index"] = SimpleItoa(i);
std::map<std::string, std::string> vars;
vars["index"] = StrCat(i);
vars["method"] = UnderscoresToCamelCase(method);
vars["input"] = name_resolver_->GetImmutableClassName(
method->input_type());
vars["input"] = name_resolver_->GetImmutableClassName(method->input_type());
vars["output"] = GetOutput(method);
printer->Print(vars,
"case $index$:\n"
" return impl.$method$(controller, ($input$)request);\n");
"case $index$:\n"
" return impl.$method$(controller, ($input$)request);\n");
}
printer->Print(
"default:\n"
" throw new java.lang.AssertionError(\"Can't get here.\");\n");
"default:\n"
" throw new java.lang.AssertionError(\"Can't get here.\");\n");
printer->Outdent();
printer->Outdent();
printer->Print(
" }\n"
"}\n"
"\n");
" }\n"
"}\n"
"\n");
}
void ImmutableServiceGenerator::GenerateGetPrototype(RequestOrResponse which,
io::Printer* printer) {
io::Printer* printer) {
/*
* TODO(cpovirk): The exception message says "Service.foo" when it may be
* "BlockingService.foo." Consider fixing.
*/
printer->Print(
"public final com.google.protobuf.Message\n"
" get$request_or_response$Prototype(\n"
" com.google.protobuf.Descriptors.MethodDescriptor method) {\n"
" if (method.getService() != getDescriptor()) {\n"
" throw new java.lang.IllegalArgumentException(\n"
" \"Service.get$request_or_response$Prototype() given method \" +\n"
" \"descriptor for wrong service type.\");\n"
" }\n"
" switch(method.getIndex()) {\n",
"request_or_response", (which == REQUEST) ? "Request" : "Response");
"public final com.google.protobuf.Message\n"
" get$request_or_response$Prototype(\n"
" com.google.protobuf.Descriptors.MethodDescriptor method) {\n"
" if (method.getService() != getDescriptor()) {\n"
" throw new java.lang.IllegalArgumentException(\n"
" \"Service.get$request_or_response$Prototype() given method \" +\n"
" \"descriptor for wrong service type.\");\n"
" }\n"
" switch(method.getIndex()) {\n",
"request_or_response", (which == REQUEST) ? "Request" : "Response");
printer->Indent();
printer->Indent();
for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
std::map<string, string> vars;
vars["index"] = SimpleItoa(i);
vars["type"] = name_resolver_->GetImmutableClassName(
(which == REQUEST) ? method->input_type() : method->output_type());
std::map<std::string, std::string> vars;
vars["index"] = StrCat(i);
vars["type"] =
(which == REQUEST)
? name_resolver_->GetImmutableClassName(method->input_type())
: GetOutput(method);
printer->Print(vars,
"case $index$:\n"
" return $type$.getDefaultInstance();\n");
"case $index$:\n"
" return $type$.getDefaultInstance();\n");
}
printer->Print(
"default:\n"
" throw new java.lang.AssertionError(\"Can't get here.\");\n");
"default:\n"
" throw new java.lang.AssertionError(\"Can't get here.\");\n");
printer->Outdent();
printer->Outdent();
printer->Print(
" }\n"
"}\n"
"\n");
" }\n"
"}\n"
"\n");
}
void ImmutableServiceGenerator::GenerateStub(io::Printer* printer) {
printer->Print(
"public static Stub newStub(\n"
" com.google.protobuf.RpcChannel channel) {\n"
" return new Stub(channel);\n"
"}\n"
"\n"
"public static final class Stub extends $classname$ implements Interface {"
"\n",
"classname", name_resolver_->GetImmutableClassName(descriptor_));
"public static Stub newStub(\n"
" com.google.protobuf.RpcChannel channel) {\n"
" return new Stub(channel);\n"
"}\n"
"\n"
"public static final class Stub extends $classname$ implements Interface "
"{"
"\n",
"classname", name_resolver_->GetImmutableClassName(descriptor_));
printer->Indent();
printer->Print(
"private Stub(com.google.protobuf.RpcChannel channel) {\n"
" this.channel = channel;\n"
"}\n"
"\n"
"private final com.google.protobuf.RpcChannel channel;\n"
"\n"
"public com.google.protobuf.RpcChannel getChannel() {\n"
" return channel;\n"
"}\n");
"private Stub(com.google.protobuf.RpcChannel channel) {\n"
" this.channel = channel;\n"
"}\n"
"\n"
"private final com.google.protobuf.RpcChannel channel;\n"
"\n"
"public com.google.protobuf.RpcChannel getChannel() {\n"
" return channel;\n"
"}\n");
for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
@@ -353,19 +355,19 @@ void ImmutableServiceGenerator::GenerateStub(io::Printer* printer) {
printer->Print(" {\n");
printer->Indent();
std::map<string, string> vars;
vars["index"] = SimpleItoa(i);
std::map<std::string, std::string> vars;
vars["index"] = StrCat(i);
vars["output"] = GetOutput(method);
printer->Print(vars,
"channel.callMethod(\n"
" getDescriptor().getMethods().get($index$),\n"
" controller,\n"
" request,\n"
" $output$.getDefaultInstance(),\n"
" com.google.protobuf.RpcUtil.generalizeCallback(\n"
" done,\n"
" $output$.class,\n"
" $output$.getDefaultInstance()));\n");
"channel.callMethod(\n"
" getDescriptor().getMethods().get($index$),\n"
" controller,\n"
" request,\n"
" $output$.getDefaultInstance(),\n"
" com.google.protobuf.RpcUtil.generalizeCallback(\n"
" done,\n"
" $output$.class,\n"
" $output$.getDefaultInstance()));\n");
printer->Outdent();
printer->Print("}\n");
@@ -373,20 +375,19 @@ void ImmutableServiceGenerator::GenerateStub(io::Printer* printer) {
printer->Outdent();
printer->Print(
"}\n"
"\n");
"}\n"
"\n");
}
void ImmutableServiceGenerator::GenerateBlockingStub(io::Printer* printer) {
printer->Print(
"public static BlockingInterface newBlockingStub(\n"
" com.google.protobuf.BlockingRpcChannel channel) {\n"
" return new BlockingStub(channel);\n"
"}\n"
"\n");
"public static BlockingInterface newBlockingStub(\n"
" com.google.protobuf.BlockingRpcChannel channel) {\n"
" return new BlockingStub(channel);\n"
"}\n"
"\n");
printer->Print(
"public interface BlockingInterface {");
printer->Print("public interface BlockingInterface {");
printer->Indent();
for (int i = 0; i < descriptor_->method_count(); i++) {
@@ -397,19 +398,20 @@ void ImmutableServiceGenerator::GenerateBlockingStub(io::Printer* printer) {
printer->Outdent();
printer->Print(
"}\n"
"\n");
"}\n"
"\n");
printer->Print(
"private static final class BlockingStub implements BlockingInterface {\n");
"private static final class BlockingStub implements BlockingInterface "
"{\n");
printer->Indent();
printer->Print(
"private BlockingStub(com.google.protobuf.BlockingRpcChannel channel) {\n"
" this.channel = channel;\n"
"}\n"
"\n"
"private final com.google.protobuf.BlockingRpcChannel channel;\n");
"private BlockingStub(com.google.protobuf.BlockingRpcChannel channel) {\n"
" this.channel = channel;\n"
"}\n"
"\n"
"private final com.google.protobuf.BlockingRpcChannel channel;\n");
for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
@@ -417,54 +419,53 @@ void ImmutableServiceGenerator::GenerateBlockingStub(io::Printer* printer) {
printer->Print(" {\n");
printer->Indent();
std::map<string, string> vars;
vars["index"] = SimpleItoa(i);
std::map<std::string, std::string> vars;
vars["index"] = StrCat(i);
vars["output"] = GetOutput(method);
printer->Print(vars,
"return ($output$) channel.callBlockingMethod(\n"
" getDescriptor().getMethods().get($index$),\n"
" controller,\n"
" request,\n"
" $output$.getDefaultInstance());\n");
"return ($output$) channel.callBlockingMethod(\n"
" getDescriptor().getMethods().get($index$),\n"
" controller,\n"
" request,\n"
" $output$.getDefaultInstance());\n");
printer->Outdent();
printer->Print(
"}\n"
"\n");
"}\n"
"\n");
}
printer->Outdent();
printer->Print("}\n");
}
void ImmutableServiceGenerator::GenerateMethodSignature(io::Printer* printer,
const MethodDescriptor* method,
IsAbstract is_abstract) {
std::map<string, string> vars;
void ImmutableServiceGenerator::GenerateMethodSignature(
io::Printer* printer, const MethodDescriptor* method,
IsAbstract is_abstract) {
std::map<std::string, std::string> vars;
vars["name"] = UnderscoresToCamelCase(method);
vars["input"] = name_resolver_->GetImmutableClassName(method->input_type());
vars["output"] = GetOutput(method);
vars["abstract"] = (is_abstract == IS_ABSTRACT) ? "abstract" : "";
printer->Print(vars,
"public $abstract$ void $name$(\n"
" com.google.protobuf.RpcController controller,\n"
" $input$ request,\n"
" com.google.protobuf.RpcCallback<$output$> done)");
"public $abstract$ void $name$(\n"
" com.google.protobuf.RpcController controller,\n"
" $input$ request,\n"
" com.google.protobuf.RpcCallback<$output$> done)");
}
void ImmutableServiceGenerator::GenerateBlockingMethodSignature(
io::Printer* printer,
const MethodDescriptor* method) {
std::map<string, string> vars;
io::Printer* printer, const MethodDescriptor* method) {
std::map<std::string, std::string> vars;
vars["method"] = UnderscoresToCamelCase(method);
vars["input"] = name_resolver_->GetImmutableClassName(method->input_type());
vars["output"] = GetOutput(method);
printer->Print(vars,
"\n"
"public $output$ $method$(\n"
" com.google.protobuf.RpcController controller,\n"
" $input$ request)\n"
" throws com.google.protobuf.ServiceException");
"\n"
"public $output$ $method$(\n"
" com.google.protobuf.RpcController controller,\n"
" $input$ request)\n"
" throws com.google.protobuf.ServiceException");
}
} // namespace java