< Summary

Information
Class: IceRpc.Features.ProtobufFeature
Assembly: IceRpc.Protobuf
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.Protobuf/Features/ProtobufFeature.cs
Tag: 2300_35243572715
Line coverage
15%
Covered lines: 3
Uncovered lines: 16
Coverable lines: 19
Total lines: 50
Line coverage: 15.7%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage
50%
Covered methods: 3
Fully covered methods: 3
Total methods: 6
Method coverage: 50%
Full method coverage: 50%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Default()100%11100%
get_MaxMessageLength()100%210%
get_EncodeOptions()100%210%
.ctor(...)0%7280%
get_MaxMessageLength()100%11100%
get_EncodeOptions()100%11100%

File(s)

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

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using IceRpc.Protobuf;
 4
 5namespace IceRpc.Features;
 6
 7/// <summary>Default implementation of <see cref="IProtobufFeature" />.</summary>
 8public sealed class ProtobufFeature : IProtobufFeature
 9{
 10    /// <summary>Gets a <see cref="IProtobufFeature" /> with default values for all properties.</summary>
 5311    public static IProtobufFeature Default { get; } = new DefaultProtobufFeature();
 12
 13    /// <inheritdoc/>
 14    /// <value>The maximum length of a Protobuf message, in bytes. Defaults to <c>1</c> MB.</value>
 015    public int MaxMessageLength { get; }
 16
 17    /// <inheritdoc/>
 018    public ProtobufEncodeOptions? EncodeOptions { get; }
 19
 20    /// <summary>Constructs a Protobuf feature.</summary>
 21    /// <param name="maxMessageLength">The maximum message length. Use <c>-1</c> to get the default value.</param>
 22    /// <param name="encodeOptions">The encode options.</param>
 23    /// <param name="defaultFeature">A feature that provides default values for all parameters. <see langword="null" />
 24    /// is equivalent to <see cref="Default" />.</param>
 25    /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="maxMessageLength" /> is a negative
 26    /// value other than <c>-1</c>.</exception>
 027    public ProtobufFeature(
 028        int maxMessageLength = -1,
 029        ProtobufEncodeOptions? encodeOptions = null,
 030        IProtobufFeature? defaultFeature = null)
 031    {
 032        if (maxMessageLength < -1)
 033        {
 034            throw new ArgumentOutOfRangeException(
 035                nameof(maxMessageLength),
 036                $"The value of {nameof(maxMessageLength)} must be greater than or equal to 0, or -1.");
 37        }
 38
 039        defaultFeature ??= Default;
 040        MaxMessageLength = maxMessageLength >= 0 ? maxMessageLength : defaultFeature.MaxMessageLength;
 041        EncodeOptions = encodeOptions ?? defaultFeature.EncodeOptions;
 042    }
 43
 44    private class DefaultProtobufFeature : IProtobufFeature
 45    {
 5146        public int MaxMessageLength => 1024 * 1024;
 47
 2348        public ProtobufEncodeOptions? EncodeOptions => null;
 49    }
 50}