Jan Tattermusch | a7fff86 | 2015-02-13 11:08:08 -0800 | [diff] [blame] | 1 | #region Copyright notice and license |
| 2 | |
Jan Tattermusch | af77b3d | 2015-02-13 11:22:21 -0800 | [diff] [blame] | 3 | // Copyright 2015, Google Inc. |
Jan Tattermusch | a7fff86 | 2015-02-13 11:08:08 -0800 | [diff] [blame] | 4 | // All rights reserved. |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 5 | // |
Jan Tattermusch | a7fff86 | 2015-02-13 11:08:08 -0800 | [diff] [blame] | 6 | // Redistribution and use in source and binary forms, with or without |
| 7 | // modification, are permitted provided that the following conditions are |
| 8 | // met: |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 9 | // |
Jan Tattermusch | a7fff86 | 2015-02-13 11:08:08 -0800 | [diff] [blame] | 10 | // * Redistributions of source code must retain the above copyright |
| 11 | // notice, this list of conditions and the following disclaimer. |
| 12 | // * Redistributions in binary form must reproduce the above |
| 13 | // copyright notice, this list of conditions and the following disclaimer |
| 14 | // in the documentation and/or other materials provided with the |
| 15 | // distribution. |
| 16 | // * Neither the name of Google Inc. nor the names of its |
| 17 | // contributors may be used to endorse or promote products derived from |
| 18 | // this software without specific prior written permission. |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 19 | // |
Jan Tattermusch | a7fff86 | 2015-02-13 11:08:08 -0800 | [diff] [blame] | 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | |
| 32 | #endregion |
| 33 | |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 34 | using System; |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 35 | using System.Collections.Generic; |
| 36 | using System.Reactive.Linq; |
Jan Tattermusch | 3086862 | 2015-02-19 09:22:33 -0800 | [diff] [blame] | 37 | using System.Threading; |
| 38 | using System.Threading.Tasks; |
| 39 | using Grpc.Core; |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 40 | |
| 41 | namespace math |
| 42 | { |
| 43 | /// <summary> |
| 44 | /// Math service definitions (this is handwritten version of code that will normally be generated). |
| 45 | /// </summary> |
| 46 | public class MathGrpc |
| 47 | { |
Jan Tattermusch | c0b3721 | 2015-03-13 08:35:41 -0700 | [diff] [blame] | 48 | static readonly string ServiceName = "/math.Math"; |
| 49 | |
Jan Tattermusch | 3de9f49 | 2015-03-12 12:53:50 -0700 | [diff] [blame] | 50 | static readonly Marshaller<DivArgs> DivArgsMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), DivArgs.ParseFrom); |
| 51 | static readonly Marshaller<DivReply> DivReplyMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), DivReply.ParseFrom); |
| 52 | static readonly Marshaller<Num> NumMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), Num.ParseFrom); |
| 53 | static readonly Marshaller<FibArgs> FibArgsMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), FibArgs.ParseFrom); |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 54 | |
Jan Tattermusch | 3de9f49 | 2015-03-12 12:53:50 -0700 | [diff] [blame] | 55 | static readonly Method<DivArgs, DivReply> DivMethod = new Method<DivArgs, DivReply>( |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 56 | MethodType.Unary, |
Jan Tattermusch | c0b3721 | 2015-03-13 08:35:41 -0700 | [diff] [blame] | 57 | "Div", |
Jan Tattermusch | 3de9f49 | 2015-03-12 12:53:50 -0700 | [diff] [blame] | 58 | DivArgsMarshaller, |
| 59 | DivReplyMarshaller); |
| 60 | |
| 61 | static readonly Method<FibArgs, Num> FibMethod = new Method<FibArgs, Num>( |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 62 | MethodType.ServerStreaming, |
Jan Tattermusch | c0b3721 | 2015-03-13 08:35:41 -0700 | [diff] [blame] | 63 | "Fib", |
Jan Tattermusch | 3de9f49 | 2015-03-12 12:53:50 -0700 | [diff] [blame] | 64 | FibArgsMarshaller, |
| 65 | NumMarshaller); |
| 66 | |
| 67 | static readonly Method<Num, Num> SumMethod = new Method<Num, Num>( |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 68 | MethodType.ClientStreaming, |
Jan Tattermusch | c0b3721 | 2015-03-13 08:35:41 -0700 | [diff] [blame] | 69 | "Sum", |
Jan Tattermusch | 3de9f49 | 2015-03-12 12:53:50 -0700 | [diff] [blame] | 70 | NumMarshaller, |
| 71 | NumMarshaller); |
| 72 | |
| 73 | static readonly Method<DivArgs, DivReply> DivManyMethod = new Method<DivArgs, DivReply>( |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 74 | MethodType.DuplexStreaming, |
Jan Tattermusch | c0b3721 | 2015-03-13 08:35:41 -0700 | [diff] [blame] | 75 | "DivMany", |
Jan Tattermusch | 3de9f49 | 2015-03-12 12:53:50 -0700 | [diff] [blame] | 76 | DivArgsMarshaller, |
| 77 | DivReplyMarshaller); |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 78 | |
| 79 | public interface IMathServiceClient |
| 80 | { |
| 81 | DivReply Div(DivArgs request, CancellationToken token = default(CancellationToken)); |
| 82 | |
| 83 | Task<DivReply> DivAsync(DivArgs request, CancellationToken token = default(CancellationToken)); |
| 84 | |
Jan Tattermusch | 337a2dd | 2015-02-13 15:41:41 -0800 | [diff] [blame] | 85 | void Fib(FibArgs request, IObserver<Num> responseObserver, CancellationToken token = default(CancellationToken)); |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 86 | |
| 87 | ClientStreamingAsyncResult<Num, Num> Sum(CancellationToken token = default(CancellationToken)); |
| 88 | |
| 89 | IObserver<DivArgs> DivMany(IObserver<DivReply> responseObserver, CancellationToken token = default(CancellationToken)); |
| 90 | } |
| 91 | |
Jan Tattermusch | c0b3721 | 2015-03-13 08:35:41 -0700 | [diff] [blame] | 92 | public class MathServiceClientStub : AbstractStub<MathServiceClientStub, StubConfiguration>, IMathServiceClient |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 93 | { |
Jan Tattermusch | c0b3721 | 2015-03-13 08:35:41 -0700 | [diff] [blame] | 94 | public MathServiceClientStub(Channel channel) : this(channel, StubConfiguration.Default) |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 95 | { |
Jan Tattermusch | c0b3721 | 2015-03-13 08:35:41 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | public MathServiceClientStub(Channel channel, StubConfiguration config) : base(channel, config) |
| 99 | { |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | public DivReply Div(DivArgs request, CancellationToken token = default(CancellationToken)) |
| 103 | { |
Jan Tattermusch | c0b3721 | 2015-03-13 08:35:41 -0700 | [diff] [blame] | 104 | var call = CreateCall(ServiceName, DivMethod); |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 105 | return Calls.BlockingUnaryCall(call, request, token); |
| 106 | } |
| 107 | |
| 108 | public Task<DivReply> DivAsync(DivArgs request, CancellationToken token = default(CancellationToken)) |
| 109 | { |
Jan Tattermusch | c0b3721 | 2015-03-13 08:35:41 -0700 | [diff] [blame] | 110 | var call = CreateCall(ServiceName, DivMethod); |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 111 | return Calls.AsyncUnaryCall(call, request, token); |
| 112 | } |
| 113 | |
Jan Tattermusch | 337a2dd | 2015-02-13 15:41:41 -0800 | [diff] [blame] | 114 | public void Fib(FibArgs request, IObserver<Num> responseObserver, CancellationToken token = default(CancellationToken)) |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 115 | { |
Jan Tattermusch | c0b3721 | 2015-03-13 08:35:41 -0700 | [diff] [blame] | 116 | var call = CreateCall(ServiceName, FibMethod); |
Jan Tattermusch | 337a2dd | 2015-02-13 15:41:41 -0800 | [diff] [blame] | 117 | Calls.AsyncServerStreamingCall(call, request, responseObserver, token); |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | public ClientStreamingAsyncResult<Num, Num> Sum(CancellationToken token = default(CancellationToken)) |
| 121 | { |
Jan Tattermusch | c0b3721 | 2015-03-13 08:35:41 -0700 | [diff] [blame] | 122 | var call = CreateCall(ServiceName, SumMethod); |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 123 | return Calls.AsyncClientStreamingCall(call, token); |
| 124 | } |
| 125 | |
| 126 | public IObserver<DivArgs> DivMany(IObserver<DivReply> responseObserver, CancellationToken token = default(CancellationToken)) |
| 127 | { |
Jan Tattermusch | c0b3721 | 2015-03-13 08:35:41 -0700 | [diff] [blame] | 128 | var call = CreateCall(ServiceName, DivManyMethod); |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 129 | return Calls.DuplexStreamingCall(call, responseObserver, token); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | // server-side interface |
| 134 | public interface IMathService |
| 135 | { |
| 136 | void Div(DivArgs request, IObserver<DivReply> responseObserver); |
| 137 | |
| 138 | void Fib(FibArgs request, IObserver<Num> responseObserver); |
| 139 | |
| 140 | IObserver<Num> Sum(IObserver<Num> responseObserver); |
| 141 | |
| 142 | IObserver<DivArgs> DivMany(IObserver<DivReply> responseObserver); |
| 143 | } |
| 144 | |
| 145 | public static ServerServiceDefinition BindService(IMathService serviceImpl) |
| 146 | { |
Jan Tattermusch | c0b3721 | 2015-03-13 08:35:41 -0700 | [diff] [blame] | 147 | return ServerServiceDefinition.CreateBuilder(ServiceName) |
Jan Tattermusch | 3de9f49 | 2015-03-12 12:53:50 -0700 | [diff] [blame] | 148 | .AddMethod(DivMethod, serviceImpl.Div) |
| 149 | .AddMethod(FibMethod, serviceImpl.Fib) |
| 150 | .AddMethod(SumMethod, serviceImpl.Sum) |
| 151 | .AddMethod(DivManyMethod, serviceImpl.DivMany).Build(); |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | public static IMathServiceClient NewStub(Channel channel) |
| 155 | { |
| 156 | return new MathServiceClientStub(channel); |
| 157 | } |
Jan Tattermusch | c0b3721 | 2015-03-13 08:35:41 -0700 | [diff] [blame] | 158 | |
| 159 | public static IMathServiceClient NewStub(Channel channel, StubConfiguration config) |
| 160 | { |
| 161 | return new MathServiceClientStub(channel, config); |
| 162 | } |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 163 | } |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 164 | } |