From 05bb6a5d08831df7aa1995936d305792d2a86a9b Mon Sep 17 00:00:00 2001 From: Jakob Andersen Date: Wed, 23 Aug 2017 12:47:48 +0200 Subject: [PATCH] Update generated code using latest protoc_plugin. (#30) Preparation for updating the call generation logic. --- .../lib/src/generated/metadata.pb.dart | 4 +- example/route_guide/README.md | 2 +- .../lib/src/generated/route_guide.pb.dart | 26 ++++--- .../lib/src/generated/route_guide.pbgrpc.dart | 26 +++---- interop/lib/src/generated/messages.pb.dart | 68 +++++++++---------- interop/lib/src/generated/test.pbgrpc.dart | 48 ++++++------- lib/src/client.dart | 2 +- 7 files changed, 84 insertions(+), 92 deletions(-) diff --git a/example/metadata/lib/src/generated/metadata.pb.dart b/example/metadata/lib/src/generated/metadata.pb.dart index 960b012..00940d8 100644 --- a/example/metadata/lib/src/generated/metadata.pb.dart +++ b/example/metadata/lib/src/generated/metadata.pb.dart @@ -12,7 +12,7 @@ import 'package:protobuf/protobuf.dart'; class Record extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('Record') - ..a/**/(1, 'value', PbFieldType.OS) + ..a(1, 'value', PbFieldType.OS) ..hasRequiredFields = false; Record() : super(); @@ -48,7 +48,7 @@ class _ReadonlyRecord extends Record with ReadonlyMessageMixin {} class Number extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('Number') - ..a/**/(1, 'value', PbFieldType.O3) + ..a(1, 'value', PbFieldType.O3) ..hasRequiredFields = false; Number() : super(); diff --git a/example/route_guide/README.md b/example/route_guide/README.md index f49cfa6..f703d22 100644 --- a/example/route_guide/README.md +++ b/example/route_guide/README.md @@ -29,7 +29,7 @@ $ dart bin/client.dart If you have made changes to the message or service definition in `protos/route_guide.proto` and need to regenerate the corresponding Dart files, you will need to have protoc version 3.0.0 or higher and the Dart protoc plugin -version 0.7.3 or higher on your PATH. +version 0.7.6 or higher on your PATH. To install protoc, see the instructions on [the Protocol Buffers website](https://developers.google.com/protocol-buffers/). diff --git a/example/route_guide/lib/src/generated/route_guide.pb.dart b/example/route_guide/lib/src/generated/route_guide.pb.dart index 64e9183..7986de0 100644 --- a/example/route_guide/lib/src/generated/route_guide.pb.dart +++ b/example/route_guide/lib/src/generated/route_guide.pb.dart @@ -12,8 +12,8 @@ import 'package:protobuf/protobuf.dart'; class Point extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('Point') - ..a/**/(1, 'latitude', PbFieldType.O3) - ..a/**/(2, 'longitude', PbFieldType.O3) + ..a(1, 'latitude', PbFieldType.O3) + ..a(2, 'longitude', PbFieldType.O3) ..hasRequiredFields = false; Point() : super(); @@ -56,8 +56,8 @@ class _ReadonlyPoint extends Point with ReadonlyMessageMixin {} class Rectangle extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('Rectangle') - ..a/**/(1, 'lo', PbFieldType.OM, Point.getDefault, Point.create) - ..a/**/(2, 'hi', PbFieldType.OM, Point.getDefault, Point.create) + ..a(1, 'lo', PbFieldType.OM, Point.getDefault, Point.create) + ..a(2, 'hi', PbFieldType.OM, Point.getDefault, Point.create) ..hasRequiredFields = false; Rectangle() : super(); @@ -101,9 +101,8 @@ class _ReadonlyRectangle extends Rectangle with ReadonlyMessageMixin {} class Feature extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('Feature') - ..a/**/(1, 'name', PbFieldType.OS) - ..a/**/( - 2, 'location', PbFieldType.OM, Point.getDefault, Point.create) + ..a(1, 'name', PbFieldType.OS) + ..a(2, 'location', PbFieldType.OM, Point.getDefault, Point.create) ..hasRequiredFields = false; Feature() : super(); @@ -147,9 +146,8 @@ class _ReadonlyFeature extends Feature with ReadonlyMessageMixin {} class RouteNote extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('RouteNote') - ..a/**/( - 1, 'location', PbFieldType.OM, Point.getDefault, Point.create) - ..a/**/(2, 'message', PbFieldType.OS) + ..a(1, 'location', PbFieldType.OM, Point.getDefault, Point.create) + ..a(2, 'message', PbFieldType.OS) ..hasRequiredFields = false; RouteNote() : super(); @@ -193,10 +191,10 @@ class _ReadonlyRouteNote extends RouteNote with ReadonlyMessageMixin {} class RouteSummary extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('RouteSummary') - ..a/**/(1, 'pointCount', PbFieldType.O3) - ..a/**/(2, 'featureCount', PbFieldType.O3) - ..a/**/(3, 'distance', PbFieldType.O3) - ..a/**/(4, 'elapsedTime', PbFieldType.O3) + ..a(1, 'pointCount', PbFieldType.O3) + ..a(2, 'featureCount', PbFieldType.O3) + ..a(3, 'distance', PbFieldType.O3) + ..a(4, 'elapsedTime', PbFieldType.O3) ..hasRequiredFields = false; RouteSummary() : super(); diff --git a/example/route_guide/lib/src/generated/route_guide.pbgrpc.dart b/example/route_guide/lib/src/generated/route_guide.pbgrpc.dart index aa7d563..46d5072 100644 --- a/example/route_guide/lib/src/generated/route_guide.pbgrpc.dart +++ b/example/route_guide/lib/src/generated/route_guide.pbgrpc.dart @@ -12,9 +12,7 @@ import 'package:grpc/grpc.dart'; import 'route_guide.pb.dart'; export 'route_guide.pb.dart'; -class RouteGuideClient { - final ClientChannel _channel; - +class RouteGuideClient extends Client { static final _$getFeature = new ClientMethod( '/routeguide.RouteGuide/GetFeature', (Point value) => value.writeToBuffer(), @@ -32,32 +30,36 @@ class RouteGuideClient { (RouteNote value) => value.writeToBuffer(), (List value) => new RouteNote.fromBuffer(value)); - RouteGuideClient(this._channel); + RouteGuideClient(ClientChannel channel, {CallOptions options}) + : super(channel, options: options); - ResponseFuture getFeature(Point request) { - final call = new ClientCall(_channel, _$getFeature); + ResponseFuture getFeature(Point request, {CallOptions options}) { + final call = $createCall(_$getFeature, options: options); call.request ..add(request) ..close(); return new ResponseFuture(call); } - ResponseStream listFeatures(Rectangle request) { - final call = new ClientCall(_channel, _$listFeatures); + ResponseStream listFeatures(Rectangle request, + {CallOptions options}) { + final call = $createCall(_$listFeatures, options: options); call.request ..add(request) ..close(); return new ResponseStream(call); } - ResponseFuture recordRoute(Stream request) { - final call = new ClientCall(_channel, _$recordRoute); + ResponseFuture recordRoute(Stream request, + {CallOptions options}) { + final call = $createCall(_$recordRoute, options: options); request.pipe(call.request); return new ResponseFuture(call); } - ResponseStream routeChat(Stream request) { - final call = new ClientCall(_channel, _$routeChat); + ResponseStream routeChat(Stream request, + {CallOptions options}) { + final call = $createCall(_$routeChat, options: options); request.pipe(call.request); return new ResponseStream(call); } diff --git a/interop/lib/src/generated/messages.pb.dart b/interop/lib/src/generated/messages.pb.dart index 973c655..def9e61 100644 --- a/interop/lib/src/generated/messages.pb.dart +++ b/interop/lib/src/generated/messages.pb.dart @@ -16,7 +16,7 @@ export 'messages.pbenum.dart'; class BoolValue extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('BoolValue') - ..a/**/(1, 'value', PbFieldType.OB) + ..a(1, 'value', PbFieldType.OB) ..hasRequiredFields = false; BoolValue() : super(); @@ -52,9 +52,9 @@ class _ReadonlyBoolValue extends BoolValue with ReadonlyMessageMixin {} class Payload extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('Payload') - ..e/**/(1, 'type', PbFieldType.OE, PayloadType.COMPRESSABLE, + ..e(1, 'type', PbFieldType.OE, PayloadType.COMPRESSABLE, PayloadType.valueOf) - ..a/*>*/(2, 'body', PbFieldType.OY) + ..a>(2, 'body', PbFieldType.OY) ..hasRequiredFields = false; Payload() : super(); @@ -98,8 +98,8 @@ class _ReadonlyPayload extends Payload with ReadonlyMessageMixin {} class EchoStatus extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('EchoStatus') - ..a/**/(1, 'code', PbFieldType.O3) - ..a/**/(2, 'message', PbFieldType.OS) + ..a(1, 'code', PbFieldType.O3) + ..a(2, 'message', PbFieldType.OS) ..hasRequiredFields = false; EchoStatus() : super(); @@ -143,19 +143,19 @@ class _ReadonlyEchoStatus extends EchoStatus with ReadonlyMessageMixin {} class SimpleRequest extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('SimpleRequest') - ..e/**/(1, 'responseType', PbFieldType.OE, + ..e(1, 'responseType', PbFieldType.OE, PayloadType.COMPRESSABLE, PayloadType.valueOf) - ..a/**/(2, 'responseSize', PbFieldType.O3) - ..a/**/( + ..a(2, 'responseSize', PbFieldType.O3) + ..a( 3, 'payload', PbFieldType.OM, Payload.getDefault, Payload.create) - ..a/**/(4, 'fillUsername', PbFieldType.OB) - ..a/**/(5, 'fillOauthScope', PbFieldType.OB) - ..a/**/(6, 'responseCompressed', PbFieldType.OM, - BoolValue.getDefault, BoolValue.create) - ..a/**/(7, 'responseStatus', PbFieldType.OM, - EchoStatus.getDefault, EchoStatus.create) - ..a/**/(8, 'expectCompressed', PbFieldType.OM, + ..a(4, 'fillUsername', PbFieldType.OB) + ..a(5, 'fillOauthScope', PbFieldType.OB) + ..a(6, 'responseCompressed', PbFieldType.OM, BoolValue.getDefault, BoolValue.create) + ..a(7, 'responseStatus', PbFieldType.OM, EchoStatus.getDefault, + EchoStatus.create) + ..a(8, 'expectCompressed', PbFieldType.OM, BoolValue.getDefault, + BoolValue.create) ..hasRequiredFields = false; SimpleRequest() : super(); @@ -249,10 +249,10 @@ class _ReadonlySimpleRequest extends SimpleRequest with ReadonlyMessageMixin {} class SimpleResponse extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('SimpleResponse') - ..a/**/( + ..a( 1, 'payload', PbFieldType.OM, Payload.getDefault, Payload.create) - ..a/**/(2, 'username', PbFieldType.OS) - ..a/**/(3, 'oauthScope', PbFieldType.OS) + ..a(2, 'username', PbFieldType.OS) + ..a(3, 'oauthScope', PbFieldType.OS) ..hasRequiredFields = false; SimpleResponse() : super(); @@ -308,10 +308,10 @@ class _ReadonlySimpleResponse extends SimpleResponse with ReadonlyMessageMixin { class StreamingInputCallRequest extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('StreamingInputCallRequest') - ..a/**/( + ..a( 1, 'payload', PbFieldType.OM, Payload.getDefault, Payload.create) - ..a/**/(2, 'expectCompressed', PbFieldType.OM, - BoolValue.getDefault, BoolValue.create) + ..a(2, 'expectCompressed', PbFieldType.OM, BoolValue.getDefault, + BoolValue.create) ..hasRequiredFields = false; StreamingInputCallRequest() : super(); @@ -361,7 +361,7 @@ class _ReadonlyStreamingInputCallRequest extends StreamingInputCallRequest class StreamingInputCallResponse extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('StreamingInputCallResponse') - ..a/**/(1, 'aggregatedPayloadSize', PbFieldType.O3) + ..a(1, 'aggregatedPayloadSize', PbFieldType.O3) ..hasRequiredFields = false; StreamingInputCallResponse() : super(); @@ -404,9 +404,9 @@ class _ReadonlyStreamingInputCallResponse extends StreamingInputCallResponse class ResponseParameters extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('ResponseParameters') - ..a/**/(1, 'size', PbFieldType.O3) - ..a/**/(2, 'intervalUs', PbFieldType.O3) - ..a/**/( + ..a(1, 'size', PbFieldType.O3) + ..a(2, 'intervalUs', PbFieldType.O3) + ..a( 3, 'compressed', PbFieldType.OM, BoolValue.getDefault, BoolValue.create) ..hasRequiredFields = false; @@ -464,14 +464,14 @@ class _ReadonlyResponseParameters extends ResponseParameters class StreamingOutputCallRequest extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('StreamingOutputCallRequest') - ..e/**/(1, 'responseType', PbFieldType.OE, + ..e(1, 'responseType', PbFieldType.OE, PayloadType.COMPRESSABLE, PayloadType.valueOf) - ..pp/**/(2, 'responseParameters', PbFieldType.PM, + ..pp(2, 'responseParameters', PbFieldType.PM, ResponseParameters.$checkItem, ResponseParameters.create) - ..a/**/( + ..a( 3, 'payload', PbFieldType.OM, Payload.getDefault, Payload.create) - ..a/**/(7, 'responseStatus', PbFieldType.OM, - EchoStatus.getDefault, EchoStatus.create) + ..a(7, 'responseStatus', PbFieldType.OM, EchoStatus.getDefault, + EchoStatus.create) ..hasRequiredFields = false; StreamingOutputCallRequest() : super(); @@ -532,7 +532,7 @@ class _ReadonlyStreamingOutputCallRequest extends StreamingOutputCallRequest class StreamingOutputCallResponse extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('StreamingOutputCallResponse') - ..a/**/( + ..a( 1, 'payload', PbFieldType.OM, Payload.getDefault, Payload.create) ..hasRequiredFields = false; @@ -576,7 +576,7 @@ class _ReadonlyStreamingOutputCallResponse extends StreamingOutputCallResponse class ReconnectParams extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('ReconnectParams') - ..a/**/(1, 'maxReconnectBackoffMs', PbFieldType.O3) + ..a(1, 'maxReconnectBackoffMs', PbFieldType.O3) ..hasRequiredFields = false; ReconnectParams() : super(); @@ -616,8 +616,8 @@ class _ReadonlyReconnectParams extends ReconnectParams class ReconnectInfo extends GeneratedMessage { static final BuilderInfo _i = new BuilderInfo('ReconnectInfo') - ..a/**/(1, 'passed', PbFieldType.OB) - ..p/**/(2, 'backoffMs', PbFieldType.P3) + ..a(1, 'passed', PbFieldType.OB) + ..p(2, 'backoffMs', PbFieldType.P3) ..hasRequiredFields = false; ReconnectInfo() : super(); diff --git a/interop/lib/src/generated/test.pbgrpc.dart b/interop/lib/src/generated/test.pbgrpc.dart index ee5e348..84be978 100644 --- a/interop/lib/src/generated/test.pbgrpc.dart +++ b/interop/lib/src/generated/test.pbgrpc.dart @@ -13,9 +13,7 @@ import 'empty.pb.dart'; import 'messages.pb.dart'; export 'test.pb.dart'; -class TestServiceClient { - final ClientChannel _channel; - +class TestServiceClient extends Client { static final _$emptyCall = new ClientMethod( '/grpc.testing.TestService/EmptyCall', (Empty value) => value.writeToBuffer(), @@ -58,10 +56,11 @@ class TestServiceClient { (Empty value) => value.writeToBuffer(), (List value) => new Empty.fromBuffer(value)); - TestServiceClient(this._channel); + TestServiceClient(ClientChannel channel, {CallOptions options}) + : super(channel, options: options); ResponseFuture emptyCall(Empty request, {CallOptions options}) { - final call = new ClientCall(_channel, _$emptyCall, options: options); + final call = $createCall(_$emptyCall, options: options); call.request ..add(request) ..close(); @@ -70,7 +69,7 @@ class TestServiceClient { ResponseFuture unaryCall(SimpleRequest request, {CallOptions options}) { - final call = new ClientCall(_channel, _$unaryCall, options: options); + final call = $createCall(_$unaryCall, options: options); call.request ..add(request) ..close(); @@ -79,8 +78,7 @@ class TestServiceClient { ResponseFuture cacheableUnaryCall(SimpleRequest request, {CallOptions options}) { - final call = - new ClientCall(_channel, _$cacheableUnaryCall, options: options); + final call = $createCall(_$cacheableUnaryCall, options: options); call.request ..add(request) ..close(); @@ -90,8 +88,7 @@ class TestServiceClient { ResponseStream streamingOutputCall( StreamingOutputCallRequest request, {CallOptions options}) { - final call = - new ClientCall(_channel, _$streamingOutputCall, options: options); + final call = $createCall(_$streamingOutputCall, options: options); call.request ..add(request) ..close(); @@ -101,8 +98,7 @@ class TestServiceClient { ResponseFuture streamingInputCall( Stream request, {CallOptions options}) { - final call = - new ClientCall(_channel, _$streamingInputCall, options: options); + final call = $createCall(_$streamingInputCall, options: options); request.pipe(call.request); return new ResponseFuture(call); } @@ -110,7 +106,7 @@ class TestServiceClient { ResponseStream fullDuplexCall( Stream request, {CallOptions options}) { - final call = new ClientCall(_channel, _$fullDuplexCall, options: options); + final call = $createCall(_$fullDuplexCall, options: options); request.pipe(call.request); return new ResponseStream(call); } @@ -118,15 +114,14 @@ class TestServiceClient { ResponseStream halfDuplexCall( Stream request, {CallOptions options}) { - final call = new ClientCall(_channel, _$halfDuplexCall, options: options); + final call = $createCall(_$halfDuplexCall, options: options); request.pipe(call.request); return new ResponseStream(call); } ResponseFuture unimplementedCall(Empty request, {CallOptions options}) { - final call = - new ClientCall(_channel, _$unimplementedCall, options: options); + final call = $createCall(_$unimplementedCall, options: options); call.request ..add(request) ..close(); @@ -222,20 +217,18 @@ abstract class TestServiceBase extends Service { ServiceCall call, Stream request); } -class UnimplementedServiceClient { - final ClientChannel _channel; - +class UnimplementedServiceClient extends Client { static final _$unimplementedCall = new ClientMethod( '/grpc.testing.UnimplementedService/UnimplementedCall', (Empty value) => value.writeToBuffer(), (List value) => new Empty.fromBuffer(value)); - UnimplementedServiceClient(this._channel); + UnimplementedServiceClient(ClientChannel channel, {CallOptions options}) + : super(channel, options: options); ResponseFuture unimplementedCall(Empty request, {CallOptions options}) { - final call = - new ClientCall(_channel, _$unimplementedCall, options: options); + final call = $createCall(_$unimplementedCall, options: options); call.request ..add(request) ..close(); @@ -264,9 +257,7 @@ abstract class UnimplementedServiceBase extends Service { Future unimplementedCall(ServiceCall call, Empty request); } -class ReconnectServiceClient { - final ClientChannel _channel; - +class ReconnectServiceClient extends Client { static final _$start = new ClientMethod( '/grpc.testing.ReconnectService/Start', (ReconnectParams value) => value.writeToBuffer(), @@ -276,10 +267,11 @@ class ReconnectServiceClient { (Empty value) => value.writeToBuffer(), (List value) => new ReconnectInfo.fromBuffer(value)); - ReconnectServiceClient(this._channel); + ReconnectServiceClient(ClientChannel channel, {CallOptions options}) + : super(channel, options: options); ResponseFuture start(ReconnectParams request, {CallOptions options}) { - final call = new ClientCall(_channel, _$start, options: options); + final call = $createCall(_$start, options: options); call.request ..add(request) ..close(); @@ -287,7 +279,7 @@ class ReconnectServiceClient { } ResponseFuture stop(Empty request, {CallOptions options}) { - final call = new ClientCall(_channel, _$stop, options: options); + final call = $createCall(_$stop, options: options); call.request ..add(request) ..close(); diff --git a/lib/src/client.dart b/lib/src/client.dart index 41198d9..f940af6 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -64,7 +64,7 @@ class ClientChannel { {this.port = 443, this.options = const ChannelOptions()}); /// Returns a connection to this [Channel]'s RPC endpoint. The connection may - /// be shared between multiple RPC calls. + /// be shared between multiple RPCs. Future connect() async { final securityContext = options.securityContext;