#region Copyright notice and license
// 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.
#endregion
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Grpc.Core;
namespace grpc.testing
{
///
/// TestService (this is handwritten version of code that will normally be generated).
///
public class TestServiceGrpc
{
static readonly string ServiceName = "/grpc.testing.TestService";
static readonly Marshaller EmptyMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), Empty.ParseFrom);
static readonly Marshaller SimpleRequestMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), SimpleRequest.ParseFrom);
static readonly Marshaller SimpleResponseMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), SimpleResponse.ParseFrom);
static readonly Marshaller StreamingOutputCallRequestMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), StreamingOutputCallRequest.ParseFrom);
static readonly Marshaller StreamingOutputCallResponseMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), StreamingOutputCallResponse.ParseFrom);
static readonly Marshaller StreamingInputCallRequestMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), StreamingInputCallRequest.ParseFrom);
static readonly Marshaller StreamingInputCallResponseMarshaller = Marshallers.Create((arg) => arg.ToByteArray(), StreamingInputCallResponse.ParseFrom);
static readonly Method EmptyCallMethod = new Method(
MethodType.Unary,
"EmptyCall",
EmptyMarshaller,
EmptyMarshaller);
static readonly Method UnaryCallMethod = new Method(
MethodType.Unary,
"UnaryCall",
SimpleRequestMarshaller,
SimpleResponseMarshaller);
static readonly Method StreamingOutputCallMethod = new Method(
MethodType.ServerStreaming,
"StreamingOutputCall",
StreamingOutputCallRequestMarshaller,
StreamingOutputCallResponseMarshaller);
static readonly Method StreamingInputCallMethod = new Method(
MethodType.ClientStreaming,
"StreamingInputCall",
StreamingInputCallRequestMarshaller,
StreamingInputCallResponseMarshaller);
static readonly Method FullDuplexCallMethod = new Method(
MethodType.DuplexStreaming,
"FullDuplexCall",
StreamingOutputCallRequestMarshaller,
StreamingOutputCallResponseMarshaller);
static readonly Method HalfDuplexCallMethod = new Method(
MethodType.DuplexStreaming,
"HalfDuplexCall",
StreamingOutputCallRequestMarshaller,
StreamingOutputCallResponseMarshaller);
public interface ITestServiceClient
{
Empty EmptyCall(Empty request, CancellationToken token = default(CancellationToken));
Task EmptyCallAsync(Empty request, CancellationToken token = default(CancellationToken));
SimpleResponse UnaryCall(SimpleRequest request, CancellationToken token = default(CancellationToken));
Task UnaryCallAsync(SimpleRequest request, CancellationToken token = default(CancellationToken));
AsyncServerStreamingCall StreamingOutputCall(StreamingOutputCallRequest request, CancellationToken token = default(CancellationToken));
AsyncClientStreamingCall StreamingInputCall(CancellationToken token = default(CancellationToken));
AsyncDuplexStreamingCall FullDuplexCall(CancellationToken token = default(CancellationToken));
AsyncDuplexStreamingCall HalfDuplexCall(CancellationToken token = default(CancellationToken));
}
public class TestServiceClientStub : AbstractStub, ITestServiceClient
{
public TestServiceClientStub(Channel channel) : base(channel, StubConfiguration.Default)
{
}
public TestServiceClientStub(Channel channel, StubConfiguration config) : base(channel, config)
{
}
public Empty EmptyCall(Empty request, CancellationToken token = default(CancellationToken))
{
var call = CreateCall(ServiceName, EmptyCallMethod);
return Calls.BlockingUnaryCall(call, request, token);
}
public Task EmptyCallAsync(Empty request, CancellationToken token = default(CancellationToken))
{
var call = CreateCall(ServiceName, EmptyCallMethod);
return Calls.AsyncUnaryCall(call, request, token);
}
public SimpleResponse UnaryCall(SimpleRequest request, CancellationToken token = default(CancellationToken))
{
var call = CreateCall(ServiceName, UnaryCallMethod);
return Calls.BlockingUnaryCall(call, request, token);
}
public Task UnaryCallAsync(SimpleRequest request, CancellationToken token = default(CancellationToken))
{
var call = CreateCall(ServiceName, UnaryCallMethod);
return Calls.AsyncUnaryCall(call, request, token);
}
public AsyncServerStreamingCall StreamingOutputCall(StreamingOutputCallRequest request, CancellationToken token = default(CancellationToken))
{
var call = CreateCall(ServiceName, StreamingOutputCallMethod);
return Calls.AsyncServerStreamingCall(call, request, token);
}
public AsyncClientStreamingCall StreamingInputCall(CancellationToken token = default(CancellationToken))
{
var call = CreateCall(ServiceName, StreamingInputCallMethod);
return Calls.AsyncClientStreamingCall(call, token);
}
public AsyncDuplexStreamingCall FullDuplexCall(CancellationToken token = default(CancellationToken))
{
var call = CreateCall(ServiceName, FullDuplexCallMethod);
return Calls.AsyncDuplexStreamingCall(call, token);
}
public AsyncDuplexStreamingCall HalfDuplexCall(CancellationToken token = default(CancellationToken))
{
var call = CreateCall(ServiceName, HalfDuplexCallMethod);
return Calls.AsyncDuplexStreamingCall(call, token);
}
}
// server-side interface
public interface ITestService
{
Task EmptyCall(ServerCallContext context, Empty request);
Task UnaryCall(ServerCallContext context, SimpleRequest request);
Task StreamingOutputCall(ServerCallContext context, StreamingOutputCallRequest request, IServerStreamWriter responseStream);
Task StreamingInputCall(ServerCallContext context, IAsyncStreamReader requestStream);
Task FullDuplexCall(ServerCallContext context, IAsyncStreamReader requestStream, IServerStreamWriter responseStream);
Task HalfDuplexCall(ServerCallContext context, IAsyncStreamReader requestStream, IServerStreamWriter responseStream);
}
public static ServerServiceDefinition BindService(ITestService serviceImpl)
{
return ServerServiceDefinition.CreateBuilder(ServiceName)
.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();
}
public static ITestServiceClient NewStub(Channel channel)
{
return new TestServiceClientStub(channel);
}
}
}