From 56b805ff03f2618847676fc526d61d0f2ff7ed21 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 6 Feb 2015 12:20:28 -0800 Subject: [PATCH] added support for streaming calls to TestService stubs --- src/csharp/GrpcApi/TestServiceGrpc.cs | 75 +++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 4 deletions(-) diff --git a/src/csharp/GrpcApi/TestServiceGrpc.cs b/src/csharp/GrpcApi/TestServiceGrpc.cs index 65ca1f07677..e836d604929 100644 --- a/src/csharp/GrpcApi/TestServiceGrpc.cs +++ b/src/csharp/GrpcApi/TestServiceGrpc.cs @@ -15,6 +15,10 @@ namespace grpc.testing readonly static Marshaller emptyMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), Empty.ParseFrom); readonly static Marshaller simpleRequestMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), SimpleRequest.ParseFrom); readonly static Marshaller simpleResponseMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), SimpleResponse.ParseFrom); + readonly static Marshaller streamingOutputCallRequestMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), StreamingOutputCallRequest.ParseFrom); + readonly static Marshaller streamingOutputCallResponseMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), StreamingOutputCallResponse.ParseFrom); + readonly static Marshaller streamingInputCallRequestMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), StreamingInputCallRequest.ParseFrom); + readonly static Marshaller streamingInputCallResponseMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), StreamingInputCallResponse.ParseFrom); readonly static Method emptyCallMethod = new Method( MethodType.Unary, @@ -28,6 +32,30 @@ namespace grpc.testing simpleRequestMarshaller, simpleResponseMarshaller ); + readonly static Method streamingOutputCallMethod = new Method( + MethodType.ServerStreaming, + "/grpc.testing.TestService/StreamingOutputCall", + streamingOutputCallRequestMarshaller, + streamingOutputCallResponseMarshaller + ); + readonly static Method streamingInputCallMethod = new Method( + MethodType.ClientStreaming, + "/grpc.testing.TestService/StreamingInputCall", + streamingInputCallRequestMarshaller, + streamingInputCallResponseMarshaller + ); + readonly static Method fullDuplexCallMethod = new Method( + MethodType.DuplexStreaming, + "/grpc.testing.TestService/FullDuplexCall", + streamingOutputCallRequestMarshaller, + streamingOutputCallResponseMarshaller + ); + readonly static Method halfDuplexCallMethod = new Method( + MethodType.DuplexStreaming, + "/grpc.testing.TestService/HalfDuplexCall", + streamingOutputCallRequestMarshaller, + streamingOutputCallResponseMarshaller + ); public interface ITestServiceClient { @@ -39,10 +67,13 @@ namespace grpc.testing Task UnaryCallAsync(SimpleRequest request, CancellationToken token = default(CancellationToken)); - // TODO: StreamingOutputCall - // TODO: StreamingInputCall - // TODO: FullDuplexCall - // TODO: HalfDuplexCall + Task StreamingOutputCall(StreamingOutputCallRequest request, IObserver responseObserver, CancellationToken token = default(CancellationToken)); + + ClientStreamingAsyncResult StreamingInputCall(CancellationToken token = default(CancellationToken)); + + IObserver FullDuplexCall(IObserver responseObserver, CancellationToken token = default(CancellationToken)); + + IObserver HalfDuplexCall(IObserver responseObserver, CancellationToken token = default(CancellationToken)); } public class TestServiceClientStub : ITestServiceClient @@ -77,6 +108,30 @@ namespace grpc.testing var call = new Google.GRPC.Core.Call(unaryCallMethod, channel); return Calls.AsyncUnaryCall(call, request, token); } + + public Task StreamingOutputCall(StreamingOutputCallRequest request, IObserver responseObserver, CancellationToken token = default(CancellationToken)) { + var call = new Google.GRPC.Core.Call(streamingOutputCallMethod, channel); + return Calls.AsyncServerStreamingCall(call, request, responseObserver, token); + } + + public ClientStreamingAsyncResult StreamingInputCall(CancellationToken token = default(CancellationToken)) + { + var call = new Google.GRPC.Core.Call(streamingInputCallMethod, channel); + return Calls.AsyncClientStreamingCall(call, token); + } + + public IObserver FullDuplexCall(IObserver responseObserver, CancellationToken token = default(CancellationToken)) + { + var call = new Google.GRPC.Core.Call(fullDuplexCallMethod, channel); + return Calls.DuplexStreamingCall(call, responseObserver, token); + } + + + public IObserver HalfDuplexCall(IObserver responseObserver, CancellationToken token = default(CancellationToken)) + { + var call = new Google.GRPC.Core.Call(halfDuplexCallMethod, channel); + return Calls.DuplexStreamingCall(call, responseObserver, token); + } } // server-side interface @@ -85,6 +140,14 @@ namespace grpc.testing void EmptyCall(Empty request, IObserver responseObserver); void UnaryCall(SimpleRequest request, IObserver responseObserver); + + void StreamingOutputCall(StreamingOutputCallRequest request, IObserver responseObserver); + + IObserver StreamingInputCall(IObserver responseObserver); + + IObserver FullDuplexCall(IObserver responseObserver); + + IObserver HalfDuplexCall(IObserver responseObserver); } public static ServerServiceDefinition BindService(ITestService serviceImpl) @@ -92,6 +155,10 @@ namespace grpc.testing return ServerServiceDefinition.CreateBuilder("/grpc.testing.TestService/") .AddMethod(emptyCallMethod, serviceImpl.EmptyCall) .AddMethod(unaryCallMethod, serviceImpl.UnaryCall) + .AddMethod(streamingOutputCallMethod, serviceImpl.StreamingOutputCall) + .AddMethod(streamingInputCallMethod, serviceImpl.StreamingInputCall) + .AddMethod(fullDuplexCallMethod, serviceImpl.FullDuplexCall) + .AddMethod(halfDuplexCallMethod, serviceImpl.HalfDuplexCall) .Build(); }