Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame^] | 1 | using System; |
| 2 | using System.Threading; |
| 3 | using System.Threading.Tasks; |
| 4 | using System.Collections.Generic; |
| 5 | using System.Reactive.Linq; |
| 6 | using Google.GRPC.Core; |
| 7 | |
| 8 | namespace math |
| 9 | { |
| 10 | /// <summary> |
| 11 | /// Implementation of math service stub (this is handwritten version of code |
| 12 | /// that will normally be generated). |
| 13 | /// </summary> |
| 14 | public class MathServiceClientStub : IMathServiceClient |
| 15 | { |
| 16 | readonly Channel channel; |
| 17 | readonly TimeSpan methodTimeout; |
| 18 | |
| 19 | public MathServiceClientStub(Channel channel, TimeSpan methodTimeout) |
| 20 | { |
| 21 | this.channel = channel; |
| 22 | this.methodTimeout = methodTimeout; |
| 23 | } |
| 24 | |
| 25 | public DivReply Div(DivArgs args, CancellationToken token = default(CancellationToken)) |
| 26 | { |
| 27 | var call = new Google.GRPC.Core.Call<DivArgs, DivReply>("/math.Math/Div", Serialize_DivArgs, Deserialize_DivReply, methodTimeout, channel); |
| 28 | return Calls.BlockingUnaryCall(call, args, token); |
| 29 | } |
| 30 | |
| 31 | public Task<DivReply> DivAsync(DivArgs args, CancellationToken token = default(CancellationToken)) |
| 32 | { |
| 33 | var call = new Google.GRPC.Core.Call<DivArgs, DivReply>("/math.Math/Div", Serialize_DivArgs, Deserialize_DivReply, methodTimeout, channel); |
| 34 | return Calls.AsyncUnaryCall(call, args, token); |
| 35 | } |
| 36 | |
| 37 | public Task Fib(FibArgs args, IObserver<Num> outputs, CancellationToken token = default(CancellationToken)) |
| 38 | { |
| 39 | var call = new Google.GRPC.Core.Call<FibArgs, Num>("/math.Math/Fib", Serialize_FibArgs, Deserialize_Num, methodTimeout, channel); |
| 40 | return Calls.AsyncServerStreamingCall(call, args, outputs, token); |
| 41 | } |
| 42 | |
| 43 | public ClientStreamingAsyncResult<Num, Num> Sum(CancellationToken token = default(CancellationToken)) |
| 44 | { |
| 45 | var call = new Google.GRPC.Core.Call<Num, Num>("/math.Math/Sum", Serialize_Num, Deserialize_Num, methodTimeout, channel); |
| 46 | return Calls.AsyncClientStreamingCall(call, token); |
| 47 | } |
| 48 | |
| 49 | public IObserver<DivArgs> DivMany(IObserver<DivReply> outputs, CancellationToken token = default(CancellationToken)) |
| 50 | { |
| 51 | var call = new Google.GRPC.Core.Call<DivArgs, DivReply>("/math.Math/DivMany", Serialize_DivArgs, Deserialize_DivReply, methodTimeout, channel); |
| 52 | return Calls.DuplexStreamingCall(call, outputs, token); |
| 53 | } |
| 54 | |
| 55 | private static byte[] Serialize_DivArgs(DivArgs arg) { |
| 56 | return arg.ToByteArray(); |
| 57 | } |
| 58 | |
| 59 | private static byte[] Serialize_FibArgs(FibArgs arg) { |
| 60 | return arg.ToByteArray(); |
| 61 | } |
| 62 | |
| 63 | private static byte[] Serialize_Num(Num arg) { |
| 64 | return arg.ToByteArray(); |
| 65 | } |
| 66 | |
| 67 | private static DivReply Deserialize_DivReply(byte[] payload) { |
| 68 | return DivReply.CreateBuilder().MergeFrom(payload).Build(); |
| 69 | } |
| 70 | |
| 71 | private static Num Deserialize_Num(byte[] payload) { |
| 72 | return Num.CreateBuilder().MergeFrom(payload).Build(); |
| 73 | } |
| 74 | } |
| 75 | } |