#region Copyright notice and license // Copyright 2015 gRPC authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #endregion using System; using Grpc.Core.Utils; namespace Grpc.Core { /// /// Method types supported by gRPC. /// public enum MethodType { /// Single request sent from client, single response received from server. Unary, /// Stream of request sent from client, single response received from server. ClientStreaming, /// Single request sent from client, stream of responses received from server. ServerStreaming, /// Both server and client can stream arbitrary number of requests and responses simultaneously. DuplexStreaming } /// /// A non-generic representation of a remote method. /// public interface IMethod { /// /// Gets the type of the method. /// MethodType Type { get; } /// /// Gets the name of the service to which this method belongs. /// string ServiceName { get; } /// /// Gets the unqualified name of the method. /// string Name { get; } /// /// Gets the fully qualified name of the method. On the server side, methods are dispatched /// based on this name. /// string FullName { get; } } /// /// A description of a remote method. /// /// Request message type for this method. /// Response message type for this method. public class Method : IMethod { readonly MethodType type; readonly string serviceName; readonly string name; readonly Marshaller requestMarshaller; readonly Marshaller responseMarshaller; readonly string fullName; /// /// Initializes a new instance of the Method class. /// /// Type of method. /// Name of service this method belongs to. /// Unqualified name of the method. /// Marshaller used for request messages. /// Marshaller used for response messages. public Method(MethodType type, string serviceName, string name, Marshaller requestMarshaller, Marshaller responseMarshaller) { this.type = type; this.serviceName = GrpcPreconditions.CheckNotNull(serviceName, "serviceName"); this.name = GrpcPreconditions.CheckNotNull(name, "name"); this.requestMarshaller = GrpcPreconditions.CheckNotNull(requestMarshaller, "requestMarshaller"); this.responseMarshaller = GrpcPreconditions.CheckNotNull(responseMarshaller, "responseMarshaller"); this.fullName = GetFullName(serviceName, name); } /// /// Gets the type of the method. /// public MethodType Type { get { return this.type; } } /// /// Gets the name of the service to which this method belongs. /// public string ServiceName { get { return this.serviceName; } } /// /// Gets the unqualified name of the method. /// public string Name { get { return this.name; } } /// /// Gets the marshaller used for request messages. /// public Marshaller RequestMarshaller { get { return this.requestMarshaller; } } /// /// Gets the marshaller used for response messages. /// public Marshaller ResponseMarshaller { get { return this.responseMarshaller; } } /// /// Gets the fully qualified name of the method. On the server side, methods are dispatched /// based on this name. /// public string FullName { get { return this.fullName; } } /// /// Gets full name of the method including the service name. /// internal static string GetFullName(string serviceName, string methodName) { return "/" + serviceName + "/" + methodName; } } }