diff options
Diffstat (limited to 'examples/csharp/route_guide')
16 files changed, 806 insertions, 2027 deletions
diff --git a/examples/csharp/route_guide/.nuget/packages.config b/examples/csharp/route_guide/.nuget/packages.config index b14373069f..e2879c1893 100644 --- a/examples/csharp/route_guide/.nuget/packages.config +++ b/examples/csharp/route_guide/.nuget/packages.config @@ -1,4 +1,4 @@ <?xml version="1.0" encoding="utf-8"?> <packages> - <package id="Grpc.Tools" version="0.6.0" /> + <package id="Grpc.Tools" version="0.7.0" /> </packages>
\ No newline at end of file diff --git a/examples/csharp/route_guide/README.md b/examples/csharp/route_guide/README.md index ec9a0c048e..155877e62e 100644 --- a/examples/csharp/route_guide/README.md +++ b/examples/csharp/route_guide/README.md @@ -93,16 +93,16 @@ message Point { Next we need to generate the gRPC client and server interfaces from our .proto service definition. We do this using the protocol buffer compiler `protoc` with a special gRPC C# plugin. If you want to run this yourself, make sure you've installed protoc and gRPC C# plugin. The instructions vary based on your OS: -- For Windows, the `Grpc.Tools` NuGet package contains the binaries you will need to generate the code. +- For Windows, the `Grpc.Tools` and `Google.Protobuf` NuGet packages contain the binaries you will need to generate the code. - For Linux, make sure you've [installed gRPC C Core using Linuxbrew](https://github.com/grpc/grpc/tree/master/src/csharp#usage-linux-mono) - For MacOS, make sure you've [installed gRPC C Core using Homebrew](https://github.com/grpc/grpc/tree/master/src/csharp#usage-macos-mono) Once that's done, the following command can be used to generate the C# code. -To generate the code on Windows, we use `protoc.exe` and `grpc_csharp_plugin.exe` binaries that are shipped with the `Grpc.Tools` NuGet package under the `tools` directory. +To generate the code on Windows, we use `protoc.exe` from the `Google.Protobuf` NuGet package and `grpc_csharp_plugin.exe` from the `Grpc.Tools` NuGet package (both under the `tools` directory). Normally you would need to add the `Grpc.Tools` package to the solution yourself, but in this tutorial it has been already done for you. Following command should be run from the `csharp/route_guide` directory: ``` -> packages\Grpc.Tools.0.5.1\tools\protoc -I RouteGuide/protos --csharp_out=RouteGuide --grpc_out=RouteGuide --plugin=protoc-gen-grpc=packages\Grpc.Tools.0.5.1\tools\grpc_csharp_plugin.exe RouteGuide/protos/route_guide.proto +> packages\Google.Protobuf.3.0.0-alpha4\tools\protoc -I RouteGuide/protos --csharp_out=RouteGuide --grpc_out=RouteGuide --plugin=protoc-gen-grpc=packages\Grpc.Tools.0.7.0\tools\grpc_csharp_plugin.exe RouteGuide/protos/route_guide.proto ``` On Linux/MacOS, we rely on `protoc` and `grpc_csharp_plugin` being installed by Linuxbrew/Homebrew. Run this command from the route_guide directory: @@ -143,7 +143,7 @@ public class RouteGuideImpl : RouteGuide.IRouteGuide `RouteGuideImpl` implements all our service methods. Let's look at the simplest type first, `GetFeature`, which just gets a `Point` from the client and returns the corresponding feature information from its database in a `Feature`. ```csharp - public Task<Feature> GetFeature(Grpc.Core.ServerCallContext context, Point request) + public Task<Feature> GetFeature(Point request, Grpc.Core.ServerCallContext context) { return Task.FromResult(CheckFeature(request)); } @@ -159,27 +159,14 @@ Now let's look at something a bit more complicated - a streaming RPC. `ListFeatu ```csharp // in RouteGuideImpl - public async Task ListFeatures(Grpc.Core.ServerCallContext context, Rectangle request, - Grpc.Core.IServerStreamWriter<Feature> responseStream) + public async Task ListFeatures(Rectangle request, + Grpc.Core.IServerStreamWriter<Feature> responseStream, + Grpc.Core.ServerCallContext context) { - int left = Math.Min(request.Lo.Longitude, request.Hi.Longitude); - int right = Math.Max(request.Lo.Longitude, request.Hi.Longitude); - int top = Math.Max(request.Lo.Latitude, request.Hi.Latitude); - int bottom = Math.Min(request.Lo.Latitude, request.Hi.Latitude); - - foreach (var feature in features) + var responses = features.FindAll( (feature) => feature.Exists() && request.Contains(feature.Location) ); + foreach (var response in responses) { - if (!RouteGuideUtil.Exists(feature)) - { - continue; - } - - int lat = feature.Location.Latitude; - int lon = feature.Location.Longitude; - if (lon >= left && lon <= right && lat >= bottom && lat <= top) - { - await responseStream.WriteAsync(feature); - } + await responseStream.WriteAsync(response); } } ``` @@ -191,8 +178,8 @@ As you can see, here the request object is a `Rectangle` in which our client wan Similarly, the client-side streaming method `RecordRoute` uses an [IAsyncEnumerator](https://github.com/Reactive-Extensions/Rx.NET/blob/master/Ix.NET/Source/System.Interactive.Async/IAsyncEnumerator.cs), to read the stream of requests using the async method `MoveNext` and the `Current` property. ```csharp - public async Task<RouteSummary> RecordRoute(Grpc.Core.ServerCallContext context, - Grpc.Core.IAsyncStreamReader<Point> requestStream) + public async Task<RouteSummary> RecordRoute(Grpc.Core.IAsyncStreamReader<Point> requestStream, + Grpc.Core.ServerCallContext context) { int pointCount = 0; int featureCount = 0; @@ -205,21 +192,26 @@ Similarly, the client-side streaming method `RecordRoute` uses an [IAsyncEnumera { var point = requestStream.Current; pointCount++; - if (RouteGuideUtil.Exists(CheckFeature(point))) + if (CheckFeature(point).Exists()) { featureCount++; } if (previous != null) { - distance += (int) CalcDistance(previous, point); + distance += (int) previous.GetDistance(point); } previous = point; } stopwatch.Stop(); - return RouteSummary.CreateBuilder().SetPointCount(pointCount) - .SetFeatureCount(featureCount).SetDistance(distance) - .SetElapsedTime((int) (stopwatch.ElapsedMilliseconds / 1000)).Build(); + + return new RouteSummary + { + PointCount = pointCount, + FeatureCount = featureCount, + Distance = distance, + ElapsedTime = (int)(stopwatch.ElapsedMilliseconds / 1000) + }; } ``` @@ -228,28 +220,17 @@ Similarly, the client-side streaming method `RecordRoute` uses an [IAsyncEnumera Finally, let's look at our bidirectional streaming RPC `RouteChat`. ```csharp - public async Task RouteChat(Grpc.Core.ServerCallContext context, - Grpc.Core.IAsyncStreamReader<RouteNote> requestStream, Grpc.Core.IServerStreamWriter<RouteNote> responseStream) + public async Task RouteChat(Grpc.Core.IAsyncStreamReader<RouteNote> requestStream, + Grpc.Core.IServerStreamWriter<RouteNote> responseStream, + Grpc.Core.ServerCallContext context,) { while (await requestStream.MoveNext()) - { + { var note = requestStream.Current; - List<RouteNote> notes = GetOrCreateNotes(note.Location); - - List<RouteNote> prevNotes; - lock (notes) - { - prevNotes = new List<RouteNote>(notes); - } - + List<RouteNote> prevNotes = AddNoteForLocation(note.Location, note); foreach (var prevNote in prevNotes) { await responseStream.WriteAsync(prevNote); - } - - lock (notes) - { - notes.Add(note); } } } @@ -263,11 +244,12 @@ Once we've implemented all our methods, we also need to start up a gRPC server s ```csharp var features = RouteGuideUtil.ParseFeatures(RouteGuideUtil.DefaultFeaturesFile); -GrpcEnvironment.Initialize(); -Server server = new Server(); -server.AddServiceDefinition(RouteGuide.BindService(new RouteGuideImpl(features))); -int port = server.AddListeningPort("localhost", 50052); +Server server = new Server +{ + Services = { RouteGuide.BindService(new RouteGuideImpl(features)) }, + Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) } +}; server.Start(); Console.WriteLine("RouteGuide server listening on port " + port); @@ -275,14 +257,13 @@ Console.WriteLine("Press any key to stop the server..."); Console.ReadKey(); server.ShutdownAsync().Wait(); -GrpcEnvironment.Shutdown(); ``` As you can see, we build and start our server using `Grpc.Core.Server` class. To do this, we: 1. Create an instance of `Grpc.Core.Server`. 1. Create an instance of our service implementation class `RouteGuideImpl`. -3. Register our service implementation with the server using the `AddServiceDefinition` method and the generated method `RouteGuide.BindService`. -2. Specify the address and port we want to use to listen for client requests using the `AddListeningPort` method. +3. Register our service implementation by adding its service definition to `Services` collection (We obtain the service definition from the generated `RouteGuide.BindService` method). +2. Specify the address and port we want to use to listen for client requests. This is done by adding `ServerPort` to `Ports` collection. 4. Call `Start` on the server instance to start an RPC server for our service. <a name="client"></a> @@ -294,19 +275,15 @@ In this section, we'll look at creating a C# client for our `RouteGuide` service To call service methods, we first need to create a *stub*. -First, we need to create a gRPC client channel that will connect to gRPC server. Then, we use the `RouteGuide.NewStub` method of the `RouteGuide` class generated from our .proto. +First, we need to create a gRPC client channel that will connect to gRPC server. Then, we use the `RouteGuide.NewClient` method of the `RouteGuide` class generated from our .proto. ```csharp -GrpcEnvironment.Initialize(); +Channel channel = new Channel("127.0.0.1:50052", Credentials.Insecure) +var client = new RouteGuideClient(RouteGuide.NewClient(channel)); -using (Channel channel = new Channel("127.0.0.1:50052")) -{ - var client = RouteGuide.NewStub(channel); - - // YOUR CODE GOES HERE -} +// YOUR CODE GOES HERE -GrpcEnvironment.Shutdown(); +channel.ShutdownAsync().Wait(); ``` ### Calling service methods @@ -319,7 +296,7 @@ gRPC C# also provides a synchronous method stub, but only for simple (single req Calling the simple RPC `GetFeature` in a synchronous way is nearly as straightforward as calling a local method. ```csharp -Point request = Point.CreateBuilder().SetLatitude(409146138).SetLongitude(-746188906).Build(); +Point request = new Point { Latitude = 409146138, Longitude = -746188906 }; Feature feature = client.GetFeature(request); ``` @@ -327,7 +304,7 @@ As you can see, we create and populate a request protocol buffer object (in our Alternatively, if you are in async context, you can call an asynchronous version of the method (and use `await` keyword to await the result): ```csharp -Point request = Point.CreateBuilder().SetLatitude(409146138).SetLongitude(-746188906).Build(); +Point request = new Point { Latitude = 409146138, Longitude = -746188906 }; Feature feature = await client.GetFeatureAsync(request); ``` @@ -349,17 +326,17 @@ using (var call = client.ListFeatures(request)) ``` The client-side streaming method `RecordRoute` is similar, except we use the property `RequestStream` to write the requests one by one using `WriteAsync` and eventually signal that no more request will be send using `CompleteAsync`. The method result can be obtained through the property -`Result`. +`ResponseAsync`. ```csharp using (var call = client.RecordRoute()) { foreach (var point in points) - { + { await call.RequestStream.WriteAsync(point); } await call.RequestStream.CompleteAsync(); - RouteSummary summary = await call.Result; + RouteSummary summary = await call.ResponseAsync; } ``` @@ -374,7 +351,7 @@ Finally, let's look at our bidirectional streaming RPC `RouteChat`. In this case { var note = call.ResponseStream.Current; Console.WriteLine("Received " + note); - } + } }); foreach (RouteNote request in requests) @@ -382,7 +359,7 @@ Finally, let's look at our bidirectional streaming RPC `RouteChat`. In this case await call.RequestStream.WriteAsync(request); } await call.RequestStream.CompleteAsync(); - await responseReaderTask; + await responseReaderTask; } ``` diff --git a/examples/csharp/route_guide/RouteGuide/RouteGuide.cs b/examples/csharp/route_guide/RouteGuide/RouteGuide.cs index 80508bcd3f..9bc6f307d2 100644 --- a/examples/csharp/route_guide/RouteGuide/RouteGuide.cs +++ b/examples/csharp/route_guide/RouteGuide/RouteGuide.cs @@ -3,38 +3,22 @@ #pragma warning disable 1591, 0612, 3021 #region Designer generated code -using pb = global::Google.ProtocolBuffers; -using pbc = global::Google.ProtocolBuffers.Collections; -using pbd = global::Google.ProtocolBuffers.Descriptors; +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; using scg = global::System.Collections.Generic; -namespace examples { +namespace Examples { namespace Proto { [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] public static partial class RouteGuide { - #region Extension registration - public static void RegisterAllExtensions(pb::ExtensionRegistry registry) { - } - #endregion - #region Static variables - internal static pbd::MessageDescriptor internal__static_examples_Point__Descriptor; - internal static pb::FieldAccess.FieldAccessorTable<global::examples.Point, global::examples.Point.Builder> internal__static_examples_Point__FieldAccessorTable; - internal static pbd::MessageDescriptor internal__static_examples_Rectangle__Descriptor; - internal static pb::FieldAccess.FieldAccessorTable<global::examples.Rectangle, global::examples.Rectangle.Builder> internal__static_examples_Rectangle__FieldAccessorTable; - internal static pbd::MessageDescriptor internal__static_examples_Feature__Descriptor; - internal static pb::FieldAccess.FieldAccessorTable<global::examples.Feature, global::examples.Feature.Builder> internal__static_examples_Feature__FieldAccessorTable; - internal static pbd::MessageDescriptor internal__static_examples_RouteNote__Descriptor; - internal static pb::FieldAccess.FieldAccessorTable<global::examples.RouteNote, global::examples.RouteNote.Builder> internal__static_examples_RouteNote__FieldAccessorTable; - internal static pbd::MessageDescriptor internal__static_examples_RouteSummary__Descriptor; - internal static pb::FieldAccess.FieldAccessorTable<global::examples.RouteSummary, global::examples.RouteSummary.Builder> internal__static_examples_RouteSummary__FieldAccessorTable; - #endregion #region Descriptor - public static pbd::FileDescriptor Descriptor { + public static pbr::FileDescriptor Descriptor { get { return descriptor; } } - private static pbd::FileDescriptor descriptor; + private static pbr::FileDescriptor descriptor; static RouteGuide() { byte[] descriptorData = global::System.Convert.FromBase64String( @@ -52,36 +36,17 @@ namespace examples { "dXJlcxITLmV4YW1wbGVzLlJlY3RhbmdsZRoRLmV4YW1wbGVzLkZlYXR1cmUi", "ADABEjoKC1JlY29yZFJvdXRlEg8uZXhhbXBsZXMuUG9pbnQaFi5leGFtcGxl", "cy5Sb3V0ZVN1bW1hcnkiACgBEjsKCVJvdXRlQ2hhdBITLmV4YW1wbGVzLlJv", - "dXRlTm90ZRoTLmV4YW1wbGVzLlJvdXRlTm90ZSIAKAEwAQ==")); - pbd::FileDescriptor.InternalDescriptorAssigner assigner = delegate(pbd::FileDescriptor root) { - descriptor = root; - internal__static_examples_Point__Descriptor = Descriptor.MessageTypes[0]; - internal__static_examples_Point__FieldAccessorTable = - new pb::FieldAccess.FieldAccessorTable<global::examples.Point, global::examples.Point.Builder>(internal__static_examples_Point__Descriptor, - new string[] { "Latitude", "Longitude", }); - internal__static_examples_Rectangle__Descriptor = Descriptor.MessageTypes[1]; - internal__static_examples_Rectangle__FieldAccessorTable = - new pb::FieldAccess.FieldAccessorTable<global::examples.Rectangle, global::examples.Rectangle.Builder>(internal__static_examples_Rectangle__Descriptor, - new string[] { "Lo", "Hi", }); - internal__static_examples_Feature__Descriptor = Descriptor.MessageTypes[2]; - internal__static_examples_Feature__FieldAccessorTable = - new pb::FieldAccess.FieldAccessorTable<global::examples.Feature, global::examples.Feature.Builder>(internal__static_examples_Feature__Descriptor, - new string[] { "Name", "Location", }); - internal__static_examples_RouteNote__Descriptor = Descriptor.MessageTypes[3]; - internal__static_examples_RouteNote__FieldAccessorTable = - new pb::FieldAccess.FieldAccessorTable<global::examples.RouteNote, global::examples.RouteNote.Builder>(internal__static_examples_RouteNote__Descriptor, - new string[] { "Location", "Message", }); - internal__static_examples_RouteSummary__Descriptor = Descriptor.MessageTypes[4]; - internal__static_examples_RouteSummary__FieldAccessorTable = - new pb::FieldAccess.FieldAccessorTable<global::examples.RouteSummary, global::examples.RouteSummary.Builder>(internal__static_examples_RouteSummary__Descriptor, - new string[] { "PointCount", "FeatureCount", "Distance", "ElapsedTime", }); - pb::ExtensionRegistry registry = pb::ExtensionRegistry.CreateInstance(); - RegisterAllExtensions(registry); - return registry; - }; - pbd::FileDescriptor.InternalBuildGeneratedFileFrom(descriptorData, - new pbd::FileDescriptor[] { - }, assigner); + "dXRlTm90ZRoTLmV4YW1wbGVzLlJvdXRlTm90ZSIAKAEwAUIPCgdleC5ncnBj", + "ogIDUlRHYgZwcm90bzM=")); + descriptor = pbr::FileDescriptor.InternalBuildGeneratedFileFrom(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedCodeInfo(null, new pbr::GeneratedCodeInfo[] { + new pbr::GeneratedCodeInfo(typeof(global::Examples.Point), new[]{ "Latitude", "Longitude" }, null, null, null), + new pbr::GeneratedCodeInfo(typeof(global::Examples.Rectangle), new[]{ "Lo", "Hi" }, null, null, null), + new pbr::GeneratedCodeInfo(typeof(global::Examples.Feature), new[]{ "Name", "Location" }, null, null, null), + new pbr::GeneratedCodeInfo(typeof(global::Examples.RouteNote), new[]{ "Location", "Message" }, null, null, null), + new pbr::GeneratedCodeInfo(typeof(global::Examples.RouteSummary), new[]{ "PointCount", "FeatureCount", "Distance", "ElapsedTime" }, null, null, null) + })); } #endregion @@ -89,1781 +54,719 @@ namespace examples { } #region Messages [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - public sealed partial class Point : pb::GeneratedMessage<Point, Point.Builder> { - private Point() { } - private static readonly Point defaultInstance = new Point().MakeReadOnly(); - private static readonly string[] _pointFieldNames = new string[] { "latitude", "longitude" }; - private static readonly uint[] _pointFieldTags = new uint[] { 8, 16 }; - public static Point DefaultInstance { - get { return defaultInstance; } + public sealed partial class Point : pb::IMessage<Point> { + private static readonly pb::MessageParser<Point> _parser = new pb::MessageParser<Point>(() => new Point()); + public static pb::MessageParser<Point> Parser { get { return _parser; } } + + public static pbr::MessageDescriptor Descriptor { + get { return global::Examples.Proto.RouteGuide.Descriptor.MessageTypes[0]; } } - public override Point DefaultInstanceForType { - get { return DefaultInstance; } + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } } - protected override Point ThisMessage { - get { return this; } + public Point() { + OnConstruction(); } - public static pbd::MessageDescriptor Descriptor { - get { return global::examples.Proto.RouteGuide.internal__static_examples_Point__Descriptor; } + partial void OnConstruction(); + + public Point(Point other) : this() { + latitude_ = other.latitude_; + longitude_ = other.longitude_; } - protected override pb::FieldAccess.FieldAccessorTable<Point, Point.Builder> InternalFieldAccessors { - get { return global::examples.Proto.RouteGuide.internal__static_examples_Point__FieldAccessorTable; } + public Point Clone() { + return new Point(this); } public const int LatitudeFieldNumber = 1; - private bool hasLatitude; private int latitude_; - public bool HasLatitude { - get { return hasLatitude; } - } public int Latitude { get { return latitude_; } + set { + latitude_ = value; + } } public const int LongitudeFieldNumber = 2; - private bool hasLongitude; private int longitude_; - public bool HasLongitude { - get { return hasLongitude; } - } public int Longitude { get { return longitude_; } - } - - public override bool IsInitialized { - get { - return true; + set { + longitude_ = value; } } - public override void WriteTo(pb::ICodedOutputStream output) { - CalcSerializedSize(); - string[] field_names = _pointFieldNames; - if (hasLatitude) { - output.WriteInt32(1, field_names[0], Latitude); - } - if (hasLongitude) { - output.WriteInt32(2, field_names[1], Longitude); - } - UnknownFields.WriteTo(output); - } - - private int memoizedSerializedSize = -1; - public override int SerializedSize { - get { - int size = memoizedSerializedSize; - if (size != -1) return size; - return CalcSerializedSize(); - } + public override bool Equals(object other) { + return Equals(other as Point); } - private int CalcSerializedSize() { - int size = memoizedSerializedSize; - if (size != -1) return size; - - size = 0; - if (hasLatitude) { - size += pb::CodedOutputStream.ComputeInt32Size(1, Latitude); + public bool Equals(Point other) { + if (ReferenceEquals(other, null)) { + return false; } - if (hasLongitude) { - size += pb::CodedOutputStream.ComputeInt32Size(2, Longitude); + if (ReferenceEquals(other, this)) { + return true; } - size += UnknownFields.SerializedSize; - memoizedSerializedSize = size; - return size; - } - public static Point ParseFrom(pb::ByteString data) { - return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); - } - public static Point ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); - } - public static Point ParseFrom(byte[] data) { - return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); - } - public static Point ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); - } - public static Point ParseFrom(global::System.IO.Stream input) { - return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); - } - public static Point ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); - } - public static Point ParseDelimitedFrom(global::System.IO.Stream input) { - return CreateBuilder().MergeDelimitedFrom(input).BuildParsed(); - } - public static Point ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { - return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed(); - } - public static Point ParseFrom(pb::ICodedInputStream input) { - return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); - } - public static Point ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); - } - private Point MakeReadOnly() { - return this; + if (Latitude != other.Latitude) return false; + if (Longitude != other.Longitude) return false; + return true; } - public static Builder CreateBuilder() { return new Builder(); } - public override Builder ToBuilder() { return CreateBuilder(this); } - public override Builder CreateBuilderForType() { return new Builder(); } - public static Builder CreateBuilder(Point prototype) { - return new Builder(prototype); + public override int GetHashCode() { + int hash = 1; + if (Latitude != 0) hash ^= Latitude.GetHashCode(); + if (Longitude != 0) hash ^= Longitude.GetHashCode(); + return hash; } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - public sealed partial class Builder : pb::GeneratedBuilder<Point, Builder> { - protected override Builder ThisBuilder { - get { return this; } - } - public Builder() { - result = DefaultInstance; - resultIsReadOnly = true; - } - internal Builder(Point cloneFrom) { - result = cloneFrom; - resultIsReadOnly = true; - } - - private bool resultIsReadOnly; - private Point result; + public override string ToString() { + return pb::JsonFormatter.Default.Format(this); + } - private Point PrepareBuilder() { - if (resultIsReadOnly) { - Point original = result; - result = new Point(); - resultIsReadOnly = false; - MergeFrom(original); - } - return result; + public void WriteTo(pb::CodedOutputStream output) { + if (Latitude != 0) { + output.WriteRawTag(8); + output.WriteInt32(Latitude); } - - public override bool IsInitialized { - get { return result.IsInitialized; } - } - - protected override Point MessageBeingBuilt { - get { return PrepareBuilder(); } + if (Longitude != 0) { + output.WriteRawTag(16); + output.WriteInt32(Longitude); } + } - public override Builder Clear() { - result = DefaultInstance; - resultIsReadOnly = true; - return this; + public int CalculateSize() { + int size = 0; + if (Latitude != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Latitude); } - - public override Builder Clone() { - if (resultIsReadOnly) { - return new Builder(result); - } else { - return new Builder().MergeFrom(result); - } - } - - public override pbd::MessageDescriptor DescriptorForType { - get { return global::examples.Point.Descriptor; } + if (Longitude != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Longitude); } + return size; + } - public override Point DefaultInstanceForType { - get { return global::examples.Point.DefaultInstance; } + public void MergeFrom(Point other) { + if (other == null) { + return; } - - public override Point BuildPartial() { - if (resultIsReadOnly) { - return result; - } - resultIsReadOnly = true; - return result.MakeReadOnly(); + if (other.Latitude != 0) { + Latitude = other.Latitude; } - - public override Builder MergeFrom(pb::IMessage other) { - if (other is Point) { - return MergeFrom((Point) other); - } else { - base.MergeFrom(other); - return this; - } + if (other.Longitude != 0) { + Longitude = other.Longitude; } + } - public override Builder MergeFrom(Point other) { - if (other == global::examples.Point.DefaultInstance) return this; - PrepareBuilder(); - if (other.HasLatitude) { - Latitude = other.Latitude; - } - if (other.HasLongitude) { - Longitude = other.Longitude; - } - this.MergeUnknownFields(other.UnknownFields); - return this; - } - - public override Builder MergeFrom(pb::ICodedInputStream input) { - return MergeFrom(input, pb::ExtensionRegistry.Empty); - } - - public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { - PrepareBuilder(); - pb::UnknownFieldSet.Builder unknownFields = null; - uint tag; - string field_name; - while (input.ReadTag(out tag, out field_name)) { - if(tag == 0 && field_name != null) { - int field_ordinal = global::System.Array.BinarySearch(_pointFieldNames, field_name, global::System.StringComparer.Ordinal); - if(field_ordinal >= 0) - tag = _pointFieldTags[field_ordinal]; - else { - if (unknownFields == null) { - unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields); - } - ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name); - continue; - } + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + case 8: { + Latitude = input.ReadInt32(); + break; } - switch (tag) { - case 0: { - throw pb::InvalidProtocolBufferException.InvalidTag(); - } - default: { - if (pb::WireFormat.IsEndGroupTag(tag)) { - if (unknownFields != null) { - this.UnknownFields = unknownFields.Build(); - } - return this; - } - if (unknownFields == null) { - unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields); - } - ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name); - break; - } - case 8: { - result.hasLatitude = input.ReadInt32(ref result.latitude_); - break; - } - case 16: { - result.hasLongitude = input.ReadInt32(ref result.longitude_); - break; - } + case 16: { + Longitude = input.ReadInt32(); + break; } } - - if (unknownFields != null) { - this.UnknownFields = unknownFields.Build(); - } - return this; - } - - - public bool HasLatitude { - get { return result.hasLatitude; } - } - public int Latitude { - get { return result.Latitude; } - set { SetLatitude(value); } - } - public Builder SetLatitude(int value) { - PrepareBuilder(); - result.hasLatitude = true; - result.latitude_ = value; - return this; - } - public Builder ClearLatitude() { - PrepareBuilder(); - result.hasLatitude = false; - result.latitude_ = 0; - return this; - } - - public bool HasLongitude { - get { return result.hasLongitude; } - } - public int Longitude { - get { return result.Longitude; } - set { SetLongitude(value); } - } - public Builder SetLongitude(int value) { - PrepareBuilder(); - result.hasLongitude = true; - result.longitude_ = value; - return this; - } - public Builder ClearLongitude() { - PrepareBuilder(); - result.hasLongitude = false; - result.longitude_ = 0; - return this; } } - static Point() { - object.ReferenceEquals(global::examples.Proto.RouteGuide.Descriptor, null); - } + } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - public sealed partial class Rectangle : pb::GeneratedMessage<Rectangle, Rectangle.Builder> { - private Rectangle() { } - private static readonly Rectangle defaultInstance = new Rectangle().MakeReadOnly(); - private static readonly string[] _rectangleFieldNames = new string[] { "hi", "lo" }; - private static readonly uint[] _rectangleFieldTags = new uint[] { 18, 10 }; - public static Rectangle DefaultInstance { - get { return defaultInstance; } - } + public sealed partial class Rectangle : pb::IMessage<Rectangle> { + private static readonly pb::MessageParser<Rectangle> _parser = new pb::MessageParser<Rectangle>(() => new Rectangle()); + public static pb::MessageParser<Rectangle> Parser { get { return _parser; } } - public override Rectangle DefaultInstanceForType { - get { return DefaultInstance; } + public static pbr::MessageDescriptor Descriptor { + get { return global::Examples.Proto.RouteGuide.Descriptor.MessageTypes[1]; } } - protected override Rectangle ThisMessage { - get { return this; } + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } } - public static pbd::MessageDescriptor Descriptor { - get { return global::examples.Proto.RouteGuide.internal__static_examples_Rectangle__Descriptor; } + public Rectangle() { + OnConstruction(); } - protected override pb::FieldAccess.FieldAccessorTable<Rectangle, Rectangle.Builder> InternalFieldAccessors { - get { return global::examples.Proto.RouteGuide.internal__static_examples_Rectangle__FieldAccessorTable; } - } + partial void OnConstruction(); - public const int LoFieldNumber = 1; - private bool hasLo; - private global::examples.Point lo_; - public bool HasLo { - get { return hasLo; } - } - public global::examples.Point Lo { - get { return lo_ ?? global::examples.Point.DefaultInstance; } + public Rectangle(Rectangle other) : this() { + Lo = other.lo_ != null ? other.Lo.Clone() : null; + Hi = other.hi_ != null ? other.Hi.Clone() : null; } - public const int HiFieldNumber = 2; - private bool hasHi; - private global::examples.Point hi_; - public bool HasHi { - get { return hasHi; } - } - public global::examples.Point Hi { - get { return hi_ ?? global::examples.Point.DefaultInstance; } + public Rectangle Clone() { + return new Rectangle(this); } - public override bool IsInitialized { - get { - return true; + public const int LoFieldNumber = 1; + private global::Examples.Point lo_; + public global::Examples.Point Lo { + get { return lo_; } + set { + lo_ = value; } } - public override void WriteTo(pb::ICodedOutputStream output) { - CalcSerializedSize(); - string[] field_names = _rectangleFieldNames; - if (hasLo) { - output.WriteMessage(1, field_names[1], Lo); - } - if (hasHi) { - output.WriteMessage(2, field_names[0], Hi); + public const int HiFieldNumber = 2; + private global::Examples.Point hi_; + public global::Examples.Point Hi { + get { return hi_; } + set { + hi_ = value; } - UnknownFields.WriteTo(output); } - private int memoizedSerializedSize = -1; - public override int SerializedSize { - get { - int size = memoizedSerializedSize; - if (size != -1) return size; - return CalcSerializedSize(); - } + public override bool Equals(object other) { + return Equals(other as Rectangle); } - private int CalcSerializedSize() { - int size = memoizedSerializedSize; - if (size != -1) return size; - - size = 0; - if (hasLo) { - size += pb::CodedOutputStream.ComputeMessageSize(1, Lo); + public bool Equals(Rectangle other) { + if (ReferenceEquals(other, null)) { + return false; } - if (hasHi) { - size += pb::CodedOutputStream.ComputeMessageSize(2, Hi); + if (ReferenceEquals(other, this)) { + return true; } - size += UnknownFields.SerializedSize; - memoizedSerializedSize = size; - return size; - } - public static Rectangle ParseFrom(pb::ByteString data) { - return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); - } - public static Rectangle ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); - } - public static Rectangle ParseFrom(byte[] data) { - return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); - } - public static Rectangle ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); - } - public static Rectangle ParseFrom(global::System.IO.Stream input) { - return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); - } - public static Rectangle ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); - } - public static Rectangle ParseDelimitedFrom(global::System.IO.Stream input) { - return CreateBuilder().MergeDelimitedFrom(input).BuildParsed(); - } - public static Rectangle ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { - return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed(); - } - public static Rectangle ParseFrom(pb::ICodedInputStream input) { - return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); - } - public static Rectangle ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); - } - private Rectangle MakeReadOnly() { - return this; + if (!object.Equals(Lo, other.Lo)) return false; + if (!object.Equals(Hi, other.Hi)) return false; + return true; } - public static Builder CreateBuilder() { return new Builder(); } - public override Builder ToBuilder() { return CreateBuilder(this); } - public override Builder CreateBuilderForType() { return new Builder(); } - public static Builder CreateBuilder(Rectangle prototype) { - return new Builder(prototype); + public override int GetHashCode() { + int hash = 1; + if (lo_ != null) hash ^= Lo.GetHashCode(); + if (hi_ != null) hash ^= Hi.GetHashCode(); + return hash; } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - public sealed partial class Builder : pb::GeneratedBuilder<Rectangle, Builder> { - protected override Builder ThisBuilder { - get { return this; } - } - public Builder() { - result = DefaultInstance; - resultIsReadOnly = true; - } - internal Builder(Rectangle cloneFrom) { - result = cloneFrom; - resultIsReadOnly = true; - } - - private bool resultIsReadOnly; - private Rectangle result; - - private Rectangle PrepareBuilder() { - if (resultIsReadOnly) { - Rectangle original = result; - result = new Rectangle(); - resultIsReadOnly = false; - MergeFrom(original); - } - return result; - } - - public override bool IsInitialized { - get { return result.IsInitialized; } - } + public override string ToString() { + return pb::JsonFormatter.Default.Format(this); + } - protected override Rectangle MessageBeingBuilt { - get { return PrepareBuilder(); } + public void WriteTo(pb::CodedOutputStream output) { + if (lo_ != null) { + output.WriteRawTag(10); + output.WriteMessage(Lo); } - - public override Builder Clear() { - result = DefaultInstance; - resultIsReadOnly = true; - return this; + if (hi_ != null) { + output.WriteRawTag(18); + output.WriteMessage(Hi); } + } - public override Builder Clone() { - if (resultIsReadOnly) { - return new Builder(result); - } else { - return new Builder().MergeFrom(result); - } + public int CalculateSize() { + int size = 0; + if (lo_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(Lo); } - - public override pbd::MessageDescriptor DescriptorForType { - get { return global::examples.Rectangle.Descriptor; } + if (hi_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(Hi); } + return size; + } - public override Rectangle DefaultInstanceForType { - get { return global::examples.Rectangle.DefaultInstance; } + public void MergeFrom(Rectangle other) { + if (other == null) { + return; } - - public override Rectangle BuildPartial() { - if (resultIsReadOnly) { - return result; + if (other.lo_ != null) { + if (lo_ == null) { + lo_ = new global::Examples.Point(); } - resultIsReadOnly = true; - return result.MakeReadOnly(); + Lo.MergeFrom(other.Lo); } - - public override Builder MergeFrom(pb::IMessage other) { - if (other is Rectangle) { - return MergeFrom((Rectangle) other); - } else { - base.MergeFrom(other); - return this; + if (other.hi_ != null) { + if (hi_ == null) { + hi_ = new global::Examples.Point(); } + Hi.MergeFrom(other.Hi); } + } - public override Builder MergeFrom(Rectangle other) { - if (other == global::examples.Rectangle.DefaultInstance) return this; - PrepareBuilder(); - if (other.HasLo) { - MergeLo(other.Lo); - } - if (other.HasHi) { - MergeHi(other.Hi); - } - this.MergeUnknownFields(other.UnknownFields); - return this; - } - - public override Builder MergeFrom(pb::ICodedInputStream input) { - return MergeFrom(input, pb::ExtensionRegistry.Empty); - } - - public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { - PrepareBuilder(); - pb::UnknownFieldSet.Builder unknownFields = null; - uint tag; - string field_name; - while (input.ReadTag(out tag, out field_name)) { - if(tag == 0 && field_name != null) { - int field_ordinal = global::System.Array.BinarySearch(_rectangleFieldNames, field_name, global::System.StringComparer.Ordinal); - if(field_ordinal >= 0) - tag = _rectangleFieldTags[field_ordinal]; - else { - if (unknownFields == null) { - unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields); - } - ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name); - continue; + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + case 10: { + if (lo_ == null) { + lo_ = new global::Examples.Point(); } + input.ReadMessage(lo_); + break; } - switch (tag) { - case 0: { - throw pb::InvalidProtocolBufferException.InvalidTag(); - } - default: { - if (pb::WireFormat.IsEndGroupTag(tag)) { - if (unknownFields != null) { - this.UnknownFields = unknownFields.Build(); - } - return this; - } - if (unknownFields == null) { - unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields); - } - ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name); - break; - } - case 10: { - global::examples.Point.Builder subBuilder = global::examples.Point.CreateBuilder(); - if (result.hasLo) { - subBuilder.MergeFrom(Lo); - } - input.ReadMessage(subBuilder, extensionRegistry); - Lo = subBuilder.BuildPartial(); - break; - } - case 18: { - global::examples.Point.Builder subBuilder = global::examples.Point.CreateBuilder(); - if (result.hasHi) { - subBuilder.MergeFrom(Hi); - } - input.ReadMessage(subBuilder, extensionRegistry); - Hi = subBuilder.BuildPartial(); - break; + case 18: { + if (hi_ == null) { + hi_ = new global::Examples.Point(); } + input.ReadMessage(hi_); + break; } } - - if (unknownFields != null) { - this.UnknownFields = unknownFields.Build(); - } - return this; - } - - - public bool HasLo { - get { return result.hasLo; } - } - public global::examples.Point Lo { - get { return result.Lo; } - set { SetLo(value); } - } - public Builder SetLo(global::examples.Point value) { - pb::ThrowHelper.ThrowIfNull(value, "value"); - PrepareBuilder(); - result.hasLo = true; - result.lo_ = value; - return this; - } - public Builder SetLo(global::examples.Point.Builder builderForValue) { - pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); - PrepareBuilder(); - result.hasLo = true; - result.lo_ = builderForValue.Build(); - return this; - } - public Builder MergeLo(global::examples.Point value) { - pb::ThrowHelper.ThrowIfNull(value, "value"); - PrepareBuilder(); - if (result.hasLo && - result.lo_ != global::examples.Point.DefaultInstance) { - result.lo_ = global::examples.Point.CreateBuilder(result.lo_).MergeFrom(value).BuildPartial(); - } else { - result.lo_ = value; - } - result.hasLo = true; - return this; - } - public Builder ClearLo() { - PrepareBuilder(); - result.hasLo = false; - result.lo_ = null; - return this; - } - - public bool HasHi { - get { return result.hasHi; } - } - public global::examples.Point Hi { - get { return result.Hi; } - set { SetHi(value); } - } - public Builder SetHi(global::examples.Point value) { - pb::ThrowHelper.ThrowIfNull(value, "value"); - PrepareBuilder(); - result.hasHi = true; - result.hi_ = value; - return this; - } - public Builder SetHi(global::examples.Point.Builder builderForValue) { - pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); - PrepareBuilder(); - result.hasHi = true; - result.hi_ = builderForValue.Build(); - return this; - } - public Builder MergeHi(global::examples.Point value) { - pb::ThrowHelper.ThrowIfNull(value, "value"); - PrepareBuilder(); - if (result.hasHi && - result.hi_ != global::examples.Point.DefaultInstance) { - result.hi_ = global::examples.Point.CreateBuilder(result.hi_).MergeFrom(value).BuildPartial(); - } else { - result.hi_ = value; - } - result.hasHi = true; - return this; } - public Builder ClearHi() { - PrepareBuilder(); - result.hasHi = false; - result.hi_ = null; - return this; - } - } - static Rectangle() { - object.ReferenceEquals(global::examples.Proto.RouteGuide.Descriptor, null); } + } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - public sealed partial class Feature : pb::GeneratedMessage<Feature, Feature.Builder> { - private Feature() { } - private static readonly Feature defaultInstance = new Feature().MakeReadOnly(); - private static readonly string[] _featureFieldNames = new string[] { "location", "name" }; - private static readonly uint[] _featureFieldTags = new uint[] { 18, 10 }; - public static Feature DefaultInstance { - get { return defaultInstance; } + public sealed partial class Feature : pb::IMessage<Feature> { + private static readonly pb::MessageParser<Feature> _parser = new pb::MessageParser<Feature>(() => new Feature()); + public static pb::MessageParser<Feature> Parser { get { return _parser; } } + + public static pbr::MessageDescriptor Descriptor { + get { return global::Examples.Proto.RouteGuide.Descriptor.MessageTypes[2]; } } - public override Feature DefaultInstanceForType { - get { return DefaultInstance; } + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } } - protected override Feature ThisMessage { - get { return this; } + public Feature() { + OnConstruction(); } - public static pbd::MessageDescriptor Descriptor { - get { return global::examples.Proto.RouteGuide.internal__static_examples_Feature__Descriptor; } + partial void OnConstruction(); + + public Feature(Feature other) : this() { + name_ = other.name_; + Location = other.location_ != null ? other.Location.Clone() : null; } - protected override pb::FieldAccess.FieldAccessorTable<Feature, Feature.Builder> InternalFieldAccessors { - get { return global::examples.Proto.RouteGuide.internal__static_examples_Feature__FieldAccessorTable; } + public Feature Clone() { + return new Feature(this); } public const int NameFieldNumber = 1; - private bool hasName; private string name_ = ""; - public bool HasName { - get { return hasName; } - } public string Name { get { return name_; } - } - - public const int LocationFieldNumber = 2; - private bool hasLocation; - private global::examples.Point location_; - public bool HasLocation { - get { return hasLocation; } - } - public global::examples.Point Location { - get { return location_ ?? global::examples.Point.DefaultInstance; } - } - - public override bool IsInitialized { - get { - return true; + set { + name_ = pb::Preconditions.CheckNotNull(value, "value"); } } - public override void WriteTo(pb::ICodedOutputStream output) { - CalcSerializedSize(); - string[] field_names = _featureFieldNames; - if (hasName) { - output.WriteString(1, field_names[1], Name); - } - if (hasLocation) { - output.WriteMessage(2, field_names[0], Location); + public const int LocationFieldNumber = 2; + private global::Examples.Point location_; + public global::Examples.Point Location { + get { return location_; } + set { + location_ = value; } - UnknownFields.WriteTo(output); } - private int memoizedSerializedSize = -1; - public override int SerializedSize { - get { - int size = memoizedSerializedSize; - if (size != -1) return size; - return CalcSerializedSize(); - } + public override bool Equals(object other) { + return Equals(other as Feature); } - private int CalcSerializedSize() { - int size = memoizedSerializedSize; - if (size != -1) return size; - - size = 0; - if (hasName) { - size += pb::CodedOutputStream.ComputeStringSize(1, Name); + public bool Equals(Feature other) { + if (ReferenceEquals(other, null)) { + return false; } - if (hasLocation) { - size += pb::CodedOutputStream.ComputeMessageSize(2, Location); + if (ReferenceEquals(other, this)) { + return true; } - size += UnknownFields.SerializedSize; - memoizedSerializedSize = size; - return size; - } - public static Feature ParseFrom(pb::ByteString data) { - return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); - } - public static Feature ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); - } - public static Feature ParseFrom(byte[] data) { - return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); - } - public static Feature ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); - } - public static Feature ParseFrom(global::System.IO.Stream input) { - return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); - } - public static Feature ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); - } - public static Feature ParseDelimitedFrom(global::System.IO.Stream input) { - return CreateBuilder().MergeDelimitedFrom(input).BuildParsed(); - } - public static Feature ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { - return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed(); - } - public static Feature ParseFrom(pb::ICodedInputStream input) { - return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); - } - public static Feature ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); - } - private Feature MakeReadOnly() { - return this; + if (Name != other.Name) return false; + if (!object.Equals(Location, other.Location)) return false; + return true; } - public static Builder CreateBuilder() { return new Builder(); } - public override Builder ToBuilder() { return CreateBuilder(this); } - public override Builder CreateBuilderForType() { return new Builder(); } - public static Builder CreateBuilder(Feature prototype) { - return new Builder(prototype); + public override int GetHashCode() { + int hash = 1; + if (Name.Length != 0) hash ^= Name.GetHashCode(); + if (location_ != null) hash ^= Location.GetHashCode(); + return hash; } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - public sealed partial class Builder : pb::GeneratedBuilder<Feature, Builder> { - protected override Builder ThisBuilder { - get { return this; } - } - public Builder() { - result = DefaultInstance; - resultIsReadOnly = true; - } - internal Builder(Feature cloneFrom) { - result = cloneFrom; - resultIsReadOnly = true; - } - - private bool resultIsReadOnly; - private Feature result; - - private Feature PrepareBuilder() { - if (resultIsReadOnly) { - Feature original = result; - result = new Feature(); - resultIsReadOnly = false; - MergeFrom(original); - } - return result; - } - - public override bool IsInitialized { - get { return result.IsInitialized; } - } + public override string ToString() { + return pb::JsonFormatter.Default.Format(this); + } - protected override Feature MessageBeingBuilt { - get { return PrepareBuilder(); } + public void WriteTo(pb::CodedOutputStream output) { + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); } - - public override Builder Clear() { - result = DefaultInstance; - resultIsReadOnly = true; - return this; + if (location_ != null) { + output.WriteRawTag(18); + output.WriteMessage(Location); } + } - public override Builder Clone() { - if (resultIsReadOnly) { - return new Builder(result); - } else { - return new Builder().MergeFrom(result); - } + public int CalculateSize() { + int size = 0; + if (Name.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); } - - public override pbd::MessageDescriptor DescriptorForType { - get { return global::examples.Feature.Descriptor; } + if (location_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(Location); } + return size; + } - public override Feature DefaultInstanceForType { - get { return global::examples.Feature.DefaultInstance; } + public void MergeFrom(Feature other) { + if (other == null) { + return; } - - public override Feature BuildPartial() { - if (resultIsReadOnly) { - return result; - } - resultIsReadOnly = true; - return result.MakeReadOnly(); + if (other.Name.Length != 0) { + Name = other.Name; } - - public override Builder MergeFrom(pb::IMessage other) { - if (other is Feature) { - return MergeFrom((Feature) other); - } else { - base.MergeFrom(other); - return this; + if (other.location_ != null) { + if (location_ == null) { + location_ = new global::Examples.Point(); } + Location.MergeFrom(other.Location); } + } - public override Builder MergeFrom(Feature other) { - if (other == global::examples.Feature.DefaultInstance) return this; - PrepareBuilder(); - if (other.HasName) { - Name = other.Name; - } - if (other.HasLocation) { - MergeLocation(other.Location); - } - this.MergeUnknownFields(other.UnknownFields); - return this; - } - - public override Builder MergeFrom(pb::ICodedInputStream input) { - return MergeFrom(input, pb::ExtensionRegistry.Empty); - } - - public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { - PrepareBuilder(); - pb::UnknownFieldSet.Builder unknownFields = null; - uint tag; - string field_name; - while (input.ReadTag(out tag, out field_name)) { - if(tag == 0 && field_name != null) { - int field_ordinal = global::System.Array.BinarySearch(_featureFieldNames, field_name, global::System.StringComparer.Ordinal); - if(field_ordinal >= 0) - tag = _featureFieldTags[field_ordinal]; - else { - if (unknownFields == null) { - unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields); - } - ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name); - continue; - } + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + case 10: { + Name = input.ReadString(); + break; } - switch (tag) { - case 0: { - throw pb::InvalidProtocolBufferException.InvalidTag(); - } - default: { - if (pb::WireFormat.IsEndGroupTag(tag)) { - if (unknownFields != null) { - this.UnknownFields = unknownFields.Build(); - } - return this; - } - if (unknownFields == null) { - unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields); - } - ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name); - break; - } - case 10: { - result.hasName = input.ReadString(ref result.name_); - break; - } - case 18: { - global::examples.Point.Builder subBuilder = global::examples.Point.CreateBuilder(); - if (result.hasLocation) { - subBuilder.MergeFrom(Location); - } - input.ReadMessage(subBuilder, extensionRegistry); - Location = subBuilder.BuildPartial(); - break; + case 18: { + if (location_ == null) { + location_ = new global::Examples.Point(); } + input.ReadMessage(location_); + break; } } - - if (unknownFields != null) { - this.UnknownFields = unknownFields.Build(); - } - return this; - } - - - public bool HasName { - get { return result.hasName; } - } - public string Name { - get { return result.Name; } - set { SetName(value); } - } - public Builder SetName(string value) { - pb::ThrowHelper.ThrowIfNull(value, "value"); - PrepareBuilder(); - result.hasName = true; - result.name_ = value; - return this; - } - public Builder ClearName() { - PrepareBuilder(); - result.hasName = false; - result.name_ = ""; - return this; - } - - public bool HasLocation { - get { return result.hasLocation; } - } - public global::examples.Point Location { - get { return result.Location; } - set { SetLocation(value); } - } - public Builder SetLocation(global::examples.Point value) { - pb::ThrowHelper.ThrowIfNull(value, "value"); - PrepareBuilder(); - result.hasLocation = true; - result.location_ = value; - return this; - } - public Builder SetLocation(global::examples.Point.Builder builderForValue) { - pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); - PrepareBuilder(); - result.hasLocation = true; - result.location_ = builderForValue.Build(); - return this; - } - public Builder MergeLocation(global::examples.Point value) { - pb::ThrowHelper.ThrowIfNull(value, "value"); - PrepareBuilder(); - if (result.hasLocation && - result.location_ != global::examples.Point.DefaultInstance) { - result.location_ = global::examples.Point.CreateBuilder(result.location_).MergeFrom(value).BuildPartial(); - } else { - result.location_ = value; - } - result.hasLocation = true; - return this; - } - public Builder ClearLocation() { - PrepareBuilder(); - result.hasLocation = false; - result.location_ = null; - return this; } } - static Feature() { - object.ReferenceEquals(global::examples.Proto.RouteGuide.Descriptor, null); - } + } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - public sealed partial class RouteNote : pb::GeneratedMessage<RouteNote, RouteNote.Builder> { - private RouteNote() { } - private static readonly RouteNote defaultInstance = new RouteNote().MakeReadOnly(); - private static readonly string[] _routeNoteFieldNames = new string[] { "location", "message" }; - private static readonly uint[] _routeNoteFieldTags = new uint[] { 10, 18 }; - public static RouteNote DefaultInstance { - get { return defaultInstance; } + public sealed partial class RouteNote : pb::IMessage<RouteNote> { + private static readonly pb::MessageParser<RouteNote> _parser = new pb::MessageParser<RouteNote>(() => new RouteNote()); + public static pb::MessageParser<RouteNote> Parser { get { return _parser; } } + + public static pbr::MessageDescriptor Descriptor { + get { return global::Examples.Proto.RouteGuide.Descriptor.MessageTypes[3]; } } - public override RouteNote DefaultInstanceForType { - get { return DefaultInstance; } + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } } - protected override RouteNote ThisMessage { - get { return this; } + public RouteNote() { + OnConstruction(); } - public static pbd::MessageDescriptor Descriptor { - get { return global::examples.Proto.RouteGuide.internal__static_examples_RouteNote__Descriptor; } + partial void OnConstruction(); + + public RouteNote(RouteNote other) : this() { + Location = other.location_ != null ? other.Location.Clone() : null; + message_ = other.message_; } - protected override pb::FieldAccess.FieldAccessorTable<RouteNote, RouteNote.Builder> InternalFieldAccessors { - get { return global::examples.Proto.RouteGuide.internal__static_examples_RouteNote__FieldAccessorTable; } + public RouteNote Clone() { + return new RouteNote(this); } public const int LocationFieldNumber = 1; - private bool hasLocation; - private global::examples.Point location_; - public bool HasLocation { - get { return hasLocation; } - } - public global::examples.Point Location { - get { return location_ ?? global::examples.Point.DefaultInstance; } + private global::Examples.Point location_; + public global::Examples.Point Location { + get { return location_; } + set { + location_ = value; + } } public const int MessageFieldNumber = 2; - private bool hasMessage; private string message_ = ""; - public bool HasMessage { - get { return hasMessage; } - } public string Message { get { return message_; } - } - - public override bool IsInitialized { - get { - return true; + set { + message_ = pb::Preconditions.CheckNotNull(value, "value"); } } - public override void WriteTo(pb::ICodedOutputStream output) { - CalcSerializedSize(); - string[] field_names = _routeNoteFieldNames; - if (hasLocation) { - output.WriteMessage(1, field_names[0], Location); - } - if (hasMessage) { - output.WriteString(2, field_names[1], Message); - } - UnknownFields.WriteTo(output); + public override bool Equals(object other) { + return Equals(other as RouteNote); } - private int memoizedSerializedSize = -1; - public override int SerializedSize { - get { - int size = memoizedSerializedSize; - if (size != -1) return size; - return CalcSerializedSize(); + public bool Equals(RouteNote other) { + if (ReferenceEquals(other, null)) { + return false; } - } - - private int CalcSerializedSize() { - int size = memoizedSerializedSize; - if (size != -1) return size; - - size = 0; - if (hasLocation) { - size += pb::CodedOutputStream.ComputeMessageSize(1, Location); - } - if (hasMessage) { - size += pb::CodedOutputStream.ComputeStringSize(2, Message); + if (ReferenceEquals(other, this)) { + return true; } - size += UnknownFields.SerializedSize; - memoizedSerializedSize = size; - return size; - } - public static RouteNote ParseFrom(pb::ByteString data) { - return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); - } - public static RouteNote ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); - } - public static RouteNote ParseFrom(byte[] data) { - return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); - } - public static RouteNote ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); - } - public static RouteNote ParseFrom(global::System.IO.Stream input) { - return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); - } - public static RouteNote ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); - } - public static RouteNote ParseDelimitedFrom(global::System.IO.Stream input) { - return CreateBuilder().MergeDelimitedFrom(input).BuildParsed(); - } - public static RouteNote ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { - return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed(); - } - public static RouteNote ParseFrom(pb::ICodedInputStream input) { - return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); - } - public static RouteNote ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); - } - private RouteNote MakeReadOnly() { - return this; + if (!object.Equals(Location, other.Location)) return false; + if (Message != other.Message) return false; + return true; } - public static Builder CreateBuilder() { return new Builder(); } - public override Builder ToBuilder() { return CreateBuilder(this); } - public override Builder CreateBuilderForType() { return new Builder(); } - public static Builder CreateBuilder(RouteNote prototype) { - return new Builder(prototype); + public override int GetHashCode() { + int hash = 1; + if (location_ != null) hash ^= Location.GetHashCode(); + if (Message.Length != 0) hash ^= Message.GetHashCode(); + return hash; } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - public sealed partial class Builder : pb::GeneratedBuilder<RouteNote, Builder> { - protected override Builder ThisBuilder { - get { return this; } - } - public Builder() { - result = DefaultInstance; - resultIsReadOnly = true; - } - internal Builder(RouteNote cloneFrom) { - result = cloneFrom; - resultIsReadOnly = true; - } - - private bool resultIsReadOnly; - private RouteNote result; - - private RouteNote PrepareBuilder() { - if (resultIsReadOnly) { - RouteNote original = result; - result = new RouteNote(); - resultIsReadOnly = false; - MergeFrom(original); - } - return result; - } - - public override bool IsInitialized { - get { return result.IsInitialized; } - } + public override string ToString() { + return pb::JsonFormatter.Default.Format(this); + } - protected override RouteNote MessageBeingBuilt { - get { return PrepareBuilder(); } + public void WriteTo(pb::CodedOutputStream output) { + if (location_ != null) { + output.WriteRawTag(10); + output.WriteMessage(Location); } - - public override Builder Clear() { - result = DefaultInstance; - resultIsReadOnly = true; - return this; + if (Message.Length != 0) { + output.WriteRawTag(18); + output.WriteString(Message); } + } - public override Builder Clone() { - if (resultIsReadOnly) { - return new Builder(result); - } else { - return new Builder().MergeFrom(result); - } + public int CalculateSize() { + int size = 0; + if (location_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(Location); } - - public override pbd::MessageDescriptor DescriptorForType { - get { return global::examples.RouteNote.Descriptor; } + if (Message.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Message); } + return size; + } - public override RouteNote DefaultInstanceForType { - get { return global::examples.RouteNote.DefaultInstance; } + public void MergeFrom(RouteNote other) { + if (other == null) { + return; } - - public override RouteNote BuildPartial() { - if (resultIsReadOnly) { - return result; + if (other.location_ != null) { + if (location_ == null) { + location_ = new global::Examples.Point(); } - resultIsReadOnly = true; - return result.MakeReadOnly(); + Location.MergeFrom(other.Location); } - - public override Builder MergeFrom(pb::IMessage other) { - if (other is RouteNote) { - return MergeFrom((RouteNote) other); - } else { - base.MergeFrom(other); - return this; - } + if (other.Message.Length != 0) { + Message = other.Message; } + } - public override Builder MergeFrom(RouteNote other) { - if (other == global::examples.RouteNote.DefaultInstance) return this; - PrepareBuilder(); - if (other.HasLocation) { - MergeLocation(other.Location); - } - if (other.HasMessage) { - Message = other.Message; - } - this.MergeUnknownFields(other.UnknownFields); - return this; - } - - public override Builder MergeFrom(pb::ICodedInputStream input) { - return MergeFrom(input, pb::ExtensionRegistry.Empty); - } - - public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { - PrepareBuilder(); - pb::UnknownFieldSet.Builder unknownFields = null; - uint tag; - string field_name; - while (input.ReadTag(out tag, out field_name)) { - if(tag == 0 && field_name != null) { - int field_ordinal = global::System.Array.BinarySearch(_routeNoteFieldNames, field_name, global::System.StringComparer.Ordinal); - if(field_ordinal >= 0) - tag = _routeNoteFieldTags[field_ordinal]; - else { - if (unknownFields == null) { - unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields); - } - ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name); - continue; + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + case 10: { + if (location_ == null) { + location_ = new global::Examples.Point(); } + input.ReadMessage(location_); + break; } - switch (tag) { - case 0: { - throw pb::InvalidProtocolBufferException.InvalidTag(); - } - default: { - if (pb::WireFormat.IsEndGroupTag(tag)) { - if (unknownFields != null) { - this.UnknownFields = unknownFields.Build(); - } - return this; - } - if (unknownFields == null) { - unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields); - } - ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name); - break; - } - case 10: { - global::examples.Point.Builder subBuilder = global::examples.Point.CreateBuilder(); - if (result.hasLocation) { - subBuilder.MergeFrom(Location); - } - input.ReadMessage(subBuilder, extensionRegistry); - Location = subBuilder.BuildPartial(); - break; - } - case 18: { - result.hasMessage = input.ReadString(ref result.message_); - break; - } + case 18: { + Message = input.ReadString(); + break; } } - - if (unknownFields != null) { - this.UnknownFields = unknownFields.Build(); - } - return this; - } - - - public bool HasLocation { - get { return result.hasLocation; } - } - public global::examples.Point Location { - get { return result.Location; } - set { SetLocation(value); } - } - public Builder SetLocation(global::examples.Point value) { - pb::ThrowHelper.ThrowIfNull(value, "value"); - PrepareBuilder(); - result.hasLocation = true; - result.location_ = value; - return this; - } - public Builder SetLocation(global::examples.Point.Builder builderForValue) { - pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); - PrepareBuilder(); - result.hasLocation = true; - result.location_ = builderForValue.Build(); - return this; - } - public Builder MergeLocation(global::examples.Point value) { - pb::ThrowHelper.ThrowIfNull(value, "value"); - PrepareBuilder(); - if (result.hasLocation && - result.location_ != global::examples.Point.DefaultInstance) { - result.location_ = global::examples.Point.CreateBuilder(result.location_).MergeFrom(value).BuildPartial(); - } else { - result.location_ = value; - } - result.hasLocation = true; - return this; - } - public Builder ClearLocation() { - PrepareBuilder(); - result.hasLocation = false; - result.location_ = null; - return this; - } - - public bool HasMessage { - get { return result.hasMessage; } - } - public string Message { - get { return result.Message; } - set { SetMessage(value); } - } - public Builder SetMessage(string value) { - pb::ThrowHelper.ThrowIfNull(value, "value"); - PrepareBuilder(); - result.hasMessage = true; - result.message_ = value; - return this; - } - public Builder ClearMessage() { - PrepareBuilder(); - result.hasMessage = false; - result.message_ = ""; - return this; } } - static RouteNote() { - object.ReferenceEquals(global::examples.Proto.RouteGuide.Descriptor, null); - } + } [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - public sealed partial class RouteSummary : pb::GeneratedMessage<RouteSummary, RouteSummary.Builder> { - private RouteSummary() { } - private static readonly RouteSummary defaultInstance = new RouteSummary().MakeReadOnly(); - private static readonly string[] _routeSummaryFieldNames = new string[] { "distance", "elapsed_time", "feature_count", "point_count" }; - private static readonly uint[] _routeSummaryFieldTags = new uint[] { 24, 32, 16, 8 }; - public static RouteSummary DefaultInstance { - get { return defaultInstance; } + public sealed partial class RouteSummary : pb::IMessage<RouteSummary> { + private static readonly pb::MessageParser<RouteSummary> _parser = new pb::MessageParser<RouteSummary>(() => new RouteSummary()); + public static pb::MessageParser<RouteSummary> Parser { get { return _parser; } } + + public static pbr::MessageDescriptor Descriptor { + get { return global::Examples.Proto.RouteGuide.Descriptor.MessageTypes[4]; } } - public override RouteSummary DefaultInstanceForType { - get { return DefaultInstance; } + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } } - protected override RouteSummary ThisMessage { - get { return this; } + public RouteSummary() { + OnConstruction(); } - public static pbd::MessageDescriptor Descriptor { - get { return global::examples.Proto.RouteGuide.internal__static_examples_RouteSummary__Descriptor; } + partial void OnConstruction(); + + public RouteSummary(RouteSummary other) : this() { + pointCount_ = other.pointCount_; + featureCount_ = other.featureCount_; + distance_ = other.distance_; + elapsedTime_ = other.elapsedTime_; } - protected override pb::FieldAccess.FieldAccessorTable<RouteSummary, RouteSummary.Builder> InternalFieldAccessors { - get { return global::examples.Proto.RouteGuide.internal__static_examples_RouteSummary__FieldAccessorTable; } + public RouteSummary Clone() { + return new RouteSummary(this); } public const int PointCountFieldNumber = 1; - private bool hasPointCount; private int pointCount_; - public bool HasPointCount { - get { return hasPointCount; } - } public int PointCount { get { return pointCount_; } + set { + pointCount_ = value; + } } public const int FeatureCountFieldNumber = 2; - private bool hasFeatureCount; private int featureCount_; - public bool HasFeatureCount { - get { return hasFeatureCount; } - } public int FeatureCount { get { return featureCount_; } + set { + featureCount_ = value; + } } public const int DistanceFieldNumber = 3; - private bool hasDistance; private int distance_; - public bool HasDistance { - get { return hasDistance; } - } public int Distance { get { return distance_; } + set { + distance_ = value; + } } public const int ElapsedTimeFieldNumber = 4; - private bool hasElapsedTime; private int elapsedTime_; - public bool HasElapsedTime { - get { return hasElapsedTime; } - } public int ElapsedTime { get { return elapsedTime_; } + set { + elapsedTime_ = value; + } } - public override bool IsInitialized { - get { - return true; - } + public override bool Equals(object other) { + return Equals(other as RouteSummary); } - public override void WriteTo(pb::ICodedOutputStream output) { - CalcSerializedSize(); - string[] field_names = _routeSummaryFieldNames; - if (hasPointCount) { - output.WriteInt32(1, field_names[3], PointCount); - } - if (hasFeatureCount) { - output.WriteInt32(2, field_names[2], FeatureCount); - } - if (hasDistance) { - output.WriteInt32(3, field_names[0], Distance); + public bool Equals(RouteSummary other) { + if (ReferenceEquals(other, null)) { + return false; } - if (hasElapsedTime) { - output.WriteInt32(4, field_names[1], ElapsedTime); + if (ReferenceEquals(other, this)) { + return true; } - UnknownFields.WriteTo(output); + if (PointCount != other.PointCount) return false; + if (FeatureCount != other.FeatureCount) return false; + if (Distance != other.Distance) return false; + if (ElapsedTime != other.ElapsedTime) return false; + return true; } - private int memoizedSerializedSize = -1; - public override int SerializedSize { - get { - int size = memoizedSerializedSize; - if (size != -1) return size; - return CalcSerializedSize(); - } + public override int GetHashCode() { + int hash = 1; + if (PointCount != 0) hash ^= PointCount.GetHashCode(); + if (FeatureCount != 0) hash ^= FeatureCount.GetHashCode(); + if (Distance != 0) hash ^= Distance.GetHashCode(); + if (ElapsedTime != 0) hash ^= ElapsedTime.GetHashCode(); + return hash; } - private int CalcSerializedSize() { - int size = memoizedSerializedSize; - if (size != -1) return size; + public override string ToString() { + return pb::JsonFormatter.Default.Format(this); + } - size = 0; - if (hasPointCount) { - size += pb::CodedOutputStream.ComputeInt32Size(1, PointCount); + public void WriteTo(pb::CodedOutputStream output) { + if (PointCount != 0) { + output.WriteRawTag(8); + output.WriteInt32(PointCount); } - if (hasFeatureCount) { - size += pb::CodedOutputStream.ComputeInt32Size(2, FeatureCount); + if (FeatureCount != 0) { + output.WriteRawTag(16); + output.WriteInt32(FeatureCount); } - if (hasDistance) { - size += pb::CodedOutputStream.ComputeInt32Size(3, Distance); + if (Distance != 0) { + output.WriteRawTag(24); + output.WriteInt32(Distance); } - if (hasElapsedTime) { - size += pb::CodedOutputStream.ComputeInt32Size(4, ElapsedTime); + if (ElapsedTime != 0) { + output.WriteRawTag(32); + output.WriteInt32(ElapsedTime); } - size += UnknownFields.SerializedSize; - memoizedSerializedSize = size; - return size; - } - public static RouteSummary ParseFrom(pb::ByteString data) { - return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); - } - public static RouteSummary ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); - } - public static RouteSummary ParseFrom(byte[] data) { - return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); - } - public static RouteSummary ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); - } - public static RouteSummary ParseFrom(global::System.IO.Stream input) { - return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); - } - public static RouteSummary ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); - } - public static RouteSummary ParseDelimitedFrom(global::System.IO.Stream input) { - return CreateBuilder().MergeDelimitedFrom(input).BuildParsed(); - } - public static RouteSummary ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { - return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed(); - } - public static RouteSummary ParseFrom(pb::ICodedInputStream input) { - return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); - } - public static RouteSummary ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); - } - private RouteSummary MakeReadOnly() { - return this; - } - - public static Builder CreateBuilder() { return new Builder(); } - public override Builder ToBuilder() { return CreateBuilder(this); } - public override Builder CreateBuilderForType() { return new Builder(); } - public static Builder CreateBuilder(RouteSummary prototype) { - return new Builder(prototype); } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - public sealed partial class Builder : pb::GeneratedBuilder<RouteSummary, Builder> { - protected override Builder ThisBuilder { - get { return this; } + public int CalculateSize() { + int size = 0; + if (PointCount != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(PointCount); } - public Builder() { - result = DefaultInstance; - resultIsReadOnly = true; + if (FeatureCount != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(FeatureCount); } - internal Builder(RouteSummary cloneFrom) { - result = cloneFrom; - resultIsReadOnly = true; + if (Distance != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Distance); } - - private bool resultIsReadOnly; - private RouteSummary result; - - private RouteSummary PrepareBuilder() { - if (resultIsReadOnly) { - RouteSummary original = result; - result = new RouteSummary(); - resultIsReadOnly = false; - MergeFrom(original); - } - return result; - } - - public override bool IsInitialized { - get { return result.IsInitialized; } - } - - protected override RouteSummary MessageBeingBuilt { - get { return PrepareBuilder(); } - } - - public override Builder Clear() { - result = DefaultInstance; - resultIsReadOnly = true; - return this; + if (ElapsedTime != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(ElapsedTime); } + return size; + } - public override Builder Clone() { - if (resultIsReadOnly) { - return new Builder(result); - } else { - return new Builder().MergeFrom(result); - } + public void MergeFrom(RouteSummary other) { + if (other == null) { + return; } - - public override pbd::MessageDescriptor DescriptorForType { - get { return global::examples.RouteSummary.Descriptor; } + if (other.PointCount != 0) { + PointCount = other.PointCount; } - - public override RouteSummary DefaultInstanceForType { - get { return global::examples.RouteSummary.DefaultInstance; } + if (other.FeatureCount != 0) { + FeatureCount = other.FeatureCount; } - - public override RouteSummary BuildPartial() { - if (resultIsReadOnly) { - return result; - } - resultIsReadOnly = true; - return result.MakeReadOnly(); + if (other.Distance != 0) { + Distance = other.Distance; } - - public override Builder MergeFrom(pb::IMessage other) { - if (other is RouteSummary) { - return MergeFrom((RouteSummary) other); - } else { - base.MergeFrom(other); - return this; - } + if (other.ElapsedTime != 0) { + ElapsedTime = other.ElapsedTime; } + } - public override Builder MergeFrom(RouteSummary other) { - if (other == global::examples.RouteSummary.DefaultInstance) return this; - PrepareBuilder(); - if (other.HasPointCount) { - PointCount = other.PointCount; - } - if (other.HasFeatureCount) { - FeatureCount = other.FeatureCount; - } - if (other.HasDistance) { - Distance = other.Distance; - } - if (other.HasElapsedTime) { - ElapsedTime = other.ElapsedTime; - } - this.MergeUnknownFields(other.UnknownFields); - return this; - } - - public override Builder MergeFrom(pb::ICodedInputStream input) { - return MergeFrom(input, pb::ExtensionRegistry.Empty); - } - - public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { - PrepareBuilder(); - pb::UnknownFieldSet.Builder unknownFields = null; - uint tag; - string field_name; - while (input.ReadTag(out tag, out field_name)) { - if(tag == 0 && field_name != null) { - int field_ordinal = global::System.Array.BinarySearch(_routeSummaryFieldNames, field_name, global::System.StringComparer.Ordinal); - if(field_ordinal >= 0) - tag = _routeSummaryFieldTags[field_ordinal]; - else { - if (unknownFields == null) { - unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields); - } - ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name); - continue; - } + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + case 8: { + PointCount = input.ReadInt32(); + break; } - switch (tag) { - case 0: { - throw pb::InvalidProtocolBufferException.InvalidTag(); - } - default: { - if (pb::WireFormat.IsEndGroupTag(tag)) { - if (unknownFields != null) { - this.UnknownFields = unknownFields.Build(); - } - return this; - } - if (unknownFields == null) { - unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields); - } - ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name); - break; - } - case 8: { - result.hasPointCount = input.ReadInt32(ref result.pointCount_); - break; - } - case 16: { - result.hasFeatureCount = input.ReadInt32(ref result.featureCount_); - break; - } - case 24: { - result.hasDistance = input.ReadInt32(ref result.distance_); - break; - } - case 32: { - result.hasElapsedTime = input.ReadInt32(ref result.elapsedTime_); - break; - } + case 16: { + FeatureCount = input.ReadInt32(); + break; + } + case 24: { + Distance = input.ReadInt32(); + break; + } + case 32: { + ElapsedTime = input.ReadInt32(); + break; } } - - if (unknownFields != null) { - this.UnknownFields = unknownFields.Build(); - } - return this; - } - - - public bool HasPointCount { - get { return result.hasPointCount; } - } - public int PointCount { - get { return result.PointCount; } - set { SetPointCount(value); } - } - public Builder SetPointCount(int value) { - PrepareBuilder(); - result.hasPointCount = true; - result.pointCount_ = value; - return this; - } - public Builder ClearPointCount() { - PrepareBuilder(); - result.hasPointCount = false; - result.pointCount_ = 0; - return this; - } - - public bool HasFeatureCount { - get { return result.hasFeatureCount; } - } - public int FeatureCount { - get { return result.FeatureCount; } - set { SetFeatureCount(value); } - } - public Builder SetFeatureCount(int value) { - PrepareBuilder(); - result.hasFeatureCount = true; - result.featureCount_ = value; - return this; - } - public Builder ClearFeatureCount() { - PrepareBuilder(); - result.hasFeatureCount = false; - result.featureCount_ = 0; - return this; - } - - public bool HasDistance { - get { return result.hasDistance; } - } - public int Distance { - get { return result.Distance; } - set { SetDistance(value); } - } - public Builder SetDistance(int value) { - PrepareBuilder(); - result.hasDistance = true; - result.distance_ = value; - return this; - } - public Builder ClearDistance() { - PrepareBuilder(); - result.hasDistance = false; - result.distance_ = 0; - return this; - } - - public bool HasElapsedTime { - get { return result.hasElapsedTime; } - } - public int ElapsedTime { - get { return result.ElapsedTime; } - set { SetElapsedTime(value); } - } - public Builder SetElapsedTime(int value) { - PrepareBuilder(); - result.hasElapsedTime = true; - result.elapsedTime_ = value; - return this; - } - public Builder ClearElapsedTime() { - PrepareBuilder(); - result.hasElapsedTime = false; - result.elapsedTime_ = 0; - return this; } } - static RouteSummary() { - object.ReferenceEquals(global::examples.Proto.RouteGuide.Descriptor, null); - } + } #endregion diff --git a/examples/csharp/route_guide/RouteGuide/RouteGuide.csproj b/examples/csharp/route_guide/RouteGuide/RouteGuide.csproj index 8358974aac..302a783aa4 100644 --- a/examples/csharp/route_guide/RouteGuide/RouteGuide.csproj +++ b/examples/csharp/route_guide/RouteGuide/RouteGuide.csproj @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <Import Project="..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.props" Condition="Exists('..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.props')" /> - <Import Project="..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.props" Condition="Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.props')" /> + <Import Project="..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.props" Condition="Exists('..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.props')" /> + <Import Project="..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.props" Condition="Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.props')" /> <Import Project="..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.props" Condition="Exists('..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> @@ -14,7 +14,7 @@ <AssemblyName>RouteGuide</AssemblyName> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> - <NuGetPackageImportStamp>214cccda</NuGetPackageImportStamp> + <NuGetPackageImportStamp>443bbc38</NuGetPackageImportStamp> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> @@ -34,25 +34,18 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> - <Reference Include="Google.ProtocolBuffers"> - <HintPath>..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.dll</HintPath> + <Reference Include="Google.Protobuf"> + <HintPath>..\packages\Google.Protobuf.3.0.0-alpha4\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll</HintPath> </Reference> - <Reference Include="Google.ProtocolBuffers.Serialization"> - <HintPath>..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.Serialization.dll</HintPath> - </Reference> - <Reference Include="Grpc.Core, Version=0.6.5668.37363, Culture=neutral, processorArchitecture=MSIL"> + <Reference Include="Grpc.Core, Version=0.7.0.0, Culture=neutral, PublicKeyToken=d754f35622e28bad, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> - <HintPath>..\packages\Grpc.Core.0.6.0\lib\net45\Grpc.Core.dll</HintPath> + <HintPath>..\packages\Grpc.Core.0.7.0\lib\net45\Grpc.Core.dll</HintPath> </Reference> <Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>..\packages\Newtonsoft.Json.7.0.1-beta2\lib\net45\Newtonsoft.Json.dll</HintPath> </Reference> <Reference Include="System" /> - <Reference Include="System.Collections.Immutable, Version=1.1.36.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\packages\System.Collections.Immutable.1.1.36\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath> - </Reference> <Reference Include="System.Core" /> <Reference Include="System.Interactive.Async"> <HintPath>..\packages\Ix-Async.1.2.3\lib\net45\System.Interactive.Async.dll</HintPath> @@ -71,7 +64,6 @@ </ItemGroup> <ItemGroup> <None Include="packages.config" /> - <None Include="protos\route_guide.proto" /> <None Include="route_guide_db.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> @@ -83,14 +75,14 @@ </PropertyGroup> <Error Condition="!Exists('..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.props'))" /> <Error Condition="!Exists('..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.targets'))" /> - <Error Condition="!Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.props'))" /> - <Error Condition="!Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.targets'))" /> - <Error Condition="!Exists('..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.props'))" /> - <Error Condition="!Exists('..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.targets'))" /> + <Error Condition="!Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.props'))" /> + <Error Condition="!Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.targets'))" /> + <Error Condition="!Exists('..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.props'))" /> + <Error Condition="!Exists('..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.targets'))" /> </Target> <Import Project="..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.targets" Condition="Exists('..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.targets')" /> - <Import Project="..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.targets" Condition="Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.targets')" /> - <Import Project="..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.targets" Condition="Exists('..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.targets')" /> + <Import Project="..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.targets" Condition="Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.targets')" /> + <Import Project="..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.targets" Condition="Exists('..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.targets')" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> diff --git a/examples/csharp/route_guide/RouteGuide/RouteGuideGrpc.cs b/examples/csharp/route_guide/RouteGuide/RouteGuideGrpc.cs index c4b3900dca..f2dc1c2ec0 100644 --- a/examples/csharp/route_guide/RouteGuide/RouteGuideGrpc.cs +++ b/examples/csharp/route_guide/RouteGuide/RouteGuideGrpc.cs @@ -7,93 +7,130 @@ using System.Threading; using System.Threading.Tasks; using Grpc.Core; -namespace examples { +namespace Examples { public static class RouteGuide { static readonly string __ServiceName = "examples.RouteGuide"; - static readonly Marshaller<global::examples.Point> __Marshaller_Point = Marshallers.Create((arg) => arg.ToByteArray(), global::examples.Point.ParseFrom); - static readonly Marshaller<global::examples.Feature> __Marshaller_Feature = Marshallers.Create((arg) => arg.ToByteArray(), global::examples.Feature.ParseFrom); - static readonly Marshaller<global::examples.Rectangle> __Marshaller_Rectangle = Marshallers.Create((arg) => arg.ToByteArray(), global::examples.Rectangle.ParseFrom); - static readonly Marshaller<global::examples.RouteSummary> __Marshaller_RouteSummary = Marshallers.Create((arg) => arg.ToByteArray(), global::examples.RouteSummary.ParseFrom); - static readonly Marshaller<global::examples.RouteNote> __Marshaller_RouteNote = Marshallers.Create((arg) => arg.ToByteArray(), global::examples.RouteNote.ParseFrom); + static readonly Marshaller<global::Examples.Point> __Marshaller_Point = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Examples.Point.Parser.ParseFrom); + static readonly Marshaller<global::Examples.Feature> __Marshaller_Feature = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Examples.Feature.Parser.ParseFrom); + static readonly Marshaller<global::Examples.Rectangle> __Marshaller_Rectangle = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Examples.Rectangle.Parser.ParseFrom); + static readonly Marshaller<global::Examples.RouteSummary> __Marshaller_RouteSummary = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Examples.RouteSummary.Parser.ParseFrom); + static readonly Marshaller<global::Examples.RouteNote> __Marshaller_RouteNote = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Examples.RouteNote.Parser.ParseFrom); - static readonly Method<global::examples.Point, global::examples.Feature> __Method_GetFeature = new Method<global::examples.Point, global::examples.Feature>( + static readonly Method<global::Examples.Point, global::Examples.Feature> __Method_GetFeature = new Method<global::Examples.Point, global::Examples.Feature>( MethodType.Unary, + __ServiceName, "GetFeature", __Marshaller_Point, __Marshaller_Feature); - static readonly Method<global::examples.Rectangle, global::examples.Feature> __Method_ListFeatures = new Method<global::examples.Rectangle, global::examples.Feature>( + static readonly Method<global::Examples.Rectangle, global::Examples.Feature> __Method_ListFeatures = new Method<global::Examples.Rectangle, global::Examples.Feature>( MethodType.ServerStreaming, + __ServiceName, "ListFeatures", __Marshaller_Rectangle, __Marshaller_Feature); - static readonly Method<global::examples.Point, global::examples.RouteSummary> __Method_RecordRoute = new Method<global::examples.Point, global::examples.RouteSummary>( + static readonly Method<global::Examples.Point, global::Examples.RouteSummary> __Method_RecordRoute = new Method<global::Examples.Point, global::Examples.RouteSummary>( MethodType.ClientStreaming, + __ServiceName, "RecordRoute", __Marshaller_Point, __Marshaller_RouteSummary); - static readonly Method<global::examples.RouteNote, global::examples.RouteNote> __Method_RouteChat = new Method<global::examples.RouteNote, global::examples.RouteNote>( + static readonly Method<global::Examples.RouteNote, global::Examples.RouteNote> __Method_RouteChat = new Method<global::Examples.RouteNote, global::Examples.RouteNote>( MethodType.DuplexStreaming, + __ServiceName, "RouteChat", __Marshaller_RouteNote, __Marshaller_RouteNote); - // client-side stub interface + // service descriptor + public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor + { + get { return global::Examples.Proto.RouteGuide.Descriptor.Services[0]; } + } + + // client interface public interface IRouteGuideClient { - global::examples.Feature GetFeature(global::examples.Point request, CancellationToken token = default(CancellationToken)); - Task<global::examples.Feature> GetFeatureAsync(global::examples.Point request, CancellationToken token = default(CancellationToken)); - AsyncServerStreamingCall<global::examples.Feature> ListFeatures(global::examples.Rectangle request, CancellationToken token = default(CancellationToken)); - AsyncClientStreamingCall<global::examples.Point, global::examples.RouteSummary> RecordRoute(CancellationToken token = default(CancellationToken)); - AsyncDuplexStreamingCall<global::examples.RouteNote, global::examples.RouteNote> RouteChat(CancellationToken token = default(CancellationToken)); + global::Examples.Feature GetFeature(global::Examples.Point request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)); + global::Examples.Feature GetFeature(global::Examples.Point request, CallOptions options); + AsyncUnaryCall<global::Examples.Feature> GetFeatureAsync(global::Examples.Point request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)); + AsyncUnaryCall<global::Examples.Feature> GetFeatureAsync(global::Examples.Point request, CallOptions options); + AsyncServerStreamingCall<global::Examples.Feature> ListFeatures(global::Examples.Rectangle request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)); + AsyncServerStreamingCall<global::Examples.Feature> ListFeatures(global::Examples.Rectangle request, CallOptions options); + AsyncClientStreamingCall<global::Examples.Point, global::Examples.RouteSummary> RecordRoute(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)); + AsyncClientStreamingCall<global::Examples.Point, global::Examples.RouteSummary> RecordRoute(CallOptions options); + AsyncDuplexStreamingCall<global::Examples.RouteNote, global::Examples.RouteNote> RouteChat(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)); + AsyncDuplexStreamingCall<global::Examples.RouteNote, global::Examples.RouteNote> RouteChat(CallOptions options); } // server-side interface public interface IRouteGuide { - Task<global::examples.Feature> GetFeature(ServerCallContext context, global::examples.Point request); - Task ListFeatures(ServerCallContext context, global::examples.Rectangle request, IServerStreamWriter<global::examples.Feature> responseStream); - Task<global::examples.RouteSummary> RecordRoute(ServerCallContext context, IAsyncStreamReader<global::examples.Point> requestStream); - Task RouteChat(ServerCallContext context, IAsyncStreamReader<global::examples.RouteNote> requestStream, IServerStreamWriter<global::examples.RouteNote> responseStream); + Task<global::Examples.Feature> GetFeature(global::Examples.Point request, ServerCallContext context); + Task ListFeatures(global::Examples.Rectangle request, IServerStreamWriter<global::Examples.Feature> responseStream, ServerCallContext context); + Task<global::Examples.RouteSummary> RecordRoute(IAsyncStreamReader<global::Examples.Point> requestStream, ServerCallContext context); + Task RouteChat(IAsyncStreamReader<global::Examples.RouteNote> requestStream, IServerStreamWriter<global::Examples.RouteNote> responseStream, ServerCallContext context); } // client stub - public class RouteGuideClient : AbstractStub<RouteGuideClient, StubConfiguration>, IRouteGuideClient + public class RouteGuideClient : ClientBase, IRouteGuideClient { - public RouteGuideClient(Channel channel) : this(channel, StubConfiguration.Default) + public RouteGuideClient(Channel channel) : base(channel) + { + } + public global::Examples.Feature GetFeature(global::Examples.Point request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)) + { + var call = CreateCall(__Method_GetFeature, new CallOptions(headers, deadline, cancellationToken)); + return Calls.BlockingUnaryCall(call, request); + } + public global::Examples.Feature GetFeature(global::Examples.Point request, CallOptions options) { + var call = CreateCall(__Method_GetFeature, options); + return Calls.BlockingUnaryCall(call, request); } - public RouteGuideClient(Channel channel, StubConfiguration config) : base(channel, config) + public AsyncUnaryCall<global::Examples.Feature> GetFeatureAsync(global::Examples.Point request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)) { + var call = CreateCall(__Method_GetFeature, new CallOptions(headers, deadline, cancellationToken)); + return Calls.AsyncUnaryCall(call, request); } - public global::examples.Feature GetFeature(global::examples.Point request, CancellationToken token = default(CancellationToken)) + public AsyncUnaryCall<global::Examples.Feature> GetFeatureAsync(global::Examples.Point request, CallOptions options) { - var call = CreateCall(__ServiceName, __Method_GetFeature); - return Calls.BlockingUnaryCall(call, request, token); + var call = CreateCall(__Method_GetFeature, options); + return Calls.AsyncUnaryCall(call, request); } - public Task<global::examples.Feature> GetFeatureAsync(global::examples.Point request, CancellationToken token = default(CancellationToken)) + public AsyncServerStreamingCall<global::Examples.Feature> ListFeatures(global::Examples.Rectangle request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)) { - var call = CreateCall(__ServiceName, __Method_GetFeature); - return Calls.AsyncUnaryCall(call, request, token); + var call = CreateCall(__Method_ListFeatures, new CallOptions(headers, deadline, cancellationToken)); + return Calls.AsyncServerStreamingCall(call, request); } - public AsyncServerStreamingCall<global::examples.Feature> ListFeatures(global::examples.Rectangle request, CancellationToken token = default(CancellationToken)) + public AsyncServerStreamingCall<global::Examples.Feature> ListFeatures(global::Examples.Rectangle request, CallOptions options) { - var call = CreateCall(__ServiceName, __Method_ListFeatures); - return Calls.AsyncServerStreamingCall(call, request, token); + var call = CreateCall(__Method_ListFeatures, options); + return Calls.AsyncServerStreamingCall(call, request); } - public AsyncClientStreamingCall<global::examples.Point, global::examples.RouteSummary> RecordRoute(CancellationToken token = default(CancellationToken)) + public AsyncClientStreamingCall<global::Examples.Point, global::Examples.RouteSummary> RecordRoute(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)) { - var call = CreateCall(__ServiceName, __Method_RecordRoute); - return Calls.AsyncClientStreamingCall(call, token); + var call = CreateCall(__Method_RecordRoute, new CallOptions(headers, deadline, cancellationToken)); + return Calls.AsyncClientStreamingCall(call); } - public AsyncDuplexStreamingCall<global::examples.RouteNote, global::examples.RouteNote> RouteChat(CancellationToken token = default(CancellationToken)) + public AsyncClientStreamingCall<global::Examples.Point, global::Examples.RouteSummary> RecordRoute(CallOptions options) { - var call = CreateCall(__ServiceName, __Method_RouteChat); - return Calls.AsyncDuplexStreamingCall(call, token); + var call = CreateCall(__Method_RecordRoute, options); + return Calls.AsyncClientStreamingCall(call); + } + public AsyncDuplexStreamingCall<global::Examples.RouteNote, global::Examples.RouteNote> RouteChat(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)) + { + var call = CreateCall(__Method_RouteChat, new CallOptions(headers, deadline, cancellationToken)); + return Calls.AsyncDuplexStreamingCall(call); + } + public AsyncDuplexStreamingCall<global::Examples.RouteNote, global::Examples.RouteNote> RouteChat(CallOptions options) + { + var call = CreateCall(__Method_RouteChat, options); + return Calls.AsyncDuplexStreamingCall(call); } } @@ -107,17 +144,12 @@ namespace examples { .AddMethod(__Method_RouteChat, serviceImpl.RouteChat).Build(); } - // creates a new client stub - public static IRouteGuideClient NewStub(Channel channel) + // creates a new client + public static RouteGuideClient NewClient(Channel channel) { return new RouteGuideClient(channel); } - // creates a new client stub - public static IRouteGuideClient NewStub(Channel channel, StubConfiguration config) - { - return new RouteGuideClient(channel, config); - } } } #endregion diff --git a/examples/csharp/route_guide/RouteGuide/RouteGuideUtil.cs b/examples/csharp/route_guide/RouteGuide/RouteGuideUtil.cs index 6fb8b1e28a..21a0be43d2 100644 --- a/examples/csharp/route_guide/RouteGuide/RouteGuideUtil.cs +++ b/examples/csharp/route_guide/RouteGuide/RouteGuideUtil.cs @@ -7,8 +7,11 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace examples +namespace Examples { + /// <summary> + /// Utility methods for the route guide example. + /// </summary> public static class RouteGuideUtil { public const string DefaultFeaturesFile = "route_guide_db.json"; @@ -18,22 +21,64 @@ namespace examples /// <summary> /// Indicates whether the given feature exists (i.e. has a valid name). /// </summary> - public static bool Exists(Feature feature) + public static bool Exists(this Feature feature) { return feature != null && (feature.Name.Length != 0); } - public static double GetLatitude(Point point) + public static double GetLatitude(this Point point) { return point.Latitude / CoordFactor; } - public static double GetLongitude(Point point) + public static double GetLongitude(this Point point) { return point.Longitude / CoordFactor; } /// <summary> + /// Calculate the distance between two points using the "haversine" formula. + /// This code was taken from http://www.movable-type.co.uk/scripts/latlong.html. + /// </summary> + /// <param name="start">the starting point</param> + /// <param name="end">the end point</param> + /// <returns>the distance between the points in meters</returns> + public static double GetDistance(this Point start, Point end) + { + double lat1 = start.GetLatitude(); + double lat2 = end.GetLatitude(); + double lon1 = start.GetLongitude(); + double lon2 = end.GetLongitude(); + int r = 6371000; // metres + double phi1 = ToRadians(lat1); + double phi2 = ToRadians(lat2); + double deltaPhi = ToRadians(lat2 - lat1); + double deltaLambda = ToRadians(lon2 - lon1); + + double a = Math.Sin(deltaPhi / 2) * Math.Sin(deltaPhi / 2) + Math.Cos(phi1) * Math.Cos(phi2) * Math.Sin(deltaLambda / 2) * Math.Sin(deltaLambda / 2); + double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); + + return r * c; + } + + /// <summary> + /// Returns <c>true</c> if rectangular area contains given point. + /// </summary> + public static bool Contains(this Rectangle rectangle, Point point) + { + int left = Math.Min(rectangle.Lo.Longitude, rectangle.Hi.Longitude); + int right = Math.Max(rectangle.Lo.Longitude, rectangle.Hi.Longitude); + int top = Math.Max(rectangle.Lo.Latitude, rectangle.Hi.Latitude); + int bottom = Math.Min(rectangle.Lo.Latitude, rectangle.Hi.Latitude); + return (point.Longitude >= left && point.Longitude <= right && point.Latitude >= bottom && point.Latitude <= top); + } + + private static double ToRadians(double val) + { + return (Math.PI / 180) * val; + } + + /// <summary> /// Parses features from a JSON file. /// </summary> public static List<Feature> ParseFeatures(string filename) @@ -41,13 +86,13 @@ namespace examples var features = new List<Feature>(); var jsonFeatures = JsonConvert.DeserializeObject<List<JsonFeature>>(File.ReadAllText(filename)); - foreach(var jsonFeature in jsonFeatures) { - features.Add(Feature.CreateBuilder().SetName(jsonFeature.name).SetLocation( - Point.CreateBuilder() - .SetLongitude(jsonFeature.location.longitude) - .SetLatitude(jsonFeature.location.latitude).Build()).Build()); + features.Add(new Feature + { + Name = jsonFeature.name, + Location = new Point { Longitude = jsonFeature.location.longitude, Latitude = jsonFeature.location.latitude} + }); } return features; } diff --git a/examples/csharp/route_guide/RouteGuide/packages.config b/examples/csharp/route_guide/RouteGuide/packages.config index 79abe0aa65..8cd2ee758d 100644 --- a/examples/csharp/route_guide/RouteGuide/packages.config +++ b/examples/csharp/route_guide/RouteGuide/packages.config @@ -1,12 +1,11 @@ <?xml version="1.0" encoding="utf-8"?> <packages> - <package id="Google.ProtocolBuffers" version="2.4.1.555" targetFramework="net45" /> - <package id="Grpc" version="0.6.0" targetFramework="net45" /> - <package id="Grpc.Core" version="0.6.0" targetFramework="net45" /> - <package id="grpc.dependencies.openssl.redist" version="1.0.2.2" targetFramework="net45" /> + <package id="Google.Protobuf" version="3.0.0-alpha4" targetFramework="net45" /> + <package id="Grpc" version="0.7.0" targetFramework="net45" /> + <package id="Grpc.Core" version="0.7.0" targetFramework="net45" /> + <package id="grpc.dependencies.openssl.redist" version="1.0.2.3" targetFramework="net45" /> <package id="grpc.dependencies.zlib.redist" version="1.2.8.9" targetFramework="net45" /> - <package id="grpc.native.csharp_ext" version="0.10.0" targetFramework="net45" /> + <package id="grpc.native.csharp_ext" version="0.11.0" targetFramework="net45" /> <package id="Ix-Async" version="1.2.3" targetFramework="net45" /> <package id="Newtonsoft.Json" version="7.0.1-beta2" targetFramework="net45" /> - <package id="System.Collections.Immutable" version="1.1.36" targetFramework="net45" /> </packages>
\ No newline at end of file diff --git a/examples/csharp/route_guide/RouteGuide/protos/route_guide.proto b/examples/csharp/route_guide/RouteGuide/protos/route_guide.proto deleted file mode 100644 index f4110b5515..0000000000 --- a/examples/csharp/route_guide/RouteGuide/protos/route_guide.proto +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright 2015, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// TODO(jtattermusch): as of now, C# protobufs don't officially support -// proto3. -syntax = "proto2"; - -package examples; - -// Interface exported by the server. -service RouteGuide { - // A simple RPC. - // - // Obtains the feature at a given position. - // - // A feature with an empty name is returned if there's no feature at the given - // position. - rpc GetFeature(Point) returns (Feature) {} - - // A server-to-client streaming RPC. - // - // Obtains the Features available within the given Rectangle. Results are - // streamed rather than returned at once (e.g. in a response message with a - // repeated field), as the rectangle may cover a large area and contain a - // huge number of features. - rpc ListFeatures(Rectangle) returns (stream Feature) {} - - // A client-to-server streaming RPC. - // - // Accepts a stream of Points on a route being traversed, returning a - // RouteSummary when traversal is completed. - rpc RecordRoute(stream Point) returns (RouteSummary) {} - - // A Bidirectional streaming RPC. - // - // Accepts a stream of RouteNotes sent while a route is being traversed, - // while receiving other RouteNotes (e.g. from other users). - rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} -} - -// Points are represented as latitude-longitude pairs in the E7 representation -// (degrees multiplied by 10**7 and rounded to the nearest integer). -// Latitudes should be in the range +/- 90 degrees and longitude should be in -// the range +/- 180 degrees (inclusive). -message Point { - optional int32 latitude = 1; - optional int32 longitude = 2; -} - -// A latitude-longitude rectangle, represented as two diagonally opposite -// points "lo" and "hi". -message Rectangle { - // One corner of the rectangle. - optional Point lo = 1; - - // The other corner of the rectangle. - optional Point hi = 2; -} - -// A feature names something at a given point. -// -// If a feature could not be named, the name is empty. -message Feature { - // The name of the feature. - optional string name = 1; - - // The point where the feature is detected. - optional Point location = 2; -} - -// A RouteNote is a message sent while at a given point. -message RouteNote { - // The location from which the message is sent. - optional Point location = 1; - - // The message to be sent. - optional string message = 2; -} - -// A RouteSummary is received in response to a RecordRoute rpc. -// -// It contains the number of individual points received, the number of -// detected features, and the total distance covered as the cumulative sum of -// the distance between each point. -message RouteSummary { - // The number of points received. - optional int32 point_count = 1; - - // The number of known features passed while traversing the route. - optional int32 feature_count = 2; - - // The distance covered in metres. - optional int32 distance = 3; - - // The duration of the traversal in seconds. - optional int32 elapsed_time = 4; -} diff --git a/examples/csharp/route_guide/RouteGuideClient/Program.cs b/examples/csharp/route_guide/RouteGuideClient/Program.cs index 0352c78020..4ddb526585 100644 --- a/examples/csharp/route_guide/RouteGuideClient/Program.cs +++ b/examples/csharp/route_guide/RouteGuideClient/Program.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace examples +namespace Examples { class Program { @@ -30,27 +30,24 @@ namespace examples { Log("*** GetFeature: lat={0} lon={1}", lat, lon); - Point request = Point.CreateBuilder().SetLatitude(lat).SetLongitude(lon).Build(); + Point request = new Point { Latitude = lat, Longitude = lon }; Feature feature = client.GetFeature(request); - if (RouteGuideUtil.Exists(feature)) + if (feature.Exists()) { Log("Found feature called \"{0}\" at {1}, {2}", - feature.Name, - RouteGuideUtil.GetLatitude(feature.Location), - RouteGuideUtil.GetLongitude(feature.Location)); + feature.Name, feature.Location.GetLatitude(), feature.Location.GetLongitude()); } else { Log("Found no feature at {0}, {1}", - RouteGuideUtil.GetLatitude(feature.Location), - RouteGuideUtil.GetLongitude(feature.Location)); + feature.Location.GetLatitude(), feature.Location.GetLongitude()); } } catch (RpcException e) { Log("RPC failed " + e); - throw e; + throw; } } @@ -65,18 +62,20 @@ namespace examples Log("*** ListFeatures: lowLat={0} lowLon={1} hiLat={2} hiLon={3}", lowLat, lowLon, hiLat, hiLon); - Rectangle request = - Rectangle.CreateBuilder() - .SetLo(Point.CreateBuilder().SetLatitude(lowLat).SetLongitude(lowLon).Build()) - .SetHi(Point.CreateBuilder().SetLatitude(hiLat).SetLongitude(hiLon).Build()).Build(); + Rectangle request = new Rectangle + { + Lo = new Point { Latitude = lowLat, Longitude = lowLon }, + Hi = new Point { Latitude = hiLat, Longitude = hiLon } + }; using (var call = client.ListFeatures(request)) { + var responseStream = call.ResponseStream; StringBuilder responseLog = new StringBuilder("Result: "); - while (await call.ResponseStream.MoveNext()) + while (await responseStream.MoveNext()) { - Feature feature = call.ResponseStream.Current; + Feature feature = responseStream.Current; responseLog.Append(feature.ToString()); } Log(responseLog.ToString()); @@ -85,7 +84,7 @@ namespace examples catch (RpcException e) { Log("RPC failed " + e); - throw e; + throw; } } @@ -107,8 +106,7 @@ namespace examples { int index = rand.Next(features.Count); Point point = features[index].Location; - Log("Visiting point {0}, {1}", RouteGuideUtil.GetLatitude(point), - RouteGuideUtil.GetLongitude(point)); + Log("Visiting point {0}, {1}", point.GetLatitude(), point.GetLongitude()); await call.RequestStream.WriteAsync(point); @@ -117,7 +115,7 @@ namespace examples } await call.RequestStream.CompleteAsync(); - RouteSummary summary = await call.Result; + RouteSummary summary = await call.ResponseAsync; Log("Finished trip with {0} points. Passed {1} features. " + "Travelled {2} meters. It took {3} seconds.", summary.PointCount, summary.FeatureCount, summary.Distance, summary.ElapsedTime); @@ -128,7 +126,7 @@ namespace examples catch (RpcException e) { Log("RPC failed", e); - throw e; + throw; } } @@ -141,8 +139,13 @@ namespace examples try { Log("*** RouteChat"); - var requests = - new List<RouteNote> { NewNote("First message", 0, 0), NewNote("Second message", 0, 1), NewNote("Third message", 1, 0), NewNote("Fourth message", 1, 1) }; + var requests = new List<RouteNote> + { + NewNote("First message", 0, 0), + NewNote("Second message", 0, 1), + NewNote("Third message", 1, 0), + NewNote("Fourth message", 0, 0) + }; using (var call = client.RouteChat()) { @@ -172,7 +175,7 @@ namespace examples catch (RpcException e) { Log("RPC failed", e); - throw e; + throw; } } @@ -188,36 +191,37 @@ namespace examples private RouteNote NewNote(string message, int lat, int lon) { - return RouteNote.CreateBuilder().SetMessage(message).SetLocation( - Point.CreateBuilder().SetLatitude(lat).SetLongitude(lat).Build()).Build(); + return new RouteNote + { + Message = message, + Location = new Point { Latitude = lat, Longitude = lon } + }; } } static void Main(string[] args) { - GrpcEnvironment.Initialize(); + var channel = new Channel("127.0.0.1:50052", Credentials.Insecure); + var client = new RouteGuideClient(RouteGuide.NewClient(channel)); - using (Channel channel = new Channel("127.0.0.1:50052")) - { - var client = new RouteGuideClient(RouteGuide.NewStub(channel)); - - // Looking for a valid feature - client.GetFeature(409146138, -746188906); + // Looking for a valid feature + client.GetFeature(409146138, -746188906); - // Feature missing. - client.GetFeature(0, 0); + // Feature missing. + client.GetFeature(0, 0); - // Looking for features between 40, -75 and 42, -73. - client.ListFeatures(400000000, -750000000, 420000000, -730000000).Wait(); + // Looking for features between 40, -75 and 42, -73. + client.ListFeatures(400000000, -750000000, 420000000, -730000000).Wait(); - // Record a few randomly selected points from the features file. - client.RecordRoute(RouteGuideUtil.ParseFeatures(RouteGuideUtil.DefaultFeaturesFile), 10).Wait(); + // Record a few randomly selected points from the features file. + client.RecordRoute(RouteGuideUtil.ParseFeatures(RouteGuideUtil.DefaultFeaturesFile), 10).Wait(); - // Send and receive some notes. - client.RouteChat().Wait(); - } + // Send and receive some notes. + client.RouteChat().Wait(); - GrpcEnvironment.Shutdown(); + channel.ShutdownAsync().Wait(); + Console.WriteLine("Press any key to exit..."); + Console.ReadKey(); } } } diff --git a/examples/csharp/route_guide/RouteGuideClient/RouteGuideClient.csproj b/examples/csharp/route_guide/RouteGuideClient/RouteGuideClient.csproj index 78034a9145..cf9e567f5e 100644 --- a/examples/csharp/route_guide/RouteGuideClient/RouteGuideClient.csproj +++ b/examples/csharp/route_guide/RouteGuideClient/RouteGuideClient.csproj @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <Import Project="..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.props" Condition="Exists('..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.props')" /> - <Import Project="..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.props" Condition="Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.props')" /> + <Import Project="..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.props" Condition="Exists('..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.props')" /> + <Import Project="..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.props" Condition="Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.props')" /> <Import Project="..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.props" Condition="Exists('..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> @@ -14,7 +14,7 @@ <AssemblyName>RouteGuideClient</AssemblyName> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> - <NuGetPackageImportStamp>794416d0</NuGetPackageImportStamp> + <NuGetPackageImportStamp>77622de6</NuGetPackageImportStamp> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> @@ -36,21 +36,14 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> - <Reference Include="Google.ProtocolBuffers"> - <HintPath>..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.dll</HintPath> + <Reference Include="Google.Protobuf"> + <HintPath>..\packages\Google.Protobuf.3.0.0-alpha4\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll</HintPath> </Reference> - <Reference Include="Google.ProtocolBuffers.Serialization"> - <HintPath>..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.Serialization.dll</HintPath> - </Reference> - <Reference Include="Grpc.Core, Version=0.6.5668.37363, Culture=neutral, processorArchitecture=MSIL"> + <Reference Include="Grpc.Core, Version=0.7.0.0, Culture=neutral, PublicKeyToken=d754f35622e28bad, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> - <HintPath>..\packages\Grpc.Core.0.6.0\lib\net45\Grpc.Core.dll</HintPath> + <HintPath>..\packages\Grpc.Core.0.7.0\lib\net45\Grpc.Core.dll</HintPath> </Reference> <Reference Include="System" /> - <Reference Include="System.Collections.Immutable, Version=1.1.36.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\packages\System.Collections.Immutable.1.1.36\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath> - </Reference> <Reference Include="System.Core" /> <Reference Include="System.Interactive.Async"> <HintPath>..\packages\Ix-Async.1.2.3\lib\net45\System.Interactive.Async.dll</HintPath> @@ -82,14 +75,14 @@ </PropertyGroup> <Error Condition="!Exists('..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.props'))" /> <Error Condition="!Exists('..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.targets'))" /> - <Error Condition="!Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.props'))" /> - <Error Condition="!Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.targets'))" /> - <Error Condition="!Exists('..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.props'))" /> - <Error Condition="!Exists('..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.targets'))" /> + <Error Condition="!Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.props'))" /> + <Error Condition="!Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.targets'))" /> + <Error Condition="!Exists('..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.props'))" /> + <Error Condition="!Exists('..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.targets'))" /> </Target> <Import Project="..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.targets" Condition="Exists('..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.targets')" /> - <Import Project="..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.targets" Condition="Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.targets')" /> - <Import Project="..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.targets" Condition="Exists('..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.targets')" /> + <Import Project="..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.targets" Condition="Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.targets')" /> + <Import Project="..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.targets" Condition="Exists('..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.targets')" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> diff --git a/examples/csharp/route_guide/RouteGuideClient/packages.config b/examples/csharp/route_guide/RouteGuideClient/packages.config index 5922553bc3..1273624cbd 100644 --- a/examples/csharp/route_guide/RouteGuideClient/packages.config +++ b/examples/csharp/route_guide/RouteGuideClient/packages.config @@ -1,11 +1,10 @@ <?xml version="1.0" encoding="utf-8"?> <packages> - <package id="Google.ProtocolBuffers" version="2.4.1.555" targetFramework="net45" /> - <package id="Grpc" version="0.6.0" targetFramework="net45" /> - <package id="Grpc.Core" version="0.6.0" targetFramework="net45" /> - <package id="grpc.dependencies.openssl.redist" version="1.0.2.2" targetFramework="net45" /> + <package id="Google.Protobuf" version="3.0.0-alpha4" targetFramework="net45" /> + <package id="Grpc" version="0.7.0" targetFramework="net45" /> + <package id="Grpc.Core" version="0.7.0" targetFramework="net45" /> + <package id="grpc.dependencies.openssl.redist" version="1.0.2.3" targetFramework="net45" /> <package id="grpc.dependencies.zlib.redist" version="1.2.8.9" targetFramework="net45" /> - <package id="grpc.native.csharp_ext" version="0.10.0" targetFramework="net45" /> + <package id="grpc.native.csharp_ext" version="0.11.0" targetFramework="net45" /> <package id="Ix-Async" version="1.2.3" targetFramework="net45" /> - <package id="System.Collections.Immutable" version="1.1.36" targetFramework="net45" /> </packages>
\ No newline at end of file diff --git a/examples/csharp/route_guide/RouteGuideServer/Program.cs b/examples/csharp/route_guide/RouteGuideServer/Program.cs index e00b4d6723..0a4d73f391 100644 --- a/examples/csharp/route_guide/RouteGuideServer/Program.cs +++ b/examples/csharp/route_guide/RouteGuideServer/Program.cs @@ -5,26 +5,28 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace examples +namespace Examples { class Program { static void Main(string[] args) { + const int Port = 50052; + var features = RouteGuideUtil.ParseFeatures(RouteGuideUtil.DefaultFeaturesFile); - GrpcEnvironment.Initialize(); - Server server = new Server(); - server.AddServiceDefinition(RouteGuide.BindService(new RouteGuideImpl(features))); - int port = server.AddListeningPort("localhost", 50052); + Server server = new Server + { + Services = { RouteGuide.BindService(new RouteGuideImpl(features)) }, + Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) } + }; server.Start(); - Console.WriteLine("RouteGuide server listening on port " + port); + Console.WriteLine("RouteGuide server listening on port " + Port); Console.WriteLine("Press any key to stop the server..."); Console.ReadKey(); server.ShutdownAsync().Wait(); - GrpcEnvironment.Shutdown(); } } } diff --git a/examples/csharp/route_guide/RouteGuideServer/RouteGuideImpl.cs b/examples/csharp/route_guide/RouteGuideServer/RouteGuideImpl.cs index 0bdf386fc3..fbe0f4471c 100644 --- a/examples/csharp/route_guide/RouteGuideServer/RouteGuideImpl.cs +++ b/examples/csharp/route_guide/RouteGuideServer/RouteGuideImpl.cs @@ -6,7 +6,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace examples +using Grpc.Core.Utils; + +namespace Examples { /// <summary> /// Example implementation of RouteGuide server. @@ -14,8 +16,8 @@ namespace examples public class RouteGuideImpl : RouteGuide.IRouteGuide { readonly List<Feature> features; - private readonly ConcurrentDictionary<Point, List<RouteNote>> routeNotes = - new ConcurrentDictionary<Point, List<RouteNote>>(); + readonly object myLock = new object(); + readonly Dictionary<Point, List<RouteNote>> routeNotes = new Dictionary<Point, List<RouteNote>>(); public RouteGuideImpl(List<Feature> features) { @@ -26,7 +28,7 @@ namespace examples /// Gets the feature at the requested point. If no feature at that location /// exists, an unnammed feature is returned at the provided location. /// </summary> - public Task<Feature> GetFeature(Grpc.Core.ServerCallContext context, Point request) + public Task<Feature> GetFeature(Point request, Grpc.Core.ServerCallContext context) { return Task.FromResult(CheckFeature(request)); } @@ -34,26 +36,12 @@ namespace examples /// <summary> /// Gets all features contained within the given bounding rectangle. /// </summary> - public async Task ListFeatures(Grpc.Core.ServerCallContext context, Rectangle request, Grpc.Core.IServerStreamWriter<Feature> responseStream) + public async Task ListFeatures(Rectangle request, Grpc.Core.IServerStreamWriter<Feature> responseStream, Grpc.Core.ServerCallContext context) { - int left = Math.Min(request.Lo.Longitude, request.Hi.Longitude); - int right = Math.Max(request.Lo.Longitude, request.Hi.Longitude); - int top = Math.Max(request.Lo.Latitude, request.Hi.Latitude); - int bottom = Math.Min(request.Lo.Latitude, request.Hi.Latitude); - - foreach (var feature in features) + var responses = features.FindAll( (feature) => feature.Exists() && request.Contains(feature.Location) ); + foreach (var response in responses) { - if (!RouteGuideUtil.Exists(feature)) - { - continue; - } - - int lat = feature.Location.Latitude; - int lon = feature.Location.Longitude; - if (lon >= left && lon <= right && lat >= bottom && lat <= top) - { - await responseStream.WriteAsync(feature); - } + await responseStream.WriteAsync(response); } } @@ -61,7 +49,7 @@ namespace examples /// Gets a stream of points, and responds with statistics about the "trip": number of points, /// number of known features visited, total distance traveled, and total time spent. /// </summary> - public async Task<RouteSummary> RecordRoute(Grpc.Core.ServerCallContext context, Grpc.Core.IAsyncStreamReader<Point> requestStream) + public async Task<RouteSummary> RecordRoute(Grpc.Core.IAsyncStreamReader<Point> requestStream, Grpc.Core.ServerCallContext context) { int pointCount = 0; int featureCount = 0; @@ -74,61 +62,61 @@ namespace examples { var point = requestStream.Current; pointCount++; - if (RouteGuideUtil.Exists(CheckFeature(point))) + if (CheckFeature(point).Exists()) { featureCount++; } if (previous != null) { - distance += (int) CalcDistance(previous, point); + distance += (int) previous.GetDistance(point); } previous = point; } stopwatch.Stop(); - return RouteSummary.CreateBuilder().SetPointCount(pointCount) - .SetFeatureCount(featureCount).SetDistance(distance) - .SetElapsedTime((int) (stopwatch.ElapsedMilliseconds / 1000)).Build(); + + return new RouteSummary + { + PointCount = pointCount, + FeatureCount = featureCount, + Distance = distance, + ElapsedTime = (int)(stopwatch.ElapsedMilliseconds / 1000) + }; } /// <summary> /// Receives a stream of message/location pairs, and responds with a stream of all previous /// messages at each of those locations. /// </summary> - public async Task RouteChat(Grpc.Core.ServerCallContext context, Grpc.Core.IAsyncStreamReader<RouteNote> requestStream, Grpc.Core.IServerStreamWriter<RouteNote> responseStream) + public async Task RouteChat(Grpc.Core.IAsyncStreamReader<RouteNote> requestStream, Grpc.Core.IServerStreamWriter<RouteNote> responseStream, Grpc.Core.ServerCallContext context) { while (await requestStream.MoveNext()) { var note = requestStream.Current; - List<RouteNote> notes = GetOrCreateNotes(note.Location); - - List<RouteNote> prevNotes; - lock (notes) - { - prevNotes = new List<RouteNote>(notes); - } - + List<RouteNote> prevNotes = AddNoteForLocation(note.Location, note); foreach (var prevNote in prevNotes) { await responseStream.WriteAsync(prevNote); - } - - lock (notes) - { - notes.Add(note); } } } - /// <summary> - /// Get the notes list for the given location. If missing, create it. + /// Adds a note for location and returns a list of pre-existing notes for that location (not containing the newly added note). /// </summary> - private List<RouteNote> GetOrCreateNotes(Point location) + private List<RouteNote> AddNoteForLocation(Point location, RouteNote note) { - List<RouteNote> notes = new List<RouteNote>(); - routeNotes.TryAdd(location, notes); - return routeNotes[location]; + lock (myLock) + { + List<RouteNote> notes; + if (!routeNotes.TryGetValue(location, out notes)) { + notes = new List<RouteNote>(); + routeNotes.Add(location, notes); + } + var preexistingNotes = new List<RouteNote>(notes); + notes.Add(note); + return preexistingNotes; + } } /// <summary> @@ -138,47 +126,13 @@ namespace examples /// <returns>The feature object at the point Note that an empty name indicates no feature.</returns> private Feature CheckFeature(Point location) { - foreach (var feature in features) + var result = features.FirstOrDefault((feature) => feature.Location.Equals(location)); + if (result == null) { - if (feature.Location.Latitude == location.Latitude - && feature.Location.Longitude == location.Longitude) - { - return feature; - } + // No feature was found, return an unnamed feature. + return new Feature { Name = "", Location = location }; } - - // No feature was found, return an unnamed feature. - return Feature.CreateBuilder().SetName("").SetLocation(location).Build(); - } - - /// <summary> - /// Calculate the distance between two points using the "haversine" formula. - /// This code was taken from http://www.movable-type.co.uk/scripts/latlong.html. - /// </summary> - /// <param name="start">the starting point</param> - /// <param name="end">the end point</param> - /// <returns>the distance between the points in meters</returns> - private static double CalcDistance(Point start, Point end) - { - double lat1 = RouteGuideUtil.GetLatitude(start); - double lat2 = RouteGuideUtil.GetLatitude(end); - double lon1 = RouteGuideUtil.GetLongitude(start); - double lon2 = RouteGuideUtil.GetLongitude(end); - int r = 6371000; // metres - double φ1 = ToRadians(lat1); - double φ2 = ToRadians(lat2); - double Δφ = ToRadians(lat2 - lat1); - double Δλ = ToRadians(lon2 - lon1); - - double a = Math.Sin(Δφ / 2) * Math.Sin(Δφ / 2) + Math.Cos(φ1) * Math.Cos(φ2) * Math.Sin(Δλ / 2) * Math.Sin(Δλ / 2); - double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); - - return r * c; - } - - private static double ToRadians(double val) - { - return (Math.PI / 180) * val; + return result; } } } diff --git a/examples/csharp/route_guide/RouteGuideServer/RouteGuideServer.csproj b/examples/csharp/route_guide/RouteGuideServer/RouteGuideServer.csproj index 9ac1cfbf4d..55e1331c46 100644 --- a/examples/csharp/route_guide/RouteGuideServer/RouteGuideServer.csproj +++ b/examples/csharp/route_guide/RouteGuideServer/RouteGuideServer.csproj @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <Import Project="..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.props" Condition="Exists('..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.props')" /> - <Import Project="..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.props" Condition="Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.props')" /> + <Import Project="..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.props" Condition="Exists('..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.props')" /> + <Import Project="..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.props" Condition="Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.props')" /> <Import Project="..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.props" Condition="Exists('..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> @@ -14,7 +14,7 @@ <AssemblyName>RouteGuideServer</AssemblyName> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> - <NuGetPackageImportStamp>74781d8b</NuGetPackageImportStamp> + <NuGetPackageImportStamp>568005e2</NuGetPackageImportStamp> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> @@ -36,21 +36,14 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> - <Reference Include="Google.ProtocolBuffers"> - <HintPath>..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.dll</HintPath> + <Reference Include="Google.Protobuf"> + <HintPath>..\packages\Google.Protobuf.3.0.0-alpha4\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll</HintPath> </Reference> - <Reference Include="Google.ProtocolBuffers.Serialization"> - <HintPath>..\packages\Google.ProtocolBuffers.2.4.1.555\lib\net40\Google.ProtocolBuffers.Serialization.dll</HintPath> - </Reference> - <Reference Include="Grpc.Core, Version=0.6.5668.37363, Culture=neutral, processorArchitecture=MSIL"> + <Reference Include="Grpc.Core, Version=0.7.0.0, Culture=neutral, PublicKeyToken=d754f35622e28bad, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> - <HintPath>..\packages\Grpc.Core.0.6.0\lib\net45\Grpc.Core.dll</HintPath> + <HintPath>..\packages\Grpc.Core.0.7.0\lib\net45\Grpc.Core.dll</HintPath> </Reference> <Reference Include="System" /> - <Reference Include="System.Collections.Immutable, Version=1.1.36.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\packages\System.Collections.Immutable.1.1.36\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath> - </Reference> <Reference Include="System.Core" /> <Reference Include="System.Interactive.Async"> <HintPath>..\packages\Ix-Async.1.2.3\lib\net45\System.Interactive.Async.dll</HintPath> @@ -83,14 +76,14 @@ </PropertyGroup> <Error Condition="!Exists('..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.props'))" /> <Error Condition="!Exists('..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.targets'))" /> - <Error Condition="!Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.props'))" /> - <Error Condition="!Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.targets'))" /> - <Error Condition="!Exists('..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.props'))" /> - <Error Condition="!Exists('..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.targets'))" /> + <Error Condition="!Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.props'))" /> + <Error Condition="!Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.targets'))" /> + <Error Condition="!Exists('..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.props'))" /> + <Error Condition="!Exists('..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.targets'))" /> </Target> <Import Project="..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.targets" Condition="Exists('..\packages\grpc.dependencies.zlib.redist.1.2.8.9\build\portable-net45\grpc.dependencies.zlib.redist.targets')" /> - <Import Project="..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.targets" Condition="Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.2\build\portable-net45\grpc.dependencies.openssl.redist.targets')" /> - <Import Project="..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.targets" Condition="Exists('..\packages\grpc.native.csharp_ext.0.10.0\build\portable-net45\grpc.native.csharp_ext.targets')" /> + <Import Project="..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.targets" Condition="Exists('..\packages\grpc.dependencies.openssl.redist.1.0.2.3\build\portable-net45\grpc.dependencies.openssl.redist.targets')" /> + <Import Project="..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.targets" Condition="Exists('..\packages\grpc.native.csharp_ext.0.11.0\build\portable-net45\grpc.native.csharp_ext.targets')" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> diff --git a/examples/csharp/route_guide/RouteGuideServer/packages.config b/examples/csharp/route_guide/RouteGuideServer/packages.config index 5922553bc3..1273624cbd 100644 --- a/examples/csharp/route_guide/RouteGuideServer/packages.config +++ b/examples/csharp/route_guide/RouteGuideServer/packages.config @@ -1,11 +1,10 @@ <?xml version="1.0" encoding="utf-8"?> <packages> - <package id="Google.ProtocolBuffers" version="2.4.1.555" targetFramework="net45" /> - <package id="Grpc" version="0.6.0" targetFramework="net45" /> - <package id="Grpc.Core" version="0.6.0" targetFramework="net45" /> - <package id="grpc.dependencies.openssl.redist" version="1.0.2.2" targetFramework="net45" /> + <package id="Google.Protobuf" version="3.0.0-alpha4" targetFramework="net45" /> + <package id="Grpc" version="0.7.0" targetFramework="net45" /> + <package id="Grpc.Core" version="0.7.0" targetFramework="net45" /> + <package id="grpc.dependencies.openssl.redist" version="1.0.2.3" targetFramework="net45" /> <package id="grpc.dependencies.zlib.redist" version="1.2.8.9" targetFramework="net45" /> - <package id="grpc.native.csharp_ext" version="0.10.0" targetFramework="net45" /> + <package id="grpc.native.csharp_ext" version="0.11.0" targetFramework="net45" /> <package id="Ix-Async" version="1.2.3" targetFramework="net45" /> - <package id="System.Collections.Immutable" version="1.1.36" targetFramework="net45" /> </packages>
\ No newline at end of file diff --git a/examples/csharp/route_guide/generate_protos.bat b/examples/csharp/route_guide/generate_protos.bat new file mode 100644 index 0000000000..fb0dc5516b --- /dev/null +++ b/examples/csharp/route_guide/generate_protos.bat @@ -0,0 +1,10 @@ +@rem Generate the C# code for .proto files + +setlocal + +@rem enter this directory +cd /d %~dp0 + +packages\Google.Protobuf.3.0.0-alpha4\tools\protoc.exe -I../../protos --csharp_out RouteGuide ../../protos/route_guide.proto --grpc_out RouteGuide --plugin=protoc-gen-grpc=packages\Grpc.Tools.0.7.0\tools\grpc_csharp_plugin.exe + +endlocal
\ No newline at end of file |