< Summary

Information
Class: IceRpc.OutgoingFrame
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/OutgoingFrame.cs
Tag: 592_20856082467
Line coverage
89%
Covered lines: 25
Uncovered lines: 3
Coverable lines: 28
Total lines: 85
Line coverage: 89.2%
Branch coverage
83%
Covered branches: 10
Total branches: 12
Branch coverage: 83.3%
Method coverage
100%
Covered methods: 7
Total methods: 7
Method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Payload()100%11100%
get_PayloadContinuation()100%11100%
set_PayloadContinuation(...)75%44100%
get_Protocol()100%11100%
Use(...)75%4.59466.66%
GetPayloadWriter(...)100%44100%
.ctor(...)100%11100%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/OutgoingFrame.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using IceRpc.Internal;
 4using System.IO.Pipelines;
 5
 6namespace IceRpc;
 7
 8/// <summary>Represents the base class for outgoing frames.</summary>
 9public abstract class OutgoingFrame
 10{
 11    /// <summary>Gets or sets the payload of this frame.</summary>
 12    /// <value>The payload of this frame. Defaults to a <see cref="PipeReader" /> that returns an empty
 13    /// sequence.</value>
 14    /// <remarks>IceRPC completes the payload <see cref="PipeReader" /> with the <see
 15    /// cref="PipeReader.Complete(Exception?)" /> method. It never calls <see
 16    /// cref="PipeReader.CompleteAsync(Exception?)" />. The implementation of <see
 17    /// cref="PipeReader.Complete(Exception?)" /> should not block.</remarks>
 2416418    public PipeReader Payload { get; set; } = EmptyPipeReader.Instance;
 19
 20    /// <summary>Gets or sets the payload continuation of this frame. The payload continuation is a continuation of <see
 21    /// cref="Payload"/>. The receiver cannot distinguish any seam between payload and payload continuation in the <see
 22    /// cref="IncomingFrame.Payload" /> it receives.</summary>
 23    /// <value>The payload continuation of this frame. Defaults to <see langword="null" /> meaning no
 24    /// continuation.</value>
 25    /// <remarks>IceRPC completes the payload continuation <see cref="PipeReader" /> with the <see
 26    /// cref="PipeReader.Complete(Exception?)" /> method. It never calls <see
 27    /// cref="PipeReader.CompleteAsync(Exception?)" />. The implementation of <see
 28    /// cref="PipeReader.Complete(Exception?)" /> should not block.</remarks>
 29    public PipeReader? PayloadContinuation
 30    {
 974331        get => _payloadContinuation;
 32        set
 27933        {
 27934            _payloadContinuation = Protocol.HasPayloadContinuation || value is null ?
 27935                value : throw new NotSupportedException(
 27936                    $"The '{Protocol}' protocol does not support payload continuation.");
 27937        }
 38    }
 39
 40    /// <summary>Gets the protocol of this frame.</summary>
 41    /// <value>The <see cref="IceRpc.Protocol" /> value of this frame.</value>
 614842    public Protocol Protocol { get; }
 43
 44    private PipeReader? _payloadContinuation;
 45
 46    private Stack<Func<PipeWriter, PipeWriter>>? _payloadWriterInterceptorStack;
 47
 48    /// <summary>Installs a payload writer interceptor in this outgoing frame. This interceptor is executed just
 49    /// before sending <see cref="Payload" />, and is typically used to compress both <see cref="Payload" /> and
 50    /// <see cref="PayloadContinuation" />.</summary>
 51    /// <param name="payloadWriterInterceptor">The payload writer interceptor to install.</param>
 52    /// <returns>This outgoing frame.</returns>
 53    /// <remarks>IceRPC completes the payload writer <see cref="PipeWriter" /> with the <see
 54    /// cref="PipeWriter.Complete(Exception?)" /> method. It never calls <see
 55    /// cref="PipeWriter.CompleteAsync(Exception?)" />. The implementation of <see
 56    /// cref="PipeWriter.Complete(Exception?)" /> should not block.</remarks>
 57    public OutgoingFrame Use(Func<PipeWriter, PipeWriter> payloadWriterInterceptor)
 1358    {
 1359        if (!Protocol.SupportsPayloadWriterInterceptors)
 060        {
 061            throw new NotSupportedException(
 062                $"The '{Protocol}' protocol does not support payload writer interceptors.");
 63        }
 1364        _payloadWriterInterceptorStack ??= new();
 1365        _payloadWriterInterceptorStack.Push(payloadWriterInterceptor);
 1366        return this;
 1367    }
 68
 69    /// <summary>Returns the payload writer to use when sending the payload.</summary>
 70    internal PipeWriter GetPayloadWriter(PipeWriter writer)
 182371    {
 182372        if (_payloadWriterInterceptorStack is not null)
 1373        {
 6574            foreach (Func<PipeWriter, PipeWriter> interceptor in _payloadWriterInterceptorStack)
 1375            {
 1376                writer = interceptor(writer);
 1377            }
 1378        }
 182379        return writer;
 182380    }
 81
 82    /// <summary>Constructs an outgoing frame.</summary>
 83    /// <param name="protocol">The protocol used to send the frame.</param>
 1178284    private protected OutgoingFrame(Protocol protocol) => Protocol = protocol;
 85}