< Summary

Information
Class: IceRpc.Protobuf.IncomingRequestExtensions
Assembly: IceRpc.Protobuf
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.Protobuf/IncomingRequestExtensions.cs
Tag: 275_13775359185
Line coverage
100%
Covered lines: 52
Uncovered lines: 0
Coverable lines: 52
Total lines: 153
Line coverage: 100%
Branch coverage
87%
Covered branches: 14
Total branches: 16
Branch coverage: 87.5%
Method coverage
100%
Covered methods: 4
Total methods: 4
Method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
DispatchUnaryAsync()83.33%66100%
DispatchClientStreamingAsync()83.33%66100%
DispatchServerStreamingAsync()100%22100%
DispatchBidiStreamingAsync()100%22100%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.Protobuf/IncomingRequestExtensions.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using Google.Protobuf;
 4using IceRpc.Features;
 5using IceRpc.Protobuf.Internal;
 6
 7namespace IceRpc.Protobuf;
 8
 9/// <summary>Provides extension methods for <see cref="IncomingRequest" />.</summary>
 10/// <remarks>These methods are called by the <see cref="IDispatcher"/> implementation generated by the Protobuf service
 11/// generator.</remarks>
 12public static class IncomingRequestExtensions
 13{
 14    /// <summary>Dispatches a unary RPC method.</summary>
 15    /// <typeparam name="TInput">The type of the input message.</typeparam>
 16    /// <typeparam name="TOutput">The type of the output message.</typeparam>
 17    /// <typeparam name="TService">The generated INameService interface.</typeparam>
 18    /// <param name="request">The incoming request.</param>
 19    /// <param name="inputParser">A message parser used to decode the request payload.</param>
 20    /// <param name="service">The instance of <typeparamref name="TService"/> that implement the RPC.</param>
 21    /// <param name="method">The user-provided implementation of the RPC method.</param>
 22    /// <param name="cancellationToken">The cancellation token that accepts cancellation requests.</param>
 23    /// <returns>A value task that holds the outgoing response.</returns>
 24    public static async ValueTask<OutgoingResponse> DispatchUnaryAsync<TInput, TOutput, TService>(
 25        this IncomingRequest request,
 26        MessageParser<TInput> inputParser,
 27        TService service,
 28        Func<TService, TInput, IFeatureCollection, CancellationToken, ValueTask<TOutput>> method,
 29        CancellationToken cancellationToken) where TInput : IMessage<TInput>
 30                                             where TOutput : IMessage<TOutput>
 31                                             where TService : class
 1032    {
 1033        IProtobufFeature protobufFeature = request.Features.Get<IProtobufFeature>() ?? ProtobufFeature.Default;
 34
 1035        TInput input = await request.Payload.DecodeProtobufMessageAsync(
 1036            inputParser,
 1037            protobufFeature.MaxMessageLength,
 1038            cancellationToken).ConfigureAwait(false);
 39
 1040        TOutput output = await method(service, input, request.Features, cancellationToken).ConfigureAwait(false);
 41
 1042        return new OutgoingResponse(request)
 1043        {
 1044            Payload = output.EncodeAsLengthPrefixedMessage(
 1045                protobufFeature.EncodeOptions?.PipeOptions ?? ProtobufEncodeOptions.Default.PipeOptions)
 1046        };
 1047    }
 48
 49    /// <summary>Dispatches a client-streaming RPC method.</summary>
 50    /// <typeparam name="TInput">The type of the input message.</typeparam>
 51    /// <typeparam name="TOutput">The type of the output message.</typeparam>
 52    /// <typeparam name="TService">The generated INameService interface.</typeparam>
 53    /// <param name="request">The incoming request.</param>
 54    /// <param name="inputParser">A message parser used to decode the request payload.</param>
 55    /// <param name="service">The instance of <typeparamref name="TService"/> that implement the RPC.</param>
 56    /// <param name="method">The user-provided implementation of the RPC method.</param>
 57    /// <param name="cancellationToken">The cancellation token that accepts cancellation requests.</param>
 58    /// <returns>A value task that holds the outgoing response.</returns>
 59    public static async ValueTask<OutgoingResponse> DispatchClientStreamingAsync<TInput, TOutput, TService>(
 60        this IncomingRequest request,
 61        MessageParser<TInput> inputParser,
 62        TService service,
 63        Func<TService, IAsyncEnumerable<TInput>, IFeatureCollection, CancellationToken, ValueTask<TOutput>> method,
 64        CancellationToken cancellationToken) where TInput : IMessage<TInput>
 65                                             where TOutput : IMessage<TOutput>
 66                                             where TService : class
 367    {
 368        IProtobufFeature protobufFeature = request.Features.Get<IProtobufFeature>() ?? ProtobufFeature.Default;
 69
 370        IAsyncEnumerable<TInput> input = request.DetachPayload().ToAsyncEnumerable(
 371            inputParser,
 372            protobufFeature.MaxMessageLength,
 373            CancellationToken.None);
 74
 375        TOutput output = await method(service, input, request.Features, cancellationToken).ConfigureAwait(false);
 76
 377        return new OutgoingResponse(request)
 378        {
 379            Payload = output.EncodeAsLengthPrefixedMessage(
 380                protobufFeature.EncodeOptions?.PipeOptions ?? ProtobufEncodeOptions.Default.PipeOptions)
 381        };
 382    }
 83
 84    /// <summary>Dispatches a server-streaming RPC method.</summary>
 85    /// <typeparam name="TInput">The type of the input message.</typeparam>
 86    /// <typeparam name="TOutput">The type of the output message.</typeparam>
 87    /// <typeparam name="TService">The generated INameService interface.</typeparam>
 88    /// <param name="request">The incoming request.</param>
 89    /// <param name="inputParser">A message parser used to decode the request payload.</param>
 90    /// <param name="service">The instance of <typeparamref name="TService"/> that implement the RPC.</param>
 91    /// <param name="method">The user-provided implementation of the RPC method.</param>
 92    /// <param name="cancellationToken">The cancellation token that accepts cancellation requests.</param>
 93    /// <returns>A value task that holds the outgoing response.</returns>
 94    public static async ValueTask<OutgoingResponse> DispatchServerStreamingAsync<TInput, TOutput, TService>(
 95        this IncomingRequest request,
 96        MessageParser<TInput> inputParser,
 97        TService service,
 98        Func<TService, TInput, IFeatureCollection, CancellationToken, ValueTask<IAsyncEnumerable<TOutput>>> method,
 99        CancellationToken cancellationToken) where TInput : IMessage<TInput>
 100                                             where TOutput : IMessage<TOutput>
 101                                             where TService : class
 3102    {
 3103        IProtobufFeature protobufFeature = request.Features.Get<IProtobufFeature>() ?? ProtobufFeature.Default;
 104
 3105        TInput input = await request.Payload.DecodeProtobufMessageAsync(
 3106            inputParser,
 3107            protobufFeature.MaxMessageLength,
 3108            cancellationToken).ConfigureAwait(false);
 109
 3110        IAsyncEnumerable<TOutput> output = await method(service, input, request.Features, cancellationToken)
 3111            .ConfigureAwait(false);
 112
 3113        return new OutgoingResponse(request)
 3114        {
 3115            PayloadContinuation = output.ToPipeReader(protobufFeature.EncodeOptions)
 3116        };
 3117    }
 118
 119    /// <summary>Dispatches a bidi-streaming RPC method.</summary>
 120    /// <typeparam name="TInput">The type of the input message.</typeparam>
 121    /// <typeparam name="TOutput">The type of the output message.</typeparam>
 122    /// <typeparam name="TService">The generated INameService interface.</typeparam>
 123    /// <param name="request">The incoming request.</param>
 124    /// <param name="inputParser">A message parser used to decode the request payload.</param>
 125    /// <param name="service">The instance of <typeparamref name="TService"/> that implement the RPC.</param>
 126    /// <param name="method">The user-provided implementation of the RPC method.</param>
 127    /// <param name="cancellationToken">The cancellation token that accepts cancellation requests.</param>
 128    /// <returns>A value task that holds the outgoing response.</returns>
 129    public static async ValueTask<OutgoingResponse> DispatchBidiStreamingAsync<TInput, TOutput, TService>(
 130        this IncomingRequest request,
 131        MessageParser<TInput> inputParser,
 132        TService service,
 133        Func<TService, IAsyncEnumerable<TInput>, IFeatureCollection, CancellationToken, ValueTask<IAsyncEnumerable<TOutp
 134        CancellationToken cancellationToken) where TInput : IMessage<TInput>
 135                                             where TOutput : IMessage<TOutput>
 136                                             where TService : class
 3137    {
 3138        IProtobufFeature protobufFeature = request.Features.Get<IProtobufFeature>() ?? ProtobufFeature.Default;
 139
 3140        IAsyncEnumerable<TInput> input = request.DetachPayload().ToAsyncEnumerable(
 3141            inputParser,
 3142            protobufFeature.MaxMessageLength,
 3143            CancellationToken.None);
 144
 3145        IAsyncEnumerable<TOutput> output = await method(service, input, request.Features, cancellationToken)
 3146            .ConfigureAwait(false);
 147
 3148        return new OutgoingResponse(request)
 3149        {
 3150            PayloadContinuation = output.ToPipeReader(protobufFeature.EncodeOptions)
 3151        };
 3152    }
 153}