C# mapping
A Protobuf RPC method named RpcName in service Greeter
is mapped to abstract method RpcNameAsync in interface IGreeter
and to abstract method RpcNameAsync in interface IGreeterService
.
The mapped method name is always in Pascal case, per the usual C# naming conventions, even when RpcName is not in Pascal case.
For example:
protobuf
syntax = "proto3";
package visitor_center;option csharp_namespace = "VisitorCenter";
// A simple Greeter service.service Greeter { // Creates a personalized greeting. rpc Greet (GreetRequest) returns (GreetResponse);}
C#
namespace VisitorCenter;
public partial interface IGreeter{ Task<GreetResponse> GreetAsync( GreetRequest message, IFeatureCollection? features = null, CancellationToken cancellationToken = default);}
public partial interface IGreeterService{ ValueTask<GreetResponse> GreetAsync( GreetRequest message, IFeatureCollection features, CancellationToken cancellationToken);}
While the two methods are similar, please note they are not the same:
- the client-side method returns a
Task<T>
while the service method returns aValueTask<T>
- the
features
parameter is nullable and defaults to null only in the client-side method - the cancellation token parameter has a default value only in the client-side method
deprecated option
If you set the deprecated
option to true
on an RPC method, the mapped C# methods are marked Obsolete.
idempotency_level option
If you set the idempotency_level
option to NO_SIDE_EFFECTS
or IDEMPOTENT
, the client-side generated implementation sets the field RequestFieldKey.Idempotent
in the outgoing request it creates; otherwise, it leaves this field unset.