Skip to content

Commit 47a7ccf

Browse files
committed
Avoid Parser for normal protobuf
Eventually, this could avoid allocating Parser, since we can use newBuilderForType().mergeFrom(). This would primarily benefit Lite proto.
1 parent d52a7a2 commit 47a7ccf

11 files changed

Lines changed: 55 additions & 52 deletions

File tree

benchmarks/src/generated/main/grpc/io/grpc/testing/TestServiceGrpc.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ public class TestServiceGrpc {
2626
io.grpc.MethodDescriptor.MethodType.UNARY,
2727
generateFullMethodName(
2828
"grpc.testing.TestService", "UnaryCall"),
29-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.SimpleRequest.parser()),
30-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.SimpleResponse.parser()));
29+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.SimpleRequest.getDefaultInstance()),
30+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.SimpleResponse.getDefaultInstance()));
3131
@io.grpc.ExperimentalApi
3232
public static final io.grpc.MethodDescriptor<io.grpc.testing.SimpleRequest,
3333
io.grpc.testing.SimpleResponse> METHOD_STREAMING_CALL =
3434
io.grpc.MethodDescriptor.create(
3535
io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING,
3636
generateFullMethodName(
3737
"grpc.testing.TestService", "StreamingCall"),
38-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.SimpleRequest.parser()),
39-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.SimpleResponse.parser()));
38+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.SimpleRequest.getDefaultInstance()),
39+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.SimpleResponse.getDefaultInstance()));
4040

4141
public static TestServiceStub newStub(io.grpc.Channel channel) {
4242
return new TestServiceStub(channel);

benchmarks/src/generated/main/grpc/io/grpc/testing/WorkerGrpc.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ public class WorkerGrpc {
2626
io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING,
2727
generateFullMethodName(
2828
"grpc.testing.Worker", "RunTest"),
29-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.ClientArgs.parser()),
30-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.ClientStatus.parser()));
29+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.ClientArgs.getDefaultInstance()),
30+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.ClientStatus.getDefaultInstance()));
3131
@io.grpc.ExperimentalApi
3232
public static final io.grpc.MethodDescriptor<io.grpc.testing.ServerArgs,
3333
io.grpc.testing.ServerStatus> METHOD_RUN_SERVER =
3434
io.grpc.MethodDescriptor.create(
3535
io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING,
3636
generateFullMethodName(
3737
"grpc.testing.Worker", "RunServer"),
38-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.ServerArgs.parser()),
39-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.ServerStatus.parser()));
38+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.ServerArgs.getDefaultInstance()),
39+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.ServerStatus.getDefaultInstance()));
4040

4141
public static WorkerStub newStub(io.grpc.Channel channel) {
4242
return new WorkerStub(channel);

compiler/src/java_plugin/cpp/java_generator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ static void PrintMethodFields(
138138
" $MethodType$.$method_type$,\n"
139139
" generateFullMethodName(\n"
140140
" \"$Package$$service_name$\", \"$method_name$\"),\n"
141-
" $ProtoUtils$.marshaller($input_type$.parser()),\n"
142-
" $ProtoUtils$.marshaller($output_type$.parser()));\n");
141+
" $ProtoUtils$.marshaller($input_type$.getDefaultInstance()),\n"
142+
" $ProtoUtils$.marshaller($output_type$.getDefaultInstance()));\n");
143143
}
144144
}
145145
p->Print("\n");

compiler/src/test/golden/TestService.java.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,44 +26,44 @@ public class TestServiceGrpc {
2626
io.grpc.MethodDescriptor.MethodType.UNARY,
2727
generateFullMethodName(
2828
"grpc.testing.TestService", "UnaryCall"),
29-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Test.SimpleRequest.parser()),
30-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Test.SimpleResponse.parser()));
29+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Test.SimpleRequest.getDefaultInstance()),
30+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Test.SimpleResponse.getDefaultInstance()));
3131
@io.grpc.ExperimentalApi
3232
public static final io.grpc.MethodDescriptor<io.grpc.testing.integration.Test.StreamingOutputCallRequest,
3333
io.grpc.testing.integration.Test.StreamingOutputCallResponse> METHOD_STREAMING_OUTPUT_CALL =
3434
io.grpc.MethodDescriptor.create(
3535
io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING,
3636
generateFullMethodName(
3737
"grpc.testing.TestService", "StreamingOutputCall"),
38-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Test.StreamingOutputCallRequest.parser()),
39-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Test.StreamingOutputCallResponse.parser()));
38+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Test.StreamingOutputCallRequest.getDefaultInstance()),
39+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Test.StreamingOutputCallResponse.getDefaultInstance()));
4040
@io.grpc.ExperimentalApi
4141
public static final io.grpc.MethodDescriptor<io.grpc.testing.integration.Test.StreamingInputCallRequest,
4242
io.grpc.testing.integration.Test.StreamingInputCallResponse> METHOD_STREAMING_INPUT_CALL =
4343
io.grpc.MethodDescriptor.create(
4444
io.grpc.MethodDescriptor.MethodType.CLIENT_STREAMING,
4545
generateFullMethodName(
4646
"grpc.testing.TestService", "StreamingInputCall"),
47-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Test.StreamingInputCallRequest.parser()),
48-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Test.StreamingInputCallResponse.parser()));
47+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Test.StreamingInputCallRequest.getDefaultInstance()),
48+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Test.StreamingInputCallResponse.getDefaultInstance()));
4949
@io.grpc.ExperimentalApi
5050
public static final io.grpc.MethodDescriptor<io.grpc.testing.integration.Test.StreamingOutputCallRequest,
5151
io.grpc.testing.integration.Test.StreamingOutputCallResponse> METHOD_FULL_BIDI_CALL =
5252
io.grpc.MethodDescriptor.create(
5353
io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING,
5454
generateFullMethodName(
5555
"grpc.testing.TestService", "FullBidiCall"),
56-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Test.StreamingOutputCallRequest.parser()),
57-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Test.StreamingOutputCallResponse.parser()));
56+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Test.StreamingOutputCallRequest.getDefaultInstance()),
57+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Test.StreamingOutputCallResponse.getDefaultInstance()));
5858
@io.grpc.ExperimentalApi
5959
public static final io.grpc.MethodDescriptor<io.grpc.testing.integration.Test.StreamingOutputCallRequest,
6060
io.grpc.testing.integration.Test.StreamingOutputCallResponse> METHOD_HALF_BIDI_CALL =
6161
io.grpc.MethodDescriptor.create(
6262
io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING,
6363
generateFullMethodName(
6464
"grpc.testing.TestService", "HalfBidiCall"),
65-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Test.StreamingOutputCallRequest.parser()),
66-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Test.StreamingOutputCallResponse.parser()));
65+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Test.StreamingOutputCallRequest.getDefaultInstance()),
66+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Test.StreamingOutputCallResponse.getDefaultInstance()));
6767

6868
public static TestServiceStub newStub(io.grpc.Channel channel) {
6969
return new TestServiceStub(channel);

examples/src/generated/main/grpc/io/grpc/examples/helloworld/GreeterGrpc.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public class GreeterGrpc {
2626
io.grpc.MethodDescriptor.MethodType.UNARY,
2727
generateFullMethodName(
2828
"helloworld.Greeter", "SayHello"),
29-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.examples.helloworld.HelloRequest.parser()),
30-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.examples.helloworld.HelloResponse.parser()));
29+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.examples.helloworld.HelloRequest.getDefaultInstance()),
30+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.examples.helloworld.HelloResponse.getDefaultInstance()));
3131

3232
public static GreeterStub newStub(io.grpc.Channel channel) {
3333
return new GreeterStub(channel);

examples/src/generated/main/grpc/io/grpc/examples/routeguide/RouteGuideGrpc.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,35 +26,35 @@ public class RouteGuideGrpc {
2626
io.grpc.MethodDescriptor.MethodType.UNARY,
2727
generateFullMethodName(
2828
"routeguide.RouteGuide", "GetFeature"),
29-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.examples.routeguide.Point.parser()),
30-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.examples.routeguide.Feature.parser()));
29+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.examples.routeguide.Point.getDefaultInstance()),
30+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.examples.routeguide.Feature.getDefaultInstance()));
3131
@io.grpc.ExperimentalApi
3232
public static final io.grpc.MethodDescriptor<io.grpc.examples.routeguide.Rectangle,
3333
io.grpc.examples.routeguide.Feature> METHOD_LIST_FEATURES =
3434
io.grpc.MethodDescriptor.create(
3535
io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING,
3636
generateFullMethodName(
3737
"routeguide.RouteGuide", "ListFeatures"),
38-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.examples.routeguide.Rectangle.parser()),
39-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.examples.routeguide.Feature.parser()));
38+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.examples.routeguide.Rectangle.getDefaultInstance()),
39+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.examples.routeguide.Feature.getDefaultInstance()));
4040
@io.grpc.ExperimentalApi
4141
public static final io.grpc.MethodDescriptor<io.grpc.examples.routeguide.Point,
4242
io.grpc.examples.routeguide.RouteSummary> METHOD_RECORD_ROUTE =
4343
io.grpc.MethodDescriptor.create(
4444
io.grpc.MethodDescriptor.MethodType.CLIENT_STREAMING,
4545
generateFullMethodName(
4646
"routeguide.RouteGuide", "RecordRoute"),
47-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.examples.routeguide.Point.parser()),
48-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.examples.routeguide.RouteSummary.parser()));
47+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.examples.routeguide.Point.getDefaultInstance()),
48+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.examples.routeguide.RouteSummary.getDefaultInstance()));
4949
@io.grpc.ExperimentalApi
5050
public static final io.grpc.MethodDescriptor<io.grpc.examples.routeguide.RouteNote,
5151
io.grpc.examples.routeguide.RouteNote> METHOD_ROUTE_CHAT =
5252
io.grpc.MethodDescriptor.create(
5353
io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING,
5454
generateFullMethodName(
5555
"routeguide.RouteGuide", "RouteChat"),
56-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.examples.routeguide.RouteNote.parser()),
57-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.examples.routeguide.RouteNote.parser()));
56+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.examples.routeguide.RouteNote.getDefaultInstance()),
57+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.examples.routeguide.RouteNote.getDefaultInstance()));
5858

5959
public static RouteGuideStub newStub(io.grpc.Channel channel) {
6060
return new RouteGuideStub(channel);

interop-testing/src/generated/main/grpc/io/grpc/testing/integration/ReconnectServiceGrpc.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ public class ReconnectServiceGrpc {
2626
io.grpc.MethodDescriptor.MethodType.UNARY,
2727
generateFullMethodName(
2828
"grpc.testing.ReconnectService", "Start"),
29-
io.grpc.protobuf.ProtoUtils.marshaller(com.google.protobuf.EmptyProtos.Empty.parser()),
30-
io.grpc.protobuf.ProtoUtils.marshaller(com.google.protobuf.EmptyProtos.Empty.parser()));
29+
io.grpc.protobuf.ProtoUtils.marshaller(com.google.protobuf.EmptyProtos.Empty.getDefaultInstance()),
30+
io.grpc.protobuf.ProtoUtils.marshaller(com.google.protobuf.EmptyProtos.Empty.getDefaultInstance()));
3131
@io.grpc.ExperimentalApi
3232
public static final io.grpc.MethodDescriptor<com.google.protobuf.EmptyProtos.Empty,
3333
io.grpc.testing.integration.Messages.ReconnectInfo> METHOD_STOP =
3434
io.grpc.MethodDescriptor.create(
3535
io.grpc.MethodDescriptor.MethodType.UNARY,
3636
generateFullMethodName(
3737
"grpc.testing.ReconnectService", "Stop"),
38-
io.grpc.protobuf.ProtoUtils.marshaller(com.google.protobuf.EmptyProtos.Empty.parser()),
39-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.ReconnectInfo.parser()));
38+
io.grpc.protobuf.ProtoUtils.marshaller(com.google.protobuf.EmptyProtos.Empty.getDefaultInstance()),
39+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.ReconnectInfo.getDefaultInstance()));
4040

4141
public static ReconnectServiceStub newStub(io.grpc.Channel channel) {
4242
return new ReconnectServiceStub(channel);

interop-testing/src/generated/main/grpc/io/grpc/testing/integration/TestServiceGrpc.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,53 +26,53 @@ public class TestServiceGrpc {
2626
io.grpc.MethodDescriptor.MethodType.UNARY,
2727
generateFullMethodName(
2828
"grpc.testing.TestService", "EmptyCall"),
29-
io.grpc.protobuf.ProtoUtils.marshaller(com.google.protobuf.EmptyProtos.Empty.parser()),
30-
io.grpc.protobuf.ProtoUtils.marshaller(com.google.protobuf.EmptyProtos.Empty.parser()));
29+
io.grpc.protobuf.ProtoUtils.marshaller(com.google.protobuf.EmptyProtos.Empty.getDefaultInstance()),
30+
io.grpc.protobuf.ProtoUtils.marshaller(com.google.protobuf.EmptyProtos.Empty.getDefaultInstance()));
3131
@io.grpc.ExperimentalApi
3232
public static final io.grpc.MethodDescriptor<io.grpc.testing.integration.Messages.SimpleRequest,
3333
io.grpc.testing.integration.Messages.SimpleResponse> METHOD_UNARY_CALL =
3434
io.grpc.MethodDescriptor.create(
3535
io.grpc.MethodDescriptor.MethodType.UNARY,
3636
generateFullMethodName(
3737
"grpc.testing.TestService", "UnaryCall"),
38-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.SimpleRequest.parser()),
39-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.SimpleResponse.parser()));
38+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.SimpleRequest.getDefaultInstance()),
39+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.SimpleResponse.getDefaultInstance()));
4040
@io.grpc.ExperimentalApi
4141
public static final io.grpc.MethodDescriptor<io.grpc.testing.integration.Messages.StreamingOutputCallRequest,
4242
io.grpc.testing.integration.Messages.StreamingOutputCallResponse> METHOD_STREAMING_OUTPUT_CALL =
4343
io.grpc.MethodDescriptor.create(
4444
io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING,
4545
generateFullMethodName(
4646
"grpc.testing.TestService", "StreamingOutputCall"),
47-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.StreamingOutputCallRequest.parser()),
48-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.StreamingOutputCallResponse.parser()));
47+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.StreamingOutputCallRequest.getDefaultInstance()),
48+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.StreamingOutputCallResponse.getDefaultInstance()));
4949
@io.grpc.ExperimentalApi
5050
public static final io.grpc.MethodDescriptor<io.grpc.testing.integration.Messages.StreamingInputCallRequest,
5151
io.grpc.testing.integration.Messages.StreamingInputCallResponse> METHOD_STREAMING_INPUT_CALL =
5252
io.grpc.MethodDescriptor.create(
5353
io.grpc.MethodDescriptor.MethodType.CLIENT_STREAMING,
5454
generateFullMethodName(
5555
"grpc.testing.TestService", "StreamingInputCall"),
56-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.StreamingInputCallRequest.parser()),
57-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.StreamingInputCallResponse.parser()));
56+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.StreamingInputCallRequest.getDefaultInstance()),
57+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.StreamingInputCallResponse.getDefaultInstance()));
5858
@io.grpc.ExperimentalApi
5959
public static final io.grpc.MethodDescriptor<io.grpc.testing.integration.Messages.StreamingOutputCallRequest,
6060
io.grpc.testing.integration.Messages.StreamingOutputCallResponse> METHOD_FULL_DUPLEX_CALL =
6161
io.grpc.MethodDescriptor.create(
6262
io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING,
6363
generateFullMethodName(
6464
"grpc.testing.TestService", "FullDuplexCall"),
65-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.StreamingOutputCallRequest.parser()),
66-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.StreamingOutputCallResponse.parser()));
65+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.StreamingOutputCallRequest.getDefaultInstance()),
66+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.StreamingOutputCallResponse.getDefaultInstance()));
6767
@io.grpc.ExperimentalApi
6868
public static final io.grpc.MethodDescriptor<io.grpc.testing.integration.Messages.StreamingOutputCallRequest,
6969
io.grpc.testing.integration.Messages.StreamingOutputCallResponse> METHOD_HALF_DUPLEX_CALL =
7070
io.grpc.MethodDescriptor.create(
7171
io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING,
7272
generateFullMethodName(
7373
"grpc.testing.TestService", "HalfDuplexCall"),
74-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.StreamingOutputCallRequest.parser()),
75-
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.StreamingOutputCallResponse.parser()));
74+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.StreamingOutputCallRequest.getDefaultInstance()),
75+
io.grpc.protobuf.ProtoUtils.marshaller(io.grpc.testing.integration.Messages.StreamingOutputCallResponse.getDefaultInstance()));
7676

7777
public static TestServiceStub newStub(io.grpc.Channel channel) {
7878
return new TestServiceStub(channel);

interop-testing/src/generated/main/grpc/io/grpc/testing/integration/UnimplementedServiceGrpc.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public class UnimplementedServiceGrpc {
2626
io.grpc.MethodDescriptor.MethodType.UNARY,
2727
generateFullMethodName(
2828
"grpc.testing.UnimplementedService", "UnimplementedCall"),
29-
io.grpc.protobuf.ProtoUtils.marshaller(com.google.protobuf.EmptyProtos.Empty.parser()),
30-
io.grpc.protobuf.ProtoUtils.marshaller(com.google.protobuf.EmptyProtos.Empty.parser()));
29+
io.grpc.protobuf.ProtoUtils.marshaller(com.google.protobuf.EmptyProtos.Empty.getDefaultInstance()),
30+
io.grpc.protobuf.ProtoUtils.marshaller(com.google.protobuf.EmptyProtos.Empty.getDefaultInstance()));
3131

3232
public static UnimplementedServiceStub newStub(io.grpc.Channel channel) {
3333
return new UnimplementedServiceStub(channel);

protobuf/src/main/java/io/grpc/protobuf/ProtoUtils.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@
4848
*/
4949
public class ProtoUtils {
5050

51-
/** Adapt a {@code Parser} to a {@code Marshaller}. */
52-
public static <T extends MessageLite> Marshaller<T> marshaller(final Parser<T> parser) {
51+
/** Create a {@code Marshaller} for protos of the same type as {@code defaultInstance}. */
52+
public static <T extends MessageLite> Marshaller<T> marshaller(final T defaultInstance) {
53+
Parser<?> parserGeneric = defaultInstance.getParserForType();
54+
@SuppressWarnings("unchecked")
55+
final Parser<T> parser = (Parser<T>) parserGeneric;
5356
return new Marshaller<T>() {
5457
@Override
5558
public InputStream stream(T value) {

0 commit comments

Comments
 (0)