From 50b08eee3bb52199cdf4dd7246f95323db699195 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Wed, 22 May 2019 08:49:07 -0700 Subject: [PATCH] Delete protobuf-nano Nano was dropped from upstream protobuf. See gRFC L51 --- .gitattributes | 2 - RELEASING.md | 6 +- all/build.gradle | 1 - build.gradle | 5 - compiler/README.md | 5 - compiler/build.gradle | 32 +- .../src/java_plugin/cpp/java_generator.cpp | 288 ++------ compiler/src/java_plugin/cpp/java_generator.h | 4 +- compiler/src/java_plugin/cpp/java_plugin.cpp | 7 +- .../golden/TestDeprecatedService.java.txt | 305 -------- .../src/testNano/golden/TestService.java.txt | 664 ------------------ protobuf-nano/BUILD.bazel | 14 - protobuf-nano/build.gradle | 43 -- .../protobuf/nano/MessageNanoFactory.java | 30 - .../protobuf/nano/NanoProtoInputStream.java | 95 --- .../java/io/grpc/protobuf/nano/NanoUtils.java | 100 --- .../io/grpc/protobuf/nano/package-info.java | 21 - .../io/grpc/protobuf/nano/NanoUtilsTest.java | 116 --- .../proto/grpc/testing/nano/messages.proto | 26 - repositories.bzl | 12 - settings.gradle | 2 - 21 files changed, 74 insertions(+), 1704 deletions(-) delete mode 100644 compiler/src/testNano/golden/TestDeprecatedService.java.txt delete mode 100644 compiler/src/testNano/golden/TestService.java.txt delete mode 100644 protobuf-nano/BUILD.bazel delete mode 100644 protobuf-nano/build.gradle delete mode 100644 protobuf-nano/src/main/java/io/grpc/protobuf/nano/MessageNanoFactory.java delete mode 100644 protobuf-nano/src/main/java/io/grpc/protobuf/nano/NanoProtoInputStream.java delete mode 100644 protobuf-nano/src/main/java/io/grpc/protobuf/nano/NanoUtils.java delete mode 100644 protobuf-nano/src/main/java/io/grpc/protobuf/nano/package-info.java delete mode 100644 protobuf-nano/src/test/java/io/grpc/protobuf/nano/NanoUtilsTest.java delete mode 100644 protobuf-nano/src/test/proto/grpc/testing/nano/messages.proto diff --git a/.gitattributes b/.gitattributes index d7df7b3f22..6d0661ec5a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,4 @@ TestService.java.txt binary TestServiceLite.java.txt binary -TestServiceNano.java.txt binary TestDeprecatedService.java.txt binary TestDeprecatedServiceLite.java.txt binary -TestDeprecatedServiceNano.java.txt binary diff --git a/RELEASING.md b/RELEASING.md index f72fba0cfe..0473f4a3b7 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -70,7 +70,7 @@ would be used to create all `v1.7` tags (e.g. `v1.7.0`, `v1.7.1`). $ sed -i 's/[0-9]\+\.[0-9]\+\.[0-9]\+\(.*CURRENT_GRPC_VERSION\)/'$MAJOR.$((MINOR+1)).0'\1/' \ "${VERSION_FILES[@]}" $ sed -i s/$MAJOR.$MINOR.$PATCH/$MAJOR.$((MINOR+1)).0/ \ - compiler/src/test{,Lite,Nano}/golden/Test{,Deprecated}Service.java.txt + compiler/src/test{,Lite}/golden/Test{,Deprecated}Service.java.txt $ ./gradlew build $ git commit -a -m "Start $MAJOR.$((MINOR+1)).0 development cycle" ``` @@ -126,7 +126,7 @@ Tagging the Release ```bash # Change version to remove -SNAPSHOT $ sed -i 's/-SNAPSHOT\(.*CURRENT_GRPC_VERSION\)/\1/' "${VERSION_FILES[@]}" - $ sed -i s/-SNAPSHOT// compiler/src/test{,Lite,Nano}/golden/Test{,Deprecated}Service.java.txt + $ sed -i s/-SNAPSHOT// compiler/src/test{,Lite}/golden/Test{,Deprecated}Service.java.txt $ ./gradlew build $ git commit -a -m "Bump version to $MAJOR.$MINOR.$PATCH" $ git tag -a v$MAJOR.$MINOR.$PATCH -m "Version $MAJOR.$MINOR.$PATCH" @@ -139,7 +139,7 @@ Tagging the Release $ sed -i 's/[0-9]\+\.[0-9]\+\.[0-9]\+\(.*CURRENT_GRPC_VERSION\)/'$MAJOR.$MINOR.$((PATCH+1))-SNAPSHOT'\1/' \ "${VERSION_FILES[@]}" $ sed -i s/$MAJOR.$MINOR.$PATCH/$MAJOR.$MINOR.$((PATCH+1))-SNAPSHOT/ \ - compiler/src/test{,Lite,Nano}/golden/Test{,Deprecated}Service.java.txt + compiler/src/test{,Lite}/golden/Test{,Deprecated}Service.java.txt $ ./gradlew build $ git commit -a -m "Bump version to $MAJOR.$MINOR.$((PATCH+1))-SNAPSHOT" ``` diff --git a/all/build.gradle b/all/build.gradle index 85586b0e50..65e139bfba 100644 --- a/all/build.gradle +++ b/all/build.gradle @@ -19,7 +19,6 @@ def subprojects = [ project(':grpc-okhttp'), project(':grpc-protobuf'), project(':grpc-protobuf-lite'), - project(':grpc-protobuf-nano'), project(':grpc-stub'), project(':grpc-testing'), ] diff --git a/build.gradle b/build.gradle index 2ccdff1c8d..6e2a39b5cf 100644 --- a/build.gradle +++ b/build.gradle @@ -111,7 +111,6 @@ subprojects { guavaVersion = '26.0-android' protobufVersion = '3.7.1' protocVersion = protobufVersion - protobufNanoVersion = '3.0.0-alpha-5' opencensusVersion = '0.21.0' configureProtoCompilation = { @@ -210,8 +209,6 @@ subprojects { protobuf: "com.google.protobuf:protobuf-java:${protobufVersion}", protobuf_lite: "com.google.protobuf:protobuf-lite:3.0.1", protoc_lite: "com.google.protobuf:protoc-gen-javalite:3.0.0", - protobuf_nano: "com.google.protobuf.nano:protobuf-javanano:${protobufNanoVersion}", - protoc_nano: "com.google.protobuf:protoc:3.5.1-1", protobuf_plugin: 'com.google.protobuf:protobuf-gradle-plugin:0.8.8', protobuf_util: "com.google.protobuf:protobuf-java-util:${protobufVersion}", lang: "org.apache.commons:commons-lang3:3.5", @@ -386,7 +383,6 @@ subprojects { "grpc-stub", "grpc-protobuf", "grpc-protobuf-lite", - "grpc-protobuf-nano" ])) { asNode().dependencies.'*'.findAll() { dep -> dep.artifactId.text() in ['grpc-api', 'grpc-core'] @@ -461,7 +457,6 @@ def publicApiSubprojects = [ ':grpc-okhttp', ':grpc-protobuf', ':grpc-protobuf-lite', - ':grpc-protobuf-nano', ':grpc-stub', ':grpc-testing', ] diff --git a/compiler/README.md b/compiler/README.md index fc87b2d026..676b0cbf4d 100644 --- a/compiler/README.md +++ b/compiler/README.md @@ -42,11 +42,6 @@ To generate Java interfaces with protobuf lite: $ protoc --plugin=protoc-gen-grpc-java=build/exe/java_plugin/protoc-gen-grpc-java \ --grpc-java_out=lite:"$OUTPUT_FILE" --proto_path="$DIR_OF_PROTO_FILE" "$PROTO_FILE" ``` -To generate Java interfaces with protobuf nano: -``` -$ protoc --plugin=protoc-gen-grpc-java=build/exe/java_plugin/protoc-gen-grpc-java \ - --grpc-java_out=nano:"$OUTPUT_FILE" --proto_path="$DIR_OF_PROTO_FILE" "$PROTO_FILE" -``` ## Installing the codegen to Maven local repository This will compile a codegen and put it under your ``~/.m2/repository``. This diff --git a/compiler/build.gradle b/compiler/build.gradle index 5be5d15286..cfe037d12b 100644 --- a/compiler/build.gradle +++ b/compiler/build.gradle @@ -125,7 +125,6 @@ model { configurations { testLiteCompile - testNanoCompile } dependencies { @@ -135,18 +134,12 @@ dependencies { testLiteCompile project(':grpc-protobuf-lite'), project(':grpc-stub'), libraries.javax_annotation - testNanoCompile project(':grpc-protobuf-nano'), - project(':grpc-stub'), - libraries.javax_annotation } sourceSets { testLite { proto { setSrcDirs(['src/test/proto']) } } - testNano { - proto { setSrcDirs(['src/test/proto']) } - } } compileTestJava { @@ -167,20 +160,12 @@ compileTestLiteJava { options.errorprone.excludedPaths = ".*/build/generated/source/proto/.*" } -compileTestNanoJava { - options.compilerArgs = compileTestJava.options.compilerArgs - options.errorprone.excludedPaths = ".*/build/generated/source/proto/.*" -} - protobuf { protoc { if (project.hasProperty('protoc')) { path = project.protoc } else { - // Since nano is removed from newer versions of protoc, use an older version for the - // while. This means we won't be able to test any descriptor.proto additions, but that - // should be fine for a while. - artifact = libraries.protoc_nano + artifact = "com.google.protobuf:protoc:${protocVersion}" } } plugins { @@ -206,20 +191,9 @@ protobuf { grpc { option 'lite' } } } - ofSourceSet('testNano').each { task -> - task.builtins { - remove java - javanano { option 'ignore_services=true' } - } - task.plugins { grpc { option 'nano' } } - } } } -checkstyleTestNano { - source = fileTree(dir: "src/testNano", include: "**/*.java") -} - println "*** Building codegen requires Protobuf version ${protocVersion}" println "*** Please refer to https://github.com/grpc/grpc-java/blob/master/COMPILING.md#how-to-build-code-generation-plugin" @@ -320,13 +294,9 @@ def configureTestTask(Task task, String dep, String extraPackage, String service task testGolden(type: Exec) task testLiteGolden(type: Exec) -task testNanoGolden(type: Exec) task testDeprecatedGolden(type: Exec) task testDeprecatedLiteGolden(type: Exec) -task testDeprecatedNanoGolden(type: Exec) configureTestTask(testGolden, '', '', 'TestService') configureTestTask(testLiteGolden, 'Lite', '', 'TestService') -configureTestTask(testNanoGolden, 'Nano', '/nano', 'TestService') configureTestTask(testDeprecatedGolden, '', '', 'TestDeprecatedService') configureTestTask(testDeprecatedLiteGolden, 'Lite', '', 'TestDeprecatedService') -configureTestTask(testDeprecatedNanoGolden, 'Nano', '/nano', 'TestDeprecatedService') diff --git a/compiler/src/java_plugin/cpp/java_generator.cpp b/compiler/src/java_plugin/cpp/java_generator.cpp index 519a28aa07..4ef7b8e437 100644 --- a/compiler/src/java_plugin/cpp/java_generator.cpp +++ b/compiler/src/java_plugin/cpp/java_generator.cpp @@ -149,22 +149,8 @@ static inline bool ShouldGenerateAsLite(const Descriptor* desc) { return false; } -static inline string MessageFullJavaName(bool nano, const Descriptor* desc) { - string name = google::protobuf::compiler::java::ClassName(desc); - if (nano && !ShouldGenerateAsLite(desc)) { - // XXX: Add "nano" to the original package - // (https://github.com/grpc/grpc-java/issues/900) - if (isupper(name[0])) { - // No java package specified. - return "nano." + name; - } - for (size_t i = 0; i < name.size(); ++i) { - if ((name[i] == '.') && (i < (name.size() - 1)) && isupper(name[i + 1])) { - return name.substr(0, i + 1) + "nano." + name.substr(i + 1); - } - } - } - return name; +static inline string MessageFullJavaName(const Descriptor* desc) { + return google::protobuf::compiler::java::ClassName(desc); } // TODO(nmittler): Remove once protobuf includes javadoc methods in distribution. @@ -379,10 +365,8 @@ static void PrintMethodFields( (*vars)["arg_in_id"] = to_string(2 * i); (*vars)["arg_out_id"] = to_string(2 * i + 1); (*vars)["method_name"] = method->name(); - (*vars)["input_type"] = MessageFullJavaName(flavor == ProtoFlavor::NANO, - method->input_type()); - (*vars)["output_type"] = MessageFullJavaName(flavor == ProtoFlavor::NANO, - method->output_type()); + (*vars)["input_type"] = MessageFullJavaName(method->input_type()); + (*vars)["output_type"] = MessageFullJavaName(method->output_type()); (*vars)["method_field_name"] = MethodPropertiesFieldName(method); (*vars)["method_new_field_name"] = MethodPropertiesGetterName(method); (*vars)["method_method_name"] = MethodPropertiesGetterName(method); @@ -402,170 +386,53 @@ static void PrintMethodFields( } } - if (flavor == ProtoFlavor::NANO) { - // TODO(zsurocking): we're creating two NanoFactories for each method right now. - // We could instead create static NanoFactories and reuse them if some methods - // share the same request or response messages. - if (!ShouldGenerateAsLite(method->input_type())) { - p->Print( - *vars, - "private static final int ARG_IN_$method_field_name$ = $arg_in_id$;\n"); - } - if (!ShouldGenerateAsLite(method->output_type())) { - p->Print( - *vars, - "private static final int ARG_OUT_$method_field_name$ = $arg_out_id$;\n"); - } - p->Print( - *vars, - "private static volatile $MethodDescriptor$<$input_type$,\n" - " $output_type$> $method_new_field_name$;\n" - "\n" - "public static $MethodDescriptor$<$input_type$,\n" - " $output_type$> $method_method_name$() {\n" - " $MethodDescriptor$<$input_type$, $output_type$> $method_new_field_name$;\n" - " if (($method_new_field_name$ = $service_class_name$.$method_new_field_name$) == null) {\n" - " synchronized ($service_class_name$.class) {\n" - " if (($method_new_field_name$ = $service_class_name$.$method_new_field_name$) == null) {\n" - " $service_class_name$.$method_new_field_name$ = $method_new_field_name$ = \n" - " $MethodDescriptor$.<$input_type$, $output_type$>newBuilder()\n" - " .setType($MethodType$.$method_type$)\n" - " .setFullMethodName(generateFullMethodName(\n" - " \"$Package$$service_name$\", \"$method_name$\"))\n" - " .setSampledToLocalTracing(true)\n"); - - (*vars)["ProtoLiteUtils"] = "io.grpc.protobuf.lite.ProtoLiteUtils"; - - if (ShouldGenerateAsLite(method->input_type())) { - p->Print( - *vars, - " .setRequestMarshaller($ProtoLiteUtils$.marshaller(\n" - " $input_type$.getDefaultInstance()))\n"); - } else { - p->Print( - *vars, - " .setRequestMarshaller($NanoUtils$.<$input_type$>marshaller(\n" - " new NanoFactory<$input_type$>(ARG_IN_$method_field_name$)))\n"); - } - if (ShouldGenerateAsLite(method->output_type())) { - p->Print( - *vars, - " .setResponseMarshaller($ProtoLiteUtils$.marshaller(\n" - " $output_type$.getDefaultInstance()))\n"); - } else { - p->Print( - *vars, - " .setResponseMarshaller($NanoUtils$.<$output_type$>marshaller(\n" - " new NanoFactory<$output_type$>(ARG_OUT_$method_field_name$)))\n"); - } - p->Print( - *vars, - " .build();\n" - " }\n" - " }\n" - " }\n" - " return $method_new_field_name$;\n" - "}\n" - "\n"); + if (flavor == ProtoFlavor::LITE) { + (*vars)["ProtoUtils"] = "io.grpc.protobuf.lite.ProtoLiteUtils"; } else { - if (flavor == ProtoFlavor::LITE) { - (*vars)["ProtoUtils"] = "io.grpc.protobuf.lite.ProtoLiteUtils"; - } else { - (*vars)["ProtoUtils"] = "io.grpc.protobuf.ProtoUtils"; - } - p->Print( - *vars, - "private static volatile $MethodDescriptor$<$input_type$,\n" - " $output_type$> $method_new_field_name$;\n" - "\n" - "@$RpcMethod$(\n" - " fullMethodName = SERVICE_NAME + '/' + \"$method_name$\",\n" - " requestType = $input_type$.class,\n" - " responseType = $output_type$.class,\n" - " methodType = $MethodType$.$method_type$)\n" - "public static $MethodDescriptor$<$input_type$,\n" - " $output_type$> $method_method_name$() {\n" - " $MethodDescriptor$<$input_type$, $output_type$> $method_new_field_name$;\n" - " if (($method_new_field_name$ = $service_class_name$.$method_new_field_name$) == null) {\n" - " synchronized ($service_class_name$.class) {\n" - " if (($method_new_field_name$ = $service_class_name$.$method_new_field_name$) == null) {\n" - " $service_class_name$.$method_new_field_name$ = $method_new_field_name$ = \n" - " $MethodDescriptor$.<$input_type$, $output_type$>newBuilder()\n" - " .setType($MethodType$.$method_type$)\n" - " .setFullMethodName(generateFullMethodName(\n" - " \"$Package$$service_name$\", \"$method_name$\"))\n" - " .setSampledToLocalTracing(true)\n" - " .setRequestMarshaller($ProtoUtils$.marshaller(\n" - " $input_type$.getDefaultInstance()))\n" - " .setResponseMarshaller($ProtoUtils$.marshaller(\n" - " $output_type$.getDefaultInstance()))\n"); - - (*vars)["proto_method_descriptor_supplier"] = service->name() + "MethodDescriptorSupplier"; - if (flavor == ProtoFlavor::NORMAL) { - p->Print( - *vars, - " .setSchemaDescriptor(new $proto_method_descriptor_supplier$(\"$method_name$\"))\n"); - } - - p->Print( - *vars, - " .build();\n"); - p->Print(*vars, - " }\n" - " }\n" - " }\n" - " return $method_new_field_name$;\n" - "}\n" - "\n"); + (*vars)["ProtoUtils"] = "io.grpc.protobuf.ProtoUtils"; } - } - - if (flavor == ProtoFlavor::NANO) { p->Print( *vars, - "private static final class NanoFactory\n" - " implements io.grpc.protobuf.nano.MessageNanoFactory {\n" - " private final int id;\n" + "private static volatile $MethodDescriptor$<$input_type$,\n" + " $output_type$> $method_new_field_name$;\n" "\n" - " NanoFactory(int id) {\n" - " this.id = id;\n" - " }\n" - "\n" - " @$Override$\n" - " public T newInstance() {\n" - " Object o;\n" - " switch (id) {\n"); - bool generate_nano = true; - for (int i = 0; i < service->method_count(); ++i) { - const MethodDescriptor* method = service->method(i); - (*vars)["input_type"] = MessageFullJavaName(generate_nano, - method->input_type()); - (*vars)["output_type"] = MessageFullJavaName(generate_nano, - method->output_type()); - (*vars)["method_field_name"] = MethodPropertiesFieldName(method); - if (!ShouldGenerateAsLite(method->input_type())) { - p->Print( - *vars, - " case ARG_IN_$method_field_name$:\n" - " o = new $input_type$();\n" - " break;\n"); - } - if (!ShouldGenerateAsLite(method->output_type())) { - p->Print( - *vars, - " case ARG_OUT_$method_field_name$:\n" - " o = new $output_type$();\n" - " break;\n"); - } + "@$RpcMethod$(\n" + " fullMethodName = SERVICE_NAME + '/' + \"$method_name$\",\n" + " requestType = $input_type$.class,\n" + " responseType = $output_type$.class,\n" + " methodType = $MethodType$.$method_type$)\n" + "public static $MethodDescriptor$<$input_type$,\n" + " $output_type$> $method_method_name$() {\n" + " $MethodDescriptor$<$input_type$, $output_type$> $method_new_field_name$;\n" + " if (($method_new_field_name$ = $service_class_name$.$method_new_field_name$) == null) {\n" + " synchronized ($service_class_name$.class) {\n" + " if (($method_new_field_name$ = $service_class_name$.$method_new_field_name$) == null) {\n" + " $service_class_name$.$method_new_field_name$ = $method_new_field_name$ = \n" + " $MethodDescriptor$.<$input_type$, $output_type$>newBuilder()\n" + " .setType($MethodType$.$method_type$)\n" + " .setFullMethodName(generateFullMethodName(\n" + " \"$Package$$service_name$\", \"$method_name$\"))\n" + " .setSampledToLocalTracing(true)\n" + " .setRequestMarshaller($ProtoUtils$.marshaller(\n" + " $input_type$.getDefaultInstance()))\n" + " .setResponseMarshaller($ProtoUtils$.marshaller(\n" + " $output_type$.getDefaultInstance()))\n"); + + (*vars)["proto_method_descriptor_supplier"] = service->name() + "MethodDescriptorSupplier"; + if (flavor == ProtoFlavor::NORMAL) { + p->Print( + *vars, + " .setSchemaDescriptor(new $proto_method_descriptor_supplier$(\"$method_name$\"))\n"); } + p->Print( - " default:\n" - " throw new AssertionError();\n" - " }\n" - " @java.lang.SuppressWarnings(\"unchecked\")\n" - " T t = (T) o;\n" - " return t;\n" - " }\n" + *vars, + " .build();\n"); + p->Print(*vars, + " }\n" + " }\n" + " }\n" + " return $method_new_field_name$;\n" "}\n" "\n"); } @@ -590,14 +457,13 @@ enum CallType { static void PrintBindServiceMethodBody(const ServiceDescriptor* service, std::map* vars, - Printer* p, - bool generate_nano); + Printer* p); // Prints a client interface or implementation class, or a server interface. static void PrintStub( const ServiceDescriptor* service, std::map* vars, - Printer* p, StubType type, bool generate_nano) { + Printer* p, StubType type) { const string service_name = service->name(); (*vars)["service_name"] = service_name; (*vars)["abstract_name"] = service_name + "ImplBase"; @@ -694,10 +560,8 @@ static void PrintStub( // RPC methods for (int i = 0; i < service->method_count(); ++i) { const MethodDescriptor* method = service->method(i); - (*vars)["input_type"] = MessageFullJavaName(generate_nano, - method->input_type()); - (*vars)["output_type"] = MessageFullJavaName(generate_nano, - method->output_type()); + (*vars)["input_type"] = MessageFullJavaName(method->input_type()); + (*vars)["output_type"] = MessageFullJavaName(method->output_type()); (*vars)["lower_method_name"] = LowerMethodName(method); (*vars)["method_method_name"] = MethodPropertiesGetterName(method); bool client_streaming = method->client_streaming(); @@ -858,7 +722,7 @@ static void PrintStub( *vars, "@$Override$ public final $ServerServiceDefinition$ bindService() {\n"); (*vars)["instance"] = "this"; - PrintBindServiceMethodBody(service, vars, p, generate_nano); + PrintBindServiceMethodBody(service, vars, p); p->Print("}\n"); } @@ -876,8 +740,7 @@ static bool CompareMethodClientStreaming(const MethodDescriptor* method1, // on Android. static void PrintMethodHandlerClass(const ServiceDescriptor* service, std::map* vars, - Printer* p, - bool generate_nano) { + Printer* p) { // Sort method ids based on client_streaming() so switch tables are compact. std::vector sorted_methods(service->method_count()); for (int i = 0; i < service->method_count(); ++i) { @@ -926,10 +789,8 @@ static void PrintMethodHandlerClass(const ServiceDescriptor* service, } (*vars)["method_id_name"] = MethodIdFieldName(method); (*vars)["lower_method_name"] = LowerMethodName(method); - (*vars)["input_type"] = MessageFullJavaName(generate_nano, - method->input_type()); - (*vars)["output_type"] = MessageFullJavaName(generate_nano, - method->output_type()); + (*vars)["input_type"] = MessageFullJavaName(method->input_type()); + (*vars)["output_type"] = MessageFullJavaName(method->output_type()); p->Print( *vars, "case $method_id_name$:\n" @@ -962,10 +823,8 @@ static void PrintMethodHandlerClass(const ServiceDescriptor* service, } (*vars)["method_id_name"] = MethodIdFieldName(method); (*vars)["lower_method_name"] = LowerMethodName(method); - (*vars)["input_type"] = MessageFullJavaName(generate_nano, - method->input_type()); - (*vars)["output_type"] = MessageFullJavaName(generate_nano, - method->output_type()); + (*vars)["input_type"] = MessageFullJavaName(method->input_type()); + (*vars)["output_type"] = MessageFullJavaName(method->output_type()); p->Print( *vars, "case $method_id_name$:\n" @@ -1088,8 +947,7 @@ static void PrintGetServiceDescriptorMethod(const ServiceDescriptor* service, static void PrintBindServiceMethodBody(const ServiceDescriptor* service, std::map* vars, - Printer* p, - bool generate_nano) { + Printer* p) { (*vars)["service_name"] = service->name(); p->Indent(); p->Print(*vars, @@ -1101,10 +959,8 @@ static void PrintBindServiceMethodBody(const ServiceDescriptor* service, const MethodDescriptor* method = service->method(i); (*vars)["lower_method_name"] = LowerMethodName(method); (*vars)["method_method_name"] = MethodPropertiesGetterName(method); - (*vars)["input_type"] = MessageFullJavaName(generate_nano, - method->input_type()); - (*vars)["output_type"] = MessageFullJavaName(generate_nano, - method->output_type()); + (*vars)["input_type"] = MessageFullJavaName(method->input_type()); + (*vars)["output_type"] = MessageFullJavaName(method->output_type()); (*vars)["method_id_name"] = MethodIdFieldName(method); bool client_streaming = method->client_streaming(); bool server_streaming = method->server_streaming(); @@ -1224,19 +1080,18 @@ static void PrintService(const ServiceDescriptor* service, p->Outdent(); p->Print("}\n\n"); - bool generate_nano = flavor == ProtoFlavor::NANO; - PrintStub(service, vars, p, ABSTRACT_CLASS, generate_nano); - PrintStub(service, vars, p, ASYNC_CLIENT_IMPL, generate_nano); - PrintStub(service, vars, p, BLOCKING_CLIENT_IMPL, generate_nano); - PrintStub(service, vars, p, FUTURE_CLIENT_IMPL, generate_nano); + PrintStub(service, vars, p, ABSTRACT_CLASS); + PrintStub(service, vars, p, ASYNC_CLIENT_IMPL); + PrintStub(service, vars, p, BLOCKING_CLIENT_IMPL); + PrintStub(service, vars, p, FUTURE_CLIENT_IMPL); - PrintMethodHandlerClass(service, vars, p, generate_nano); + PrintMethodHandlerClass(service, vars, p); PrintGetServiceDescriptorMethod(service, vars, p, flavor); p->Outdent(); p->Print("}\n"); } -void PrintImports(Printer* p, bool generate_nano) { +void PrintImports(Printer* p) { p->Print( "import static " "io.grpc.MethodDescriptor.generateFullMethodName;\n" @@ -1266,9 +1121,6 @@ void PrintImports(Printer* p, bool generate_nano) { "io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;\n" "import static " "io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;\n\n"); - if (generate_nano) { - p->Print("import java.io.IOException;\n\n"); - } } void GenerateService(const ServiceDescriptor* service, @@ -1300,7 +1152,6 @@ void GenerateService(const ServiceDescriptor* service, vars["AbstractStub"] = "io.grpc.stub.AbstractStub"; vars["RpcMethod"] = "io.grpc.stub.annotations.RpcMethod"; vars["MethodDescriptor"] = "io.grpc.MethodDescriptor"; - vars["NanoUtils"] = "io.grpc.protobuf.nano.NanoUtils"; vars["StreamObserver"] = "io.grpc.stub.StreamObserver"; vars["Iterator"] = "java.util.Iterator"; vars["Generated"] = "javax.annotation.Generated"; @@ -1308,14 +1159,13 @@ void GenerateService(const ServiceDescriptor* service, "com.google.common.util.concurrent.ListenableFuture"; Printer printer(out, '$'); - string package_name = ServiceJavaPackage(service->file(), - flavor == ProtoFlavor::NANO); + string package_name = ServiceJavaPackage(service->file()); if (!package_name.empty()) { printer.Print( "package $package_name$;\n\n", "package_name", package_name); } - PrintImports(&printer, flavor == ProtoFlavor::NANO); + PrintImports(&printer); // Package string is used to fully qualify method names. vars["Package"] = service->file()->package(); @@ -1325,7 +1175,7 @@ void GenerateService(const ServiceDescriptor* service, PrintService(service, &vars, &printer, flavor, disable_version); } -string ServiceJavaPackage(const FileDescriptor* file, bool nano) { +string ServiceJavaPackage(const FileDescriptor* file) { string result = google::protobuf::compiler::java::ClassName(file); size_t last_dot_pos = result.find_last_of('.'); if (last_dot_pos != string::npos) { @@ -1333,12 +1183,6 @@ string ServiceJavaPackage(const FileDescriptor* file, bool nano) { } else { result = ""; } - if (nano) { - if (!result.empty()) { - result += "."; - } - result += "nano"; - } return result; } diff --git a/compiler/src/java_plugin/cpp/java_generator.h b/compiler/src/java_plugin/cpp/java_generator.h index ab265d06c7..7e2c1a8fe0 100644 --- a/compiler/src/java_plugin/cpp/java_generator.h +++ b/compiler/src/java_plugin/cpp/java_generator.h @@ -36,11 +36,11 @@ using namespace std; namespace java_grpc_generator { enum ProtoFlavor { - NORMAL, LITE, NANO + NORMAL, LITE }; // Returns the package name of the gRPC services defined in the given file. -string ServiceJavaPackage(const google::protobuf::FileDescriptor* file, bool nano); +string ServiceJavaPackage(const google::protobuf::FileDescriptor* file); // Returns the name of the outer class that wraps in all the generated code for // the given service. diff --git a/compiler/src/java_plugin/cpp/java_plugin.cpp b/compiler/src/java_plugin/cpp/java_plugin.cpp index b2cbd0bae1..fff219177e 100644 --- a/compiler/src/java_plugin/cpp/java_plugin.cpp +++ b/compiler/src/java_plugin/cpp/java_plugin.cpp @@ -39,17 +39,14 @@ class JavaGrpcGenerator : public google::protobuf::compiler::CodeGenerator { bool disable_version = false; for (size_t i = 0; i < options.size(); i++) { - if (options[i].first == "nano") { - flavor = java_grpc_generator::ProtoFlavor::NANO; - } else if (options[i].first == "lite") { + if (options[i].first == "lite") { flavor = java_grpc_generator::ProtoFlavor::LITE; } else if (options[i].first == "noversion") { disable_version = true; } } - string package_name = java_grpc_generator::ServiceJavaPackage( - file, flavor == java_grpc_generator::ProtoFlavor::NANO); + string package_name = java_grpc_generator::ServiceJavaPackage(file); string package_filename = JavaPackageToDir(package_name); for (int i = 0; i < file->service_count(); ++i) { const google::protobuf::ServiceDescriptor* service = file->service(i); diff --git a/compiler/src/testNano/golden/TestDeprecatedService.java.txt b/compiler/src/testNano/golden/TestDeprecatedService.java.txt deleted file mode 100644 index dc662075a3..0000000000 --- a/compiler/src/testNano/golden/TestDeprecatedService.java.txt +++ /dev/null @@ -1,305 +0,0 @@ -package io.grpc.testing.compiler.nano; - -import static io.grpc.MethodDescriptor.generateFullMethodName; -import static io.grpc.stub.ClientCalls.asyncBidiStreamingCall; -import static io.grpc.stub.ClientCalls.asyncClientStreamingCall; -import static io.grpc.stub.ClientCalls.asyncServerStreamingCall; -import static io.grpc.stub.ClientCalls.asyncUnaryCall; -import static io.grpc.stub.ClientCalls.blockingServerStreamingCall; -import static io.grpc.stub.ClientCalls.blockingUnaryCall; -import static io.grpc.stub.ClientCalls.futureUnaryCall; -import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall; -import static io.grpc.stub.ServerCalls.asyncClientStreamingCall; -import static io.grpc.stub.ServerCalls.asyncServerStreamingCall; -import static io.grpc.stub.ServerCalls.asyncUnaryCall; -import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall; -import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall; - -import java.io.IOException; - -/** - *
- * Test service that has been deprecated and should generate with Java's @Deprecated annotation
- * 
- */ -@javax.annotation.Generated( - value = "by gRPC proto compiler (version 1.22.0-SNAPSHOT)", - comments = "Source: grpc/testing/compiler/test.proto") -@java.lang.Deprecated -public final class TestDeprecatedServiceGrpc { - - private TestDeprecatedServiceGrpc() {} - - public static final String SERVICE_NAME = "grpc.testing.compiler.TestDeprecatedService"; - - // Static method descriptors that strictly reflect the proto. - private static final int ARG_IN_METHOD_DEPRECATED_METHOD = 0; - private static final int ARG_OUT_METHOD_DEPRECATED_METHOD = 1; - private static volatile io.grpc.MethodDescriptor getDeprecatedMethodMethod; - - public static io.grpc.MethodDescriptor getDeprecatedMethodMethod() { - io.grpc.MethodDescriptor getDeprecatedMethodMethod; - if ((getDeprecatedMethodMethod = TestDeprecatedServiceGrpc.getDeprecatedMethodMethod) == null) { - synchronized (TestDeprecatedServiceGrpc.class) { - if ((getDeprecatedMethodMethod = TestDeprecatedServiceGrpc.getDeprecatedMethodMethod) == null) { - TestDeprecatedServiceGrpc.getDeprecatedMethodMethod = getDeprecatedMethodMethod = - io.grpc.MethodDescriptor.newBuilder() - .setType(io.grpc.MethodDescriptor.MethodType.UNARY) - .setFullMethodName(generateFullMethodName( - "grpc.testing.compiler.TestDeprecatedService", "DeprecatedMethod")) - .setSampledToLocalTracing(true) - .setRequestMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( - new NanoFactory(ARG_IN_METHOD_DEPRECATED_METHOD))) - .setResponseMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( - new NanoFactory(ARG_OUT_METHOD_DEPRECATED_METHOD))) - .build(); - } - } - } - return getDeprecatedMethodMethod; - } - - private static final class NanoFactory - implements io.grpc.protobuf.nano.MessageNanoFactory { - private final int id; - - NanoFactory(int id) { - this.id = id; - } - - @java.lang.Override - public T newInstance() { - Object o; - switch (id) { - case ARG_IN_METHOD_DEPRECATED_METHOD: - o = new io.grpc.testing.compiler.nano.Test.SimpleRequest(); - break; - case ARG_OUT_METHOD_DEPRECATED_METHOD: - o = new io.grpc.testing.compiler.nano.Test.SimpleResponse(); - break; - default: - throw new AssertionError(); - } - @java.lang.SuppressWarnings("unchecked") - T t = (T) o; - return t; - } - } - - /** - * Creates a new async stub that supports all call types for the service - */ - public static TestDeprecatedServiceStub newStub(io.grpc.Channel channel) { - return new TestDeprecatedServiceStub(channel); - } - - /** - * Creates a new blocking-style stub that supports unary and streaming output calls on the service - */ - public static TestDeprecatedServiceBlockingStub newBlockingStub( - io.grpc.Channel channel) { - return new TestDeprecatedServiceBlockingStub(channel); - } - - /** - * Creates a new ListenableFuture-style stub that supports unary calls on the service - */ - public static TestDeprecatedServiceFutureStub newFutureStub( - io.grpc.Channel channel) { - return new TestDeprecatedServiceFutureStub(channel); - } - - /** - *
-   * Test service that has been deprecated and should generate with Java's @Deprecated annotation
-   * 
- */ - @java.lang.Deprecated - public static abstract class TestDeprecatedServiceImplBase implements io.grpc.BindableService { - - /** - *
-     * An RPC method that has been deprecated and should generate with Java's @Deprecated annotation
-     * 
- */ - @java.lang.Deprecated - public void deprecatedMethod(io.grpc.testing.compiler.nano.Test.SimpleRequest request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnimplementedUnaryCall(getDeprecatedMethodMethod(), responseObserver); - } - - @java.lang.Override public final io.grpc.ServerServiceDefinition bindService() { - return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()) - .addMethod( - getDeprecatedMethodMethod(), - asyncUnaryCall( - new MethodHandlers< - io.grpc.testing.compiler.nano.Test.SimpleRequest, - io.grpc.testing.compiler.nano.Test.SimpleResponse>( - this, METHODID_DEPRECATED_METHOD))) - .build(); - } - } - - /** - *
-   * Test service that has been deprecated and should generate with Java's @Deprecated annotation
-   * 
- */ - @java.lang.Deprecated - public static final class TestDeprecatedServiceStub extends io.grpc.stub.AbstractStub { - private TestDeprecatedServiceStub(io.grpc.Channel channel) { - super(channel); - } - - private TestDeprecatedServiceStub(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - super(channel, callOptions); - } - - @java.lang.Override - protected TestDeprecatedServiceStub build(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - return new TestDeprecatedServiceStub(channel, callOptions); - } - - /** - *
-     * An RPC method that has been deprecated and should generate with Java's @Deprecated annotation
-     * 
- */ - @java.lang.Deprecated - public void deprecatedMethod(io.grpc.testing.compiler.nano.Test.SimpleRequest request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnaryCall( - getChannel().newCall(getDeprecatedMethodMethod(), getCallOptions()), request, responseObserver); - } - } - - /** - *
-   * Test service that has been deprecated and should generate with Java's @Deprecated annotation
-   * 
- */ - @java.lang.Deprecated - public static final class TestDeprecatedServiceBlockingStub extends io.grpc.stub.AbstractStub { - private TestDeprecatedServiceBlockingStub(io.grpc.Channel channel) { - super(channel); - } - - private TestDeprecatedServiceBlockingStub(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - super(channel, callOptions); - } - - @java.lang.Override - protected TestDeprecatedServiceBlockingStub build(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - return new TestDeprecatedServiceBlockingStub(channel, callOptions); - } - - /** - *
-     * An RPC method that has been deprecated and should generate with Java's @Deprecated annotation
-     * 
- */ - @java.lang.Deprecated - public io.grpc.testing.compiler.nano.Test.SimpleResponse deprecatedMethod(io.grpc.testing.compiler.nano.Test.SimpleRequest request) { - return blockingUnaryCall( - getChannel(), getDeprecatedMethodMethod(), getCallOptions(), request); - } - } - - /** - *
-   * Test service that has been deprecated and should generate with Java's @Deprecated annotation
-   * 
- */ - @java.lang.Deprecated - public static final class TestDeprecatedServiceFutureStub extends io.grpc.stub.AbstractStub { - private TestDeprecatedServiceFutureStub(io.grpc.Channel channel) { - super(channel); - } - - private TestDeprecatedServiceFutureStub(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - super(channel, callOptions); - } - - @java.lang.Override - protected TestDeprecatedServiceFutureStub build(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - return new TestDeprecatedServiceFutureStub(channel, callOptions); - } - - /** - *
-     * An RPC method that has been deprecated and should generate with Java's @Deprecated annotation
-     * 
- */ - @java.lang.Deprecated - public com.google.common.util.concurrent.ListenableFuture deprecatedMethod( - io.grpc.testing.compiler.nano.Test.SimpleRequest request) { - return futureUnaryCall( - getChannel().newCall(getDeprecatedMethodMethod(), getCallOptions()), request); - } - } - - private static final int METHODID_DEPRECATED_METHOD = 0; - - private static final class MethodHandlers implements - io.grpc.stub.ServerCalls.UnaryMethod, - io.grpc.stub.ServerCalls.ServerStreamingMethod, - io.grpc.stub.ServerCalls.ClientStreamingMethod, - io.grpc.stub.ServerCalls.BidiStreamingMethod { - private final TestDeprecatedServiceImplBase serviceImpl; - private final int methodId; - - MethodHandlers(TestDeprecatedServiceImplBase serviceImpl, int methodId) { - this.serviceImpl = serviceImpl; - this.methodId = methodId; - } - - @java.lang.Override - @java.lang.SuppressWarnings("unchecked") - public void invoke(Req request, io.grpc.stub.StreamObserver responseObserver) { - switch (methodId) { - case METHODID_DEPRECATED_METHOD: - serviceImpl.deprecatedMethod((io.grpc.testing.compiler.nano.Test.SimpleRequest) request, - (io.grpc.stub.StreamObserver) responseObserver); - break; - default: - throw new AssertionError(); - } - } - - @java.lang.Override - @java.lang.SuppressWarnings("unchecked") - public io.grpc.stub.StreamObserver invoke( - io.grpc.stub.StreamObserver responseObserver) { - switch (methodId) { - default: - throw new AssertionError(); - } - } - } - - private static volatile io.grpc.ServiceDescriptor serviceDescriptor; - - public static io.grpc.ServiceDescriptor getServiceDescriptor() { - io.grpc.ServiceDescriptor result = serviceDescriptor; - if (result == null) { - synchronized (TestDeprecatedServiceGrpc.class) { - result = serviceDescriptor; - if (result == null) { - serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME) - .addMethod(getDeprecatedMethodMethod()) - .build(); - } - } - } - return result; - } -} diff --git a/compiler/src/testNano/golden/TestService.java.txt b/compiler/src/testNano/golden/TestService.java.txt deleted file mode 100644 index 1727fb1879..0000000000 --- a/compiler/src/testNano/golden/TestService.java.txt +++ /dev/null @@ -1,664 +0,0 @@ -package io.grpc.testing.compiler.nano; - -import static io.grpc.MethodDescriptor.generateFullMethodName; -import static io.grpc.stub.ClientCalls.asyncBidiStreamingCall; -import static io.grpc.stub.ClientCalls.asyncClientStreamingCall; -import static io.grpc.stub.ClientCalls.asyncServerStreamingCall; -import static io.grpc.stub.ClientCalls.asyncUnaryCall; -import static io.grpc.stub.ClientCalls.blockingServerStreamingCall; -import static io.grpc.stub.ClientCalls.blockingUnaryCall; -import static io.grpc.stub.ClientCalls.futureUnaryCall; -import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall; -import static io.grpc.stub.ServerCalls.asyncClientStreamingCall; -import static io.grpc.stub.ServerCalls.asyncServerStreamingCall; -import static io.grpc.stub.ServerCalls.asyncUnaryCall; -import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall; -import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall; - -import java.io.IOException; - -/** - *
- * Test service that supports all call types.
- * 
- */ -@javax.annotation.Generated( - value = "by gRPC proto compiler (version 1.22.0-SNAPSHOT)", - comments = "Source: grpc/testing/compiler/test.proto") -public final class TestServiceGrpc { - - private TestServiceGrpc() {} - - public static final String SERVICE_NAME = "grpc.testing.compiler.TestService"; - - // Static method descriptors that strictly reflect the proto. - private static final int ARG_IN_METHOD_UNARY_CALL = 0; - private static final int ARG_OUT_METHOD_UNARY_CALL = 1; - private static volatile io.grpc.MethodDescriptor getUnaryCallMethod; - - public static io.grpc.MethodDescriptor getUnaryCallMethod() { - io.grpc.MethodDescriptor getUnaryCallMethod; - if ((getUnaryCallMethod = TestServiceGrpc.getUnaryCallMethod) == null) { - synchronized (TestServiceGrpc.class) { - if ((getUnaryCallMethod = TestServiceGrpc.getUnaryCallMethod) == null) { - TestServiceGrpc.getUnaryCallMethod = getUnaryCallMethod = - io.grpc.MethodDescriptor.newBuilder() - .setType(io.grpc.MethodDescriptor.MethodType.UNARY) - .setFullMethodName(generateFullMethodName( - "grpc.testing.compiler.TestService", "UnaryCall")) - .setSampledToLocalTracing(true) - .setRequestMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( - new NanoFactory(ARG_IN_METHOD_UNARY_CALL))) - .setResponseMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( - new NanoFactory(ARG_OUT_METHOD_UNARY_CALL))) - .build(); - } - } - } - return getUnaryCallMethod; - } - - private static final int ARG_IN_METHOD_STREAMING_OUTPUT_CALL = 2; - private static final int ARG_OUT_METHOD_STREAMING_OUTPUT_CALL = 3; - private static volatile io.grpc.MethodDescriptor getStreamingOutputCallMethod; - - public static io.grpc.MethodDescriptor getStreamingOutputCallMethod() { - io.grpc.MethodDescriptor getStreamingOutputCallMethod; - if ((getStreamingOutputCallMethod = TestServiceGrpc.getStreamingOutputCallMethod) == null) { - synchronized (TestServiceGrpc.class) { - if ((getStreamingOutputCallMethod = TestServiceGrpc.getStreamingOutputCallMethod) == null) { - TestServiceGrpc.getStreamingOutputCallMethod = getStreamingOutputCallMethod = - io.grpc.MethodDescriptor.newBuilder() - .setType(io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING) - .setFullMethodName(generateFullMethodName( - "grpc.testing.compiler.TestService", "StreamingOutputCall")) - .setSampledToLocalTracing(true) - .setRequestMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( - new NanoFactory(ARG_IN_METHOD_STREAMING_OUTPUT_CALL))) - .setResponseMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( - new NanoFactory(ARG_OUT_METHOD_STREAMING_OUTPUT_CALL))) - .build(); - } - } - } - return getStreamingOutputCallMethod; - } - - private static final int ARG_IN_METHOD_STREAMING_INPUT_CALL = 4; - private static final int ARG_OUT_METHOD_STREAMING_INPUT_CALL = 5; - private static volatile io.grpc.MethodDescriptor getStreamingInputCallMethod; - - public static io.grpc.MethodDescriptor getStreamingInputCallMethod() { - io.grpc.MethodDescriptor getStreamingInputCallMethod; - if ((getStreamingInputCallMethod = TestServiceGrpc.getStreamingInputCallMethod) == null) { - synchronized (TestServiceGrpc.class) { - if ((getStreamingInputCallMethod = TestServiceGrpc.getStreamingInputCallMethod) == null) { - TestServiceGrpc.getStreamingInputCallMethod = getStreamingInputCallMethod = - io.grpc.MethodDescriptor.newBuilder() - .setType(io.grpc.MethodDescriptor.MethodType.CLIENT_STREAMING) - .setFullMethodName(generateFullMethodName( - "grpc.testing.compiler.TestService", "StreamingInputCall")) - .setSampledToLocalTracing(true) - .setRequestMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( - new NanoFactory(ARG_IN_METHOD_STREAMING_INPUT_CALL))) - .setResponseMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( - new NanoFactory(ARG_OUT_METHOD_STREAMING_INPUT_CALL))) - .build(); - } - } - } - return getStreamingInputCallMethod; - } - - private static final int ARG_IN_METHOD_FULL_BIDI_CALL = 6; - private static final int ARG_OUT_METHOD_FULL_BIDI_CALL = 7; - private static volatile io.grpc.MethodDescriptor getFullBidiCallMethod; - - public static io.grpc.MethodDescriptor getFullBidiCallMethod() { - io.grpc.MethodDescriptor getFullBidiCallMethod; - if ((getFullBidiCallMethod = TestServiceGrpc.getFullBidiCallMethod) == null) { - synchronized (TestServiceGrpc.class) { - if ((getFullBidiCallMethod = TestServiceGrpc.getFullBidiCallMethod) == null) { - TestServiceGrpc.getFullBidiCallMethod = getFullBidiCallMethod = - io.grpc.MethodDescriptor.newBuilder() - .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) - .setFullMethodName(generateFullMethodName( - "grpc.testing.compiler.TestService", "FullBidiCall")) - .setSampledToLocalTracing(true) - .setRequestMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( - new NanoFactory(ARG_IN_METHOD_FULL_BIDI_CALL))) - .setResponseMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( - new NanoFactory(ARG_OUT_METHOD_FULL_BIDI_CALL))) - .build(); - } - } - } - return getFullBidiCallMethod; - } - - private static final int ARG_IN_METHOD_HALF_BIDI_CALL = 8; - private static final int ARG_OUT_METHOD_HALF_BIDI_CALL = 9; - private static volatile io.grpc.MethodDescriptor getHalfBidiCallMethod; - - public static io.grpc.MethodDescriptor getHalfBidiCallMethod() { - io.grpc.MethodDescriptor getHalfBidiCallMethod; - if ((getHalfBidiCallMethod = TestServiceGrpc.getHalfBidiCallMethod) == null) { - synchronized (TestServiceGrpc.class) { - if ((getHalfBidiCallMethod = TestServiceGrpc.getHalfBidiCallMethod) == null) { - TestServiceGrpc.getHalfBidiCallMethod = getHalfBidiCallMethod = - io.grpc.MethodDescriptor.newBuilder() - .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) - .setFullMethodName(generateFullMethodName( - "grpc.testing.compiler.TestService", "HalfBidiCall")) - .setSampledToLocalTracing(true) - .setRequestMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( - new NanoFactory(ARG_IN_METHOD_HALF_BIDI_CALL))) - .setResponseMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( - new NanoFactory(ARG_OUT_METHOD_HALF_BIDI_CALL))) - .build(); - } - } - } - return getHalfBidiCallMethod; - } - - private static final int ARG_IN_METHOD_IMPORT = 10; - private static final int ARG_OUT_METHOD_IMPORT = 11; - private static volatile io.grpc.MethodDescriptor getImportMethod; - - public static io.grpc.MethodDescriptor getImportMethod() { - io.grpc.MethodDescriptor getImportMethod; - if ((getImportMethod = TestServiceGrpc.getImportMethod) == null) { - synchronized (TestServiceGrpc.class) { - if ((getImportMethod = TestServiceGrpc.getImportMethod) == null) { - TestServiceGrpc.getImportMethod = getImportMethod = - io.grpc.MethodDescriptor.newBuilder() - .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) - .setFullMethodName(generateFullMethodName( - "grpc.testing.compiler.TestService", "Import")) - .setSampledToLocalTracing(true) - .setRequestMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( - new NanoFactory(ARG_IN_METHOD_IMPORT))) - .setResponseMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( - new NanoFactory(ARG_OUT_METHOD_IMPORT))) - .build(); - } - } - } - return getImportMethod; - } - - private static final class NanoFactory - implements io.grpc.protobuf.nano.MessageNanoFactory { - private final int id; - - NanoFactory(int id) { - this.id = id; - } - - @java.lang.Override - public T newInstance() { - Object o; - switch (id) { - case ARG_IN_METHOD_UNARY_CALL: - o = new io.grpc.testing.compiler.nano.Test.SimpleRequest(); - break; - case ARG_OUT_METHOD_UNARY_CALL: - o = new io.grpc.testing.compiler.nano.Test.SimpleResponse(); - break; - case ARG_IN_METHOD_STREAMING_OUTPUT_CALL: - o = new io.grpc.testing.compiler.nano.Test.StreamingOutputCallRequest(); - break; - case ARG_OUT_METHOD_STREAMING_OUTPUT_CALL: - o = new io.grpc.testing.compiler.nano.Test.StreamingOutputCallResponse(); - break; - case ARG_IN_METHOD_STREAMING_INPUT_CALL: - o = new io.grpc.testing.compiler.nano.Test.StreamingInputCallRequest(); - break; - case ARG_OUT_METHOD_STREAMING_INPUT_CALL: - o = new io.grpc.testing.compiler.nano.Test.StreamingInputCallResponse(); - break; - case ARG_IN_METHOD_FULL_BIDI_CALL: - o = new io.grpc.testing.compiler.nano.Test.StreamingOutputCallRequest(); - break; - case ARG_OUT_METHOD_FULL_BIDI_CALL: - o = new io.grpc.testing.compiler.nano.Test.StreamingOutputCallResponse(); - break; - case ARG_IN_METHOD_HALF_BIDI_CALL: - o = new io.grpc.testing.compiler.nano.Test.StreamingOutputCallRequest(); - break; - case ARG_OUT_METHOD_HALF_BIDI_CALL: - o = new io.grpc.testing.compiler.nano.Test.StreamingOutputCallResponse(); - break; - case ARG_IN_METHOD_IMPORT: - o = new io.grpc.testing.compiler.nano.Test.StreamingInputCallRequest(); - break; - case ARG_OUT_METHOD_IMPORT: - o = new io.grpc.testing.compiler.nano.Test.StreamingInputCallResponse(); - break; - default: - throw new AssertionError(); - } - @java.lang.SuppressWarnings("unchecked") - T t = (T) o; - return t; - } - } - - /** - * Creates a new async stub that supports all call types for the service - */ - public static TestServiceStub newStub(io.grpc.Channel channel) { - return new TestServiceStub(channel); - } - - /** - * Creates a new blocking-style stub that supports unary and streaming output calls on the service - */ - public static TestServiceBlockingStub newBlockingStub( - io.grpc.Channel channel) { - return new TestServiceBlockingStub(channel); - } - - /** - * Creates a new ListenableFuture-style stub that supports unary calls on the service - */ - public static TestServiceFutureStub newFutureStub( - io.grpc.Channel channel) { - return new TestServiceFutureStub(channel); - } - - /** - *
-   * Test service that supports all call types.
-   * 
- */ - public static abstract class TestServiceImplBase implements io.grpc.BindableService { - - /** - *
-     * One request followed by one response.
-     * The server returns the client payload as-is.
-     * 
- */ - public void unaryCall(io.grpc.testing.compiler.nano.Test.SimpleRequest request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnimplementedUnaryCall(getUnaryCallMethod(), responseObserver); - } - - /** - *
-     * One request followed by a sequence of responses (streamed download).
-     * The server returns the payload with client desired type and sizes.
-     * 
- */ - public void streamingOutputCall(io.grpc.testing.compiler.nano.Test.StreamingOutputCallRequest request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnimplementedUnaryCall(getStreamingOutputCallMethod(), responseObserver); - } - - /** - *
-     * A sequence of requests followed by one response (streamed upload).
-     * The server returns the aggregated size of client payload as the result.
-     * 
- */ - public io.grpc.stub.StreamObserver streamingInputCall( - io.grpc.stub.StreamObserver responseObserver) { - return asyncUnimplementedStreamingCall(getStreamingInputCallMethod(), responseObserver); - } - - /** - *
-     * A sequence of requests with each request served by the server immediately.
-     * As one request could lead to multiple responses, this interface
-     * demonstrates the idea of full bidirectionality.
-     * 
- */ - public io.grpc.stub.StreamObserver fullBidiCall( - io.grpc.stub.StreamObserver responseObserver) { - return asyncUnimplementedStreamingCall(getFullBidiCallMethod(), responseObserver); - } - - /** - *
-     * A sequence of requests followed by a sequence of responses.
-     * The server buffers all the client requests and then serves them in order. A
-     * stream of responses are returned to the client when the server starts with
-     * first request.
-     * 
- */ - public io.grpc.stub.StreamObserver halfBidiCall( - io.grpc.stub.StreamObserver responseObserver) { - return asyncUnimplementedStreamingCall(getHalfBidiCallMethod(), responseObserver); - } - - /** - *
-     * An RPC method whose Java name collides with a keyword, and whose generated
-     * method should have a '_' appended.
-     * 
- */ - public io.grpc.stub.StreamObserver import_( - io.grpc.stub.StreamObserver responseObserver) { - return asyncUnimplementedStreamingCall(getImportMethod(), responseObserver); - } - - @java.lang.Override public final io.grpc.ServerServiceDefinition bindService() { - return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()) - .addMethod( - getUnaryCallMethod(), - asyncUnaryCall( - new MethodHandlers< - io.grpc.testing.compiler.nano.Test.SimpleRequest, - io.grpc.testing.compiler.nano.Test.SimpleResponse>( - this, METHODID_UNARY_CALL))) - .addMethod( - getStreamingOutputCallMethod(), - asyncServerStreamingCall( - new MethodHandlers< - io.grpc.testing.compiler.nano.Test.StreamingOutputCallRequest, - io.grpc.testing.compiler.nano.Test.StreamingOutputCallResponse>( - this, METHODID_STREAMING_OUTPUT_CALL))) - .addMethod( - getStreamingInputCallMethod(), - asyncClientStreamingCall( - new MethodHandlers< - io.grpc.testing.compiler.nano.Test.StreamingInputCallRequest, - io.grpc.testing.compiler.nano.Test.StreamingInputCallResponse>( - this, METHODID_STREAMING_INPUT_CALL))) - .addMethod( - getFullBidiCallMethod(), - asyncBidiStreamingCall( - new MethodHandlers< - io.grpc.testing.compiler.nano.Test.StreamingOutputCallRequest, - io.grpc.testing.compiler.nano.Test.StreamingOutputCallResponse>( - this, METHODID_FULL_BIDI_CALL))) - .addMethod( - getHalfBidiCallMethod(), - asyncBidiStreamingCall( - new MethodHandlers< - io.grpc.testing.compiler.nano.Test.StreamingOutputCallRequest, - io.grpc.testing.compiler.nano.Test.StreamingOutputCallResponse>( - this, METHODID_HALF_BIDI_CALL))) - .addMethod( - getImportMethod(), - asyncBidiStreamingCall( - new MethodHandlers< - io.grpc.testing.compiler.nano.Test.StreamingInputCallRequest, - io.grpc.testing.compiler.nano.Test.StreamingInputCallResponse>( - this, METHODID_IMPORT))) - .build(); - } - } - - /** - *
-   * Test service that supports all call types.
-   * 
- */ - public static final class TestServiceStub extends io.grpc.stub.AbstractStub { - private TestServiceStub(io.grpc.Channel channel) { - super(channel); - } - - private TestServiceStub(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - super(channel, callOptions); - } - - @java.lang.Override - protected TestServiceStub build(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - return new TestServiceStub(channel, callOptions); - } - - /** - *
-     * One request followed by one response.
-     * The server returns the client payload as-is.
-     * 
- */ - public void unaryCall(io.grpc.testing.compiler.nano.Test.SimpleRequest request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnaryCall( - getChannel().newCall(getUnaryCallMethod(), getCallOptions()), request, responseObserver); - } - - /** - *
-     * One request followed by a sequence of responses (streamed download).
-     * The server returns the payload with client desired type and sizes.
-     * 
- */ - public void streamingOutputCall(io.grpc.testing.compiler.nano.Test.StreamingOutputCallRequest request, - io.grpc.stub.StreamObserver responseObserver) { - asyncServerStreamingCall( - getChannel().newCall(getStreamingOutputCallMethod(), getCallOptions()), request, responseObserver); - } - - /** - *
-     * A sequence of requests followed by one response (streamed upload).
-     * The server returns the aggregated size of client payload as the result.
-     * 
- */ - public io.grpc.stub.StreamObserver streamingInputCall( - io.grpc.stub.StreamObserver responseObserver) { - return asyncClientStreamingCall( - getChannel().newCall(getStreamingInputCallMethod(), getCallOptions()), responseObserver); - } - - /** - *
-     * A sequence of requests with each request served by the server immediately.
-     * As one request could lead to multiple responses, this interface
-     * demonstrates the idea of full bidirectionality.
-     * 
- */ - public io.grpc.stub.StreamObserver fullBidiCall( - io.grpc.stub.StreamObserver responseObserver) { - return asyncBidiStreamingCall( - getChannel().newCall(getFullBidiCallMethod(), getCallOptions()), responseObserver); - } - - /** - *
-     * A sequence of requests followed by a sequence of responses.
-     * The server buffers all the client requests and then serves them in order. A
-     * stream of responses are returned to the client when the server starts with
-     * first request.
-     * 
- */ - public io.grpc.stub.StreamObserver halfBidiCall( - io.grpc.stub.StreamObserver responseObserver) { - return asyncBidiStreamingCall( - getChannel().newCall(getHalfBidiCallMethod(), getCallOptions()), responseObserver); - } - - /** - *
-     * An RPC method whose Java name collides with a keyword, and whose generated
-     * method should have a '_' appended.
-     * 
- */ - public io.grpc.stub.StreamObserver import_( - io.grpc.stub.StreamObserver responseObserver) { - return asyncBidiStreamingCall( - getChannel().newCall(getImportMethod(), getCallOptions()), responseObserver); - } - } - - /** - *
-   * Test service that supports all call types.
-   * 
- */ - public static final class TestServiceBlockingStub extends io.grpc.stub.AbstractStub { - private TestServiceBlockingStub(io.grpc.Channel channel) { - super(channel); - } - - private TestServiceBlockingStub(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - super(channel, callOptions); - } - - @java.lang.Override - protected TestServiceBlockingStub build(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - return new TestServiceBlockingStub(channel, callOptions); - } - - /** - *
-     * One request followed by one response.
-     * The server returns the client payload as-is.
-     * 
- */ - public io.grpc.testing.compiler.nano.Test.SimpleResponse unaryCall(io.grpc.testing.compiler.nano.Test.SimpleRequest request) { - return blockingUnaryCall( - getChannel(), getUnaryCallMethod(), getCallOptions(), request); - } - - /** - *
-     * One request followed by a sequence of responses (streamed download).
-     * The server returns the payload with client desired type and sizes.
-     * 
- */ - public java.util.Iterator streamingOutputCall( - io.grpc.testing.compiler.nano.Test.StreamingOutputCallRequest request) { - return blockingServerStreamingCall( - getChannel(), getStreamingOutputCallMethod(), getCallOptions(), request); - } - } - - /** - *
-   * Test service that supports all call types.
-   * 
- */ - public static final class TestServiceFutureStub extends io.grpc.stub.AbstractStub { - private TestServiceFutureStub(io.grpc.Channel channel) { - super(channel); - } - - private TestServiceFutureStub(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - super(channel, callOptions); - } - - @java.lang.Override - protected TestServiceFutureStub build(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - return new TestServiceFutureStub(channel, callOptions); - } - - /** - *
-     * One request followed by one response.
-     * The server returns the client payload as-is.
-     * 
- */ - public com.google.common.util.concurrent.ListenableFuture unaryCall( - io.grpc.testing.compiler.nano.Test.SimpleRequest request) { - return futureUnaryCall( - getChannel().newCall(getUnaryCallMethod(), getCallOptions()), request); - } - } - - private static final int METHODID_UNARY_CALL = 0; - private static final int METHODID_STREAMING_OUTPUT_CALL = 1; - private static final int METHODID_STREAMING_INPUT_CALL = 2; - private static final int METHODID_FULL_BIDI_CALL = 3; - private static final int METHODID_HALF_BIDI_CALL = 4; - private static final int METHODID_IMPORT = 5; - - private static final class MethodHandlers implements - io.grpc.stub.ServerCalls.UnaryMethod, - io.grpc.stub.ServerCalls.ServerStreamingMethod, - io.grpc.stub.ServerCalls.ClientStreamingMethod, - io.grpc.stub.ServerCalls.BidiStreamingMethod { - private final TestServiceImplBase serviceImpl; - private final int methodId; - - MethodHandlers(TestServiceImplBase serviceImpl, int methodId) { - this.serviceImpl = serviceImpl; - this.methodId = methodId; - } - - @java.lang.Override - @java.lang.SuppressWarnings("unchecked") - public void invoke(Req request, io.grpc.stub.StreamObserver responseObserver) { - switch (methodId) { - case METHODID_UNARY_CALL: - serviceImpl.unaryCall((io.grpc.testing.compiler.nano.Test.SimpleRequest) request, - (io.grpc.stub.StreamObserver) responseObserver); - break; - case METHODID_STREAMING_OUTPUT_CALL: - serviceImpl.streamingOutputCall((io.grpc.testing.compiler.nano.Test.StreamingOutputCallRequest) request, - (io.grpc.stub.StreamObserver) responseObserver); - break; - default: - throw new AssertionError(); - } - } - - @java.lang.Override - @java.lang.SuppressWarnings("unchecked") - public io.grpc.stub.StreamObserver invoke( - io.grpc.stub.StreamObserver responseObserver) { - switch (methodId) { - case METHODID_STREAMING_INPUT_CALL: - return (io.grpc.stub.StreamObserver) serviceImpl.streamingInputCall( - (io.grpc.stub.StreamObserver) responseObserver); - case METHODID_FULL_BIDI_CALL: - return (io.grpc.stub.StreamObserver) serviceImpl.fullBidiCall( - (io.grpc.stub.StreamObserver) responseObserver); - case METHODID_HALF_BIDI_CALL: - return (io.grpc.stub.StreamObserver) serviceImpl.halfBidiCall( - (io.grpc.stub.StreamObserver) responseObserver); - case METHODID_IMPORT: - return (io.grpc.stub.StreamObserver) serviceImpl.import_( - (io.grpc.stub.StreamObserver) responseObserver); - default: - throw new AssertionError(); - } - } - } - - private static volatile io.grpc.ServiceDescriptor serviceDescriptor; - - public static io.grpc.ServiceDescriptor getServiceDescriptor() { - io.grpc.ServiceDescriptor result = serviceDescriptor; - if (result == null) { - synchronized (TestServiceGrpc.class) { - result = serviceDescriptor; - if (result == null) { - serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME) - .addMethod(getUnaryCallMethod()) - .addMethod(getStreamingOutputCallMethod()) - .addMethod(getStreamingInputCallMethod()) - .addMethod(getFullBidiCallMethod()) - .addMethod(getHalfBidiCallMethod()) - .addMethod(getImportMethod()) - .build(); - } - } - } - return result; - } -} diff --git a/protobuf-nano/BUILD.bazel b/protobuf-nano/BUILD.bazel deleted file mode 100644 index 05ea2c6701..0000000000 --- a/protobuf-nano/BUILD.bazel +++ /dev/null @@ -1,14 +0,0 @@ -java_library( - name = "protobuf_nano", - srcs = glob([ - "src/main/java/**/*.java", - ]), - visibility = ["//visibility:public"], - deps = [ - "//api", - "@com_google_code_findbugs_jsr305//jar", - "@com_google_guava_guava//jar", - "@com_google_j2objc_j2objc_annotations//jar", - "@com_google_protobuf_nano_protobuf_javanano//jar", - ], -) diff --git a/protobuf-nano/build.gradle b/protobuf-nano/build.gradle deleted file mode 100644 index 9064df4bb4..0000000000 --- a/protobuf-nano/build.gradle +++ /dev/null @@ -1,43 +0,0 @@ -// Add dependency on the protobuf plugin -buildscript { - repositories { - maven { // The google mirror is less flaky than mavenCentral() - url "https://maven-central.storage-download.googleapis.com/repos/central/data/" } - } - dependencies { classpath libraries.protobuf_plugin } -} - -description = 'gRPC: Protobuf Nano' - -dependencies { - compile project(':grpc-api'), - libraries.protobuf_nano - compile (libraries.guava) { - // prefer 2.3.2 from libraries instead of 2.1.3 - exclude group: 'com.google.errorprone', module: 'error_prone_annotations' - // prefer 3.0.2 from libraries instead of 3.0.1 - exclude group: 'com.google.code.findbugs', module: 'jsr305' - // prefer 1.17 from libraries instead of 1.14 - exclude group: 'org.codehaus.mojo', module: 'animal-sniffer-annotations' - } - signature "org.codehaus.mojo.signature:java17:1.0@signature" - signature "net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature" -} - -configureProtoCompilation() - -if (project.hasProperty('protobuf')) { - protobuf { - protoc { - artifact = libraries.protoc_nano - } - generateProtoTasks { - all().each { task -> - task.builtins { - remove java - javanano { option 'ignore_services=true' } - } - } - } - } -} diff --git a/protobuf-nano/src/main/java/io/grpc/protobuf/nano/MessageNanoFactory.java b/protobuf-nano/src/main/java/io/grpc/protobuf/nano/MessageNanoFactory.java deleted file mode 100644 index ce2a9b576c..0000000000 --- a/protobuf-nano/src/main/java/io/grpc/protobuf/nano/MessageNanoFactory.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2014 The gRPC Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.grpc.protobuf.nano; - -import com.google.protobuf.nano.MessageNano; - -/** - * Produce new message instances. Used by a marshaller to deserialize incoming messages. - * - *

Should be implemented by generated code. - * - * @since 1.0.0 - */ -public interface MessageNanoFactory { - T newInstance(); -} diff --git a/protobuf-nano/src/main/java/io/grpc/protobuf/nano/NanoProtoInputStream.java b/protobuf-nano/src/main/java/io/grpc/protobuf/nano/NanoProtoInputStream.java deleted file mode 100644 index a684649f5b..0000000000 --- a/protobuf-nano/src/main/java/io/grpc/protobuf/nano/NanoProtoInputStream.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2014 The gRPC Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.grpc.protobuf.nano; - -import com.google.protobuf.nano.CodedOutputByteBufferNano; -import com.google.protobuf.nano.MessageNano; -import io.grpc.KnownLength; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import javax.annotation.Nullable; - -/** - * An {@link InputStream} backed by a nano proto. - */ -final class NanoProtoInputStream extends InputStream implements KnownLength { - - // NanoProtoInputStream is first initialized with a *message*. *partial* is initially null. - // Once there has been a read operation on this stream, *message* is serialized to *partial* and - // set to null. - @Nullable private MessageNano message; - @Nullable private ByteArrayInputStream partial; - - NanoProtoInputStream(MessageNano message) { - this.message = message; - } - - private void toPartial() { - if (message != null) { - partial = new ByteArrayInputStream(MessageNano.toByteArray(message)); - message = null; - } - } - - @Override - public int read() throws IOException { - toPartial(); - if (partial != null) { - return partial.read(); - } - return -1; - } - - @Override - public int read(byte[] b, int off, int len) throws IOException { - if (message != null) { - int size = message.getSerializedSize(); - if (size == 0) { - message = null; - partial = null; - return -1; - } - if (len >= size) { - // This is the only case that is zero-copy. - CodedOutputByteBufferNano output = CodedOutputByteBufferNano.newInstance(b, off, size); - message.writeTo(output); - output.checkNoSpaceLeft(); - - message = null; - partial = null; - return size; - } - - toPartial(); - } - if (partial != null) { - return partial.read(b, off, len); - } - return -1; - } - - @Override - public int available() { - if (message != null) { - return message.getSerializedSize(); - } else if (partial != null) { - return partial.available(); - } - return 0; - } -} diff --git a/protobuf-nano/src/main/java/io/grpc/protobuf/nano/NanoUtils.java b/protobuf-nano/src/main/java/io/grpc/protobuf/nano/NanoUtils.java deleted file mode 100644 index d435409fd9..0000000000 --- a/protobuf-nano/src/main/java/io/grpc/protobuf/nano/NanoUtils.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2014 The gRPC Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.grpc.protobuf.nano; - -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.protobuf.nano.CodedInputByteBufferNano; -import com.google.protobuf.nano.MessageNano; -import io.grpc.MethodDescriptor.Marshaller; -import io.grpc.Status; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -/** - * Utility methods for using nano proto with grpc. - */ -public final class NanoUtils { - - private NanoUtils() {} - - /** - * Adapt {@code parser} to a {@link Marshaller}. - * - * @since 1.0.0 - */ - public static Marshaller marshaller(MessageNanoFactory factory) { - return new MessageMarshaller<>(factory); - } - - private static final class MessageMarshaller implements Marshaller { - private static final int BUF_SIZE = 8192; - - private final MessageNanoFactory factory; - - MessageMarshaller(MessageNanoFactory factory) { - this.factory = factory; - } - - @Override - public InputStream stream(T value) { - return new NanoProtoInputStream(value); - } - - @Override - public T parse(InputStream stream) { - try { - // TODO(simonma): Investigate whether we can do 0-copy here. - CodedInputByteBufferNano input = - CodedInputByteBufferNano.newInstance(toByteArray(stream)); - input.setSizeLimit(Integer.MAX_VALUE); - T message = factory.newInstance(); - message.mergeFrom(input); - return message; - } catch (IOException ipbe) { - throw Status.INTERNAL.withDescription("Failed parsing nano proto message").withCause(ipbe) - .asRuntimeException(); - } - } - - // Copied from guava com.google.common.io.ByteStreams because its API is unstable (beta) - private static byte[] toByteArray(InputStream in) throws IOException { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - copy(in, out); - return out.toByteArray(); - } - - // Copied from guava com.google.common.io.ByteStreams because its API is unstable (beta) - private static long copy(InputStream from, OutputStream to) throws IOException { - checkNotNull(from); - checkNotNull(to); - byte[] buf = new byte[BUF_SIZE]; - long total = 0; - while (true) { - int r = from.read(buf); - if (r == -1) { - break; - } - to.write(buf, 0, r); - total += r; - } - return total; - } - } -} diff --git a/protobuf-nano/src/main/java/io/grpc/protobuf/nano/package-info.java b/protobuf-nano/src/main/java/io/grpc/protobuf/nano/package-info.java deleted file mode 100644 index 08993d8dda..0000000000 --- a/protobuf-nano/src/main/java/io/grpc/protobuf/nano/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2017 The gRPC Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * API for gRPC over Protocol Buffers with proto message classes generated by the JavaNano compiler. - */ - -package io.grpc.protobuf.nano; diff --git a/protobuf-nano/src/test/java/io/grpc/protobuf/nano/NanoUtilsTest.java b/protobuf-nano/src/test/java/io/grpc/protobuf/nano/NanoUtilsTest.java deleted file mode 100644 index 344a5fb264..0000000000 --- a/protobuf-nano/src/test/java/io/grpc/protobuf/nano/NanoUtilsTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright 2015 The gRPC Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.grpc.protobuf.nano; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import com.google.protobuf.nano.InvalidProtocolBufferNanoException; -import com.google.protobuf.nano.MessageNano; -import io.grpc.MethodDescriptor.Marshaller; -import io.grpc.Status; -import io.grpc.StatusRuntimeException; -import io.grpc.protobuf.nano.Messages.Message; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Unit tests for {@link NanoUtils}. */ -@RunWith(JUnit4.class) -public class NanoUtilsTest { - private Marshaller marshaller = NanoUtils.marshaller(new MessageNanoFactory() { - @Override - public Message newInstance() { - return new Message(); - } - }); - - @Test - public void testRoundTrip() { - Message m = new Message(); - m.i = 2; - m.b = true; - m.s = "string"; - Message m2 = marshaller.parse(marshaller.stream(m)); - assertNotSame(m, m2); - assertEquals(2, m2.i); - assertEquals(true, m2.b); - assertEquals("string", m2.s); - assertTrue(MessageNano.messageNanoEquals(m, m2)); - } - - @Test - public void parseInvalid() throws Exception { - InputStream is = new ByteArrayInputStream(new byte[] {-127}); - try { - marshaller.parse(is); - fail("Expected exception"); - } catch (StatusRuntimeException ex) { - assertEquals(Status.Code.INTERNAL, ex.getStatus().getCode()); - assertTrue(ex.getCause() instanceof InvalidProtocolBufferNanoException); - } - } - - @Test - public void testLarge() { - Message m = new Message(); - // The default limit is 64MB. Using a larger proto to verify that the limit is not enforced. - m.bs = new byte[70 * 1024 * 1024]; - Message m2 = marshaller.parse(marshaller.stream(m)); - assertNotSame(m, m2); - // TODO(carl-mastrangelo): assertArrayEquals is REALLY slow, and been fixed in junit4.12. - // Eventually switch back to it once we are using 4.12 everywhere. - // assertArrayEquals(m.bs, m2.bs); - assertEquals(m.bs.length, m2.bs.length); - for (int i = 0; i < m.bs.length; i++) { - assertEquals(m.bs[i], m2.bs[i]); - } - } - - @Test - public void testAvailable() throws Exception { - Message m = new Message(); - m.s = "string"; - InputStream is = marshaller.stream(m); - assertEquals(m.getSerializedSize(), is.available()); - is.read(); - assertEquals(m.getSerializedSize() - 1, is.available()); - while (is.read() != -1) {} - assertEquals(-1, is.read()); - assertEquals(0, is.available()); - } - - @Test - public void testEmpty() throws IOException { - InputStream is = marshaller.stream(new Message()); - assertEquals(0, is.available()); - byte[] b = new byte[10]; - assertEquals(-1, is.read(b)); - assertArrayEquals(new byte[10], b); - // Do the same thing again, because the internal state may be different - assertEquals(-1, is.read(b)); - assertArrayEquals(new byte[10], b); - assertEquals(-1, is.read()); - assertEquals(0, is.available()); - } -} diff --git a/protobuf-nano/src/test/proto/grpc/testing/nano/messages.proto b/protobuf-nano/src/test/proto/grpc/testing/nano/messages.proto deleted file mode 100644 index ca7a70896d..0000000000 --- a/protobuf-nano/src/test/proto/grpc/testing/nano/messages.proto +++ /dev/null @@ -1,26 +0,0 @@ - -// Copyright 2015 The gRPC Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -syntax = "proto3"; - -package grpc.testing.nano; - -option java_package = "io.grpc.protobuf"; - -message Message { - int32 i = 1; - bool b = 2; - string s = 3; - bytes bs = 4; -} diff --git a/repositories.bzl b/repositories.bzl index 0f62512769..c46a7184ae 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -18,7 +18,6 @@ def grpc_java_repositories( omit_com_google_protobuf = False, omit_com_google_protobuf_java = False, omit_com_google_protobuf_javalite = False, - omit_com_google_protobuf_nano_protobuf_javanano = False, omit_com_google_truth_truth = False, omit_com_squareup_okhttp = False, omit_com_squareup_okio = False, @@ -70,8 +69,6 @@ def grpc_java_repositories( fail("omit_com_google_protobuf_java is no longer supported and must be not be passed to grpc_java_repositories()") if not omit_com_google_protobuf_javalite: com_google_protobuf_javalite() - if not omit_com_google_protobuf_nano_protobuf_javanano: - com_google_protobuf_nano_protobuf_javanano() if not omit_com_google_truth_truth: com_google_truth_truth() if not omit_com_squareup_okhttp: @@ -253,15 +250,6 @@ def com_google_protobuf_javalite(): urls = ["https://github.com/google/protobuf/archive/384989534b2246d413dbcd750744faab2607b516.zip"], ) -def com_google_protobuf_nano_protobuf_javanano(): - jvm_maven_import_external( - name = "com_google_protobuf_nano_protobuf_javanano", - artifact = "com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-5", - server_urls = ["http://central.maven.org/maven2"], - artifact_sha256 = "6d30f1e667a8952e1c90a0a125f0ce0edf84d6b1d51c91d8555c4fb549e3d7a1", - licenses = ["notice"], # BSD 2-clause - ) - def com_google_truth_truth(): jvm_maven_import_external( name = "com_google_truth_truth", diff --git a/settings.gradle b/settings.gradle index 9c4c4a2262..a1266d5604 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,7 +7,6 @@ include ":grpc-auth" include ":grpc-okhttp" include ":grpc-protobuf" include ":grpc-protobuf-lite" -include ":grpc-protobuf-nano" include ":grpc-netty" include ":grpc-netty-shaded" include ":grpc-grpclb" @@ -30,7 +29,6 @@ project(':grpc-auth').projectDir = "$rootDir/auth" as File project(':grpc-okhttp').projectDir = "$rootDir/okhttp" as File project(':grpc-protobuf').projectDir = "$rootDir/protobuf" as File project(':grpc-protobuf-lite').projectDir = "$rootDir/protobuf-lite" as File -project(':grpc-protobuf-nano').projectDir = "$rootDir/protobuf-nano" as File project(':grpc-netty').projectDir = "$rootDir/netty" as File project(':grpc-netty-shaded').projectDir = "$rootDir/netty/shaded" as File project(':grpc-grpclb').projectDir = "$rootDir/grpclb" as File