< Summary

Information
Class: IceRpc.Slice.Internal.IncomingFrameExtensions
Assembly: IceRpc.Slice
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.Slice/Internal/IncomingFrameExtensions.cs
Tag: 275_13775359185
Line coverage
81%
Covered lines: 40
Uncovered lines: 9
Coverable lines: 49
Total lines: 111
Line coverage: 81.6%
Branch coverage
60%
Covered branches: 6
Total branches: 10
Branch coverage: 60%
Method coverage
83%
Covered methods: 5
Total methods: 6
Method coverage: 83.3%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
DecodeValueAsync(...)50%22100%
DecodeSegment()50%2.01288.23%
PerformDecodeAsync()100%11100%
DecodeVoidAsync(...)50%2.01285.71%
DecodeSegment()75%4.07483.33%
PerformDecodeAsync()100%210%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.Slice/Internal/IncomingFrameExtensions.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using IceRpc.Internal;
 4using System.IO.Pipelines;
 5using ZeroC.Slice;
 6
 7namespace IceRpc.Slice.Internal;
 8
 9/// <summary>Provides extension methods for <see cref="IncomingFrame" /> to decode its payload when this payload is
 10/// encoded with the Slice encoding.</summary>
 11internal static class IncomingFrameExtensions
 12{
 13    /// <summary>Decodes arguments or a response value from a pipe reader.</summary>
 14    /// <param name="frame">The incoming frame.</param>
 15    /// <param name="encoding">The Slice encoding version.</param>
 16    /// <param name="feature">The Slice feature.</param>
 17    /// <param name="baseProxy">The base proxy.</param>
 18    /// <param name="decodeFunc">The decode function for the payload arguments or return value.</param>
 19    /// <param name="activator">The activator.</param>
 20    /// <param name="cancellationToken">A cancellation token that receives the cancellation requests.</param>
 21    /// <returns>The decode value.</returns>
 22    internal static ValueTask<T> DecodeValueAsync<T>(
 23        this IncomingFrame frame,
 24        SliceEncoding encoding,
 25        ISliceFeature feature,
 26        IProxy? baseProxy,
 27        DecodeFunc<T> decodeFunc,
 28        IActivator? activator,
 29        CancellationToken cancellationToken)
 18530    {
 18531        return frame.Payload.TryReadSegment(encoding, feature.MaxSegmentSize, out ReadResult readResult) ?
 18532            new(DecodeSegment(readResult)) :
 18533            PerformDecodeAsync();
 34
 35        // All the logic is in this local function.
 36        T DecodeSegment(ReadResult readResult)
 18537        {
 38            // We never call CancelPendingRead; an interceptor or middleware can but it's not correct.
 18539            if (readResult.IsCanceled)
 040            {
 041                throw new InvalidOperationException("Unexpected call to CancelPendingRead.");
 42            }
 43
 18544            var decoder = new SliceDecoder(
 18545                readResult.Buffer,
 18546                encoding,
 18547                baseProxy,
 18548                feature.MaxCollectionAllocation,
 18549                activator,
 18550                feature.MaxDepth);
 18551            T value = decodeFunc(ref decoder);
 18552            decoder.SkipTagged(useTagEndMarker: false); // useTagEndMarker is Slice1-only
 18553            decoder.CheckEndOfBuffer();
 54
 18555            frame.Payload.AdvanceTo(readResult.Buffer.End);
 18556            return value;
 18557        }
 58
 59        async ValueTask<T> PerformDecodeAsync() =>
 460            DecodeSegment(await frame.Payload.ReadSegmentAsync(
 461                encoding,
 462                feature.MaxSegmentSize,
 463                cancellationToken).ConfigureAwait(false));
 18564    }
 65
 66    /// <summary>Reads/decodes empty args or a void return value.</summary>
 67    /// <param name="frame">The incoming frame.</param>
 68    /// <param name="encoding">The Slice encoding version.</param>
 69    /// <param name="feature">The Slice feature.</param>
 70    /// <param name="cancellationToken">A cancellation token that receives the cancellation requests.</param>
 71    internal static ValueTask DecodeVoidAsync(
 72        this IncomingFrame frame,
 73        SliceEncoding encoding,
 74        ISliceFeature feature,
 75        CancellationToken cancellationToken)
 12476    {
 12477        if (frame.Payload.TryReadSegment(encoding, feature.MaxSegmentSize, out ReadResult readResult))
 12478        {
 12479            DecodeSegment(readResult);
 12480            return default;
 81        }
 82
 083        return PerformDecodeAsync();
 84
 85        // All the logic is in this local function.
 86        void DecodeSegment(ReadResult readResult)
 12487        {
 88            // We never call CancelPendingRead; an interceptor or middleware can but it's not correct.
 12489            if (readResult.IsCanceled)
 090            {
 091                throw new InvalidOperationException("Unexpected call to CancelPendingRead.");
 92            }
 93
 12494            if (!readResult.Buffer.IsEmpty)
 1295            {
 96                // no need to pass maxCollectionAllocation and other args since the only thing this decoding can
 97                // do is skip unknown tags
 1298                var decoder = new SliceDecoder(readResult.Buffer, encoding);
 1299                decoder.SkipTagged(useTagEndMarker: false); // useTagEndMarker is Slice1-only
 12100                decoder.CheckEndOfBuffer();
 12101            }
 124102            frame.Payload.AdvanceTo(readResult.Buffer.End);
 124103        }
 104
 105        async ValueTask PerformDecodeAsync() =>
 0106            DecodeSegment(await frame.Payload.ReadSegmentAsync(
 0107                encoding,
 0108                feature.MaxSegmentSize,
 0109                cancellationToken).ConfigureAwait(false));
 124110    }
 111}