OLD | NEW |
(Empty) | |
| 1 #region Copyright notice and license |
| 2 |
| 3 // Copyright 2015, Google Inc. |
| 4 // All rights reserved. |
| 5 // |
| 6 // Redistribution and use in source and binary forms, with or without |
| 7 // modification, are permitted provided that the following conditions are |
| 8 // met: |
| 9 // |
| 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. |
| 19 // |
| 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 |
| 34 using System; |
| 35 using System.Collections.Generic; |
| 36 using System.Threading; |
| 37 using System.Threading.Tasks; |
| 38 using Grpc.Core; |
| 39 |
| 40 namespace grpc.testing |
| 41 { |
| 42 /// <summary> |
| 43 /// TestService (this is handwritten version of code that will normally be g
enerated). |
| 44 /// </summary> |
| 45 public class TestServiceGrpc |
| 46 { |
| 47 static readonly string ServiceName = "/grpc.testing.TestService"; |
| 48 |
| 49 static readonly Marshaller<Empty> EmptyMarshaller = Marshallers.Create((
arg) => arg.ToByteArray(), Empty.ParseFrom); |
| 50 static readonly Marshaller<SimpleRequest> SimpleRequestMarshaller = Mars
hallers.Create((arg) => arg.ToByteArray(), SimpleRequest.ParseFrom); |
| 51 static readonly Marshaller<SimpleResponse> SimpleResponseMarshaller = Ma
rshallers.Create((arg) => arg.ToByteArray(), SimpleResponse.ParseFrom); |
| 52 static readonly Marshaller<StreamingOutputCallRequest> StreamingOutputCa
llRequestMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), StreamingOu
tputCallRequest.ParseFrom); |
| 53 static readonly Marshaller<StreamingOutputCallResponse> StreamingOutputC
allResponseMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), Streaming
OutputCallResponse.ParseFrom); |
| 54 static readonly Marshaller<StreamingInputCallRequest> StreamingInputCall
RequestMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), StreamingInpu
tCallRequest.ParseFrom); |
| 55 static readonly Marshaller<StreamingInputCallResponse> StreamingInputCal
lResponseMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), StreamingIn
putCallResponse.ParseFrom); |
| 56 |
| 57 static readonly Method<Empty, Empty> EmptyCallMethod = new Method<Empty,
Empty>( |
| 58 MethodType.Unary, |
| 59 "EmptyCall", |
| 60 EmptyMarshaller, |
| 61 EmptyMarshaller); |
| 62 |
| 63 static readonly Method<SimpleRequest, SimpleResponse> UnaryCallMethod =
new Method<SimpleRequest, SimpleResponse>( |
| 64 MethodType.Unary, |
| 65 "UnaryCall", |
| 66 SimpleRequestMarshaller, |
| 67 SimpleResponseMarshaller); |
| 68 |
| 69 static readonly Method<StreamingOutputCallRequest, StreamingOutputCallRe
sponse> StreamingOutputCallMethod = new Method<StreamingOutputCallRequest, Strea
mingOutputCallResponse>( |
| 70 MethodType.ServerStreaming, |
| 71 "StreamingOutputCall", |
| 72 StreamingOutputCallRequestMarshaller, |
| 73 StreamingOutputCallResponseMarshaller); |
| 74 |
| 75 static readonly Method<StreamingInputCallRequest, StreamingInputCallResp
onse> StreamingInputCallMethod = new Method<StreamingInputCallRequest, Streaming
InputCallResponse>( |
| 76 MethodType.ClientStreaming, |
| 77 "StreamingInputCall", |
| 78 StreamingInputCallRequestMarshaller, |
| 79 StreamingInputCallResponseMarshaller); |
| 80 |
| 81 static readonly Method<StreamingOutputCallRequest, StreamingOutputCallRe
sponse> FullDuplexCallMethod = new Method<StreamingOutputCallRequest, StreamingO
utputCallResponse>( |
| 82 MethodType.DuplexStreaming, |
| 83 "FullDuplexCall", |
| 84 StreamingOutputCallRequestMarshaller, |
| 85 StreamingOutputCallResponseMarshaller); |
| 86 |
| 87 static readonly Method<StreamingOutputCallRequest, StreamingOutputCallRe
sponse> HalfDuplexCallMethod = new Method<StreamingOutputCallRequest, StreamingO
utputCallResponse>( |
| 88 MethodType.DuplexStreaming, |
| 89 "HalfDuplexCall", |
| 90 StreamingOutputCallRequestMarshaller, |
| 91 StreamingOutputCallResponseMarshaller); |
| 92 |
| 93 public interface ITestServiceClient |
| 94 { |
| 95 Empty EmptyCall(Empty request, CancellationToken token = default(Can
cellationToken)); |
| 96 |
| 97 Task<Empty> EmptyCallAsync(Empty request, CancellationToken token =
default(CancellationToken)); |
| 98 |
| 99 SimpleResponse UnaryCall(SimpleRequest request, CancellationToken to
ken = default(CancellationToken)); |
| 100 |
| 101 Task<SimpleResponse> UnaryCallAsync(SimpleRequest request, Cancellat
ionToken token = default(CancellationToken)); |
| 102 |
| 103 AsyncServerStreamingCall<StreamingOutputCallResponse> StreamingOutpu
tCall(StreamingOutputCallRequest request, CancellationToken token = default(Canc
ellationToken)); |
| 104 |
| 105 AsyncClientStreamingCall<StreamingInputCallRequest, StreamingInputCa
llResponse> StreamingInputCall(CancellationToken token = default(CancellationTok
en)); |
| 106 |
| 107 AsyncDuplexStreamingCall<StreamingOutputCallRequest, StreamingOutput
CallResponse> FullDuplexCall(CancellationToken token = default(CancellationToken
)); |
| 108 |
| 109 AsyncDuplexStreamingCall<StreamingOutputCallRequest, StreamingOutput
CallResponse> HalfDuplexCall(CancellationToken token = default(CancellationToken
)); |
| 110 } |
| 111 |
| 112 public class TestServiceClientStub : AbstractStub<TestServiceClientStub,
StubConfiguration>, ITestServiceClient |
| 113 { |
| 114 public TestServiceClientStub(Channel channel) : base(channel, StubCo
nfiguration.Default) |
| 115 { |
| 116 } |
| 117 |
| 118 public TestServiceClientStub(Channel channel, StubConfiguration conf
ig) : base(channel, config) |
| 119 { |
| 120 } |
| 121 |
| 122 public Empty EmptyCall(Empty request, CancellationToken token = defa
ult(CancellationToken)) |
| 123 { |
| 124 var call = CreateCall(ServiceName, EmptyCallMethod); |
| 125 return Calls.BlockingUnaryCall(call, request, token); |
| 126 } |
| 127 |
| 128 public Task<Empty> EmptyCallAsync(Empty request, CancellationToken t
oken = default(CancellationToken)) |
| 129 { |
| 130 var call = CreateCall(ServiceName, EmptyCallMethod); |
| 131 return Calls.AsyncUnaryCall(call, request, token); |
| 132 } |
| 133 |
| 134 public SimpleResponse UnaryCall(SimpleRequest request, CancellationT
oken token = default(CancellationToken)) |
| 135 { |
| 136 var call = CreateCall(ServiceName, UnaryCallMethod); |
| 137 return Calls.BlockingUnaryCall(call, request, token); |
| 138 } |
| 139 |
| 140 public Task<SimpleResponse> UnaryCallAsync(SimpleRequest request, Ca
ncellationToken token = default(CancellationToken)) |
| 141 { |
| 142 var call = CreateCall(ServiceName, UnaryCallMethod); |
| 143 return Calls.AsyncUnaryCall(call, request, token); |
| 144 } |
| 145 |
| 146 public AsyncServerStreamingCall<StreamingOutputCallResponse> Streami
ngOutputCall(StreamingOutputCallRequest request, CancellationToken token = defau
lt(CancellationToken)) |
| 147 { |
| 148 var call = CreateCall(ServiceName, StreamingOutputCallMethod); |
| 149 return Calls.AsyncServerStreamingCall(call, request, token); |
| 150 } |
| 151 |
| 152 public AsyncClientStreamingCall<StreamingInputCallRequest, Streaming
InputCallResponse> StreamingInputCall(CancellationToken token = default(Cancella
tionToken)) |
| 153 { |
| 154 var call = CreateCall(ServiceName, StreamingInputCallMethod); |
| 155 return Calls.AsyncClientStreamingCall(call, token); |
| 156 } |
| 157 |
| 158 public AsyncDuplexStreamingCall<StreamingOutputCallRequest, Streamin
gOutputCallResponse> FullDuplexCall(CancellationToken token = default(Cancellati
onToken)) |
| 159 { |
| 160 var call = CreateCall(ServiceName, FullDuplexCallMethod); |
| 161 return Calls.AsyncDuplexStreamingCall(call, token); |
| 162 } |
| 163 |
| 164 public AsyncDuplexStreamingCall<StreamingOutputCallRequest, Streamin
gOutputCallResponse> HalfDuplexCall(CancellationToken token = default(Cancellati
onToken)) |
| 165 { |
| 166 var call = CreateCall(ServiceName, HalfDuplexCallMethod); |
| 167 return Calls.AsyncDuplexStreamingCall(call, token); |
| 168 } |
| 169 } |
| 170 |
| 171 // server-side interface |
| 172 public interface ITestService |
| 173 { |
| 174 Task<Empty> EmptyCall(ServerCallContext context, Empty request); |
| 175 |
| 176 Task<SimpleResponse> UnaryCall(ServerCallContext context, SimpleRequ
est request); |
| 177 |
| 178 Task StreamingOutputCall(ServerCallContext context, StreamingOutputC
allRequest request, IServerStreamWriter<StreamingOutputCallResponse> responseStr
eam); |
| 179 |
| 180 Task<StreamingInputCallResponse> StreamingInputCall(ServerCallContex
t context, IAsyncStreamReader<StreamingInputCallRequest> requestStream); |
| 181 |
| 182 Task FullDuplexCall(ServerCallContext context, IAsyncStreamReader<St
reamingOutputCallRequest> requestStream, IServerStreamWriter<StreamingOutputCall
Response> responseStream); |
| 183 |
| 184 Task HalfDuplexCall(ServerCallContext context, IAsyncStreamReader<St
reamingOutputCallRequest> requestStream, IServerStreamWriter<StreamingOutputCall
Response> responseStream); |
| 185 } |
| 186 |
| 187 public static ServerServiceDefinition BindService(ITestService serviceIm
pl) |
| 188 { |
| 189 return ServerServiceDefinition.CreateBuilder(ServiceName) |
| 190 .AddMethod(EmptyCallMethod, serviceImpl.EmptyCall) |
| 191 .AddMethod(UnaryCallMethod, serviceImpl.UnaryCall) |
| 192 .AddMethod(StreamingOutputCallMethod, serviceImpl.StreamingOutpu
tCall) |
| 193 .AddMethod(StreamingInputCallMethod, serviceImpl.StreamingInputC
all) |
| 194 .AddMethod(FullDuplexCallMethod, serviceImpl.FullDuplexCall) |
| 195 .AddMethod(HalfDuplexCallMethod, serviceImpl.HalfDuplexCall) |
| 196 .Build(); |
| 197 } |
| 198 |
| 199 public static ITestServiceClient NewStub(Channel channel) |
| 200 { |
| 201 return new TestServiceClientStub(channel); |
| 202 } |
| 203 } |
| 204 } |
OLD | NEW |