< Summary

Information
Class: IceRpc.Features.SliceFeature
Assembly: IceRpc.Slice
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.Slice/Features/SliceFeature.cs
Tag: 2300_35243572715
Line coverage
65%
Covered lines: 25
Uncovered lines: 13
Coverable lines: 38
Total lines: 88
Line coverage: 65.7%
Branch coverage
50%
Covered branches: 12
Total branches: 24
Branch coverage: 50%
Method coverage
90%
Covered methods: 9
Fully covered methods: 8
Total methods: 10
Method coverage: 90%
Full method coverage: 80%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Default()100%11100%
get_BaseProxy()100%11100%
get_EncodeOptions()100%210%
get_MaxCollectionAllocation()100%11100%
get_MaxSegmentSize()100%11100%
.ctor(...)50%652458.62%
get_BaseProxy()100%11100%
get_EncodeOptions()100%11100%
get_MaxCollectionAllocation()100%11100%
get_MaxSegmentSize()100%11100%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc.Slice/Features/SliceFeature.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using IceRpc.Slice;
 4
 5namespace IceRpc.Features;
 6
 7/// <summary>Default implementation of <see cref="ISliceFeature" />.</summary>
 8public sealed class SliceFeature : ISliceFeature
 9{
 10    /// <summary>Gets a <see cref="ISliceFeature" /> with default values for all properties.</summary>
 44111    public static ISliceFeature Default { get; } = new DefaultSliceFeature();
 12
 13    /// <inheritdoc/>
 114    public ISliceProxy? BaseProxy { get; }
 15
 16    /// <inheritdoc/>
 017    public SliceEncodeOptions? EncodeOptions { get; }
 18
 19    /// <inheritdoc/>
 20    /// <value>The maximum collection allocation. Defaults to 8 times <see cref="MaxSegmentSize" />.</value>
 121    public int MaxCollectionAllocation { get; }
 22
 23    /// <inheritdoc/>
 24    /// <value>The maximum size of a Slice payload segment, in bytes. Defaults to <c>1</c> MB.</value>
 125    public int MaxSegmentSize { get; }
 26
 27    /// <summary>Constructs a Slice feature.</summary>
 28    /// <param name="encodeOptions">The encode options.</param>
 29    /// <param name="maxCollectionAllocation">The maximum collection allocation. Use <c>-1</c> to get the default value:
 30    /// 8 times <paramref name="maxSegmentSize" /> if set, otherwise the value provided by <paramref
 31    /// name="defaultFeature" />.</param>
 32    /// <param name="maxSegmentSize">The maximum segment size. Use <c>-1</c> to get the default value.</param>
 33    /// <param name="baseProxy">The base proxy, used when decoding service addresses into proxies.</param>
 34    /// <param name="defaultFeature">A feature that provides default values for all parameters. <see langword="null" />
 35    /// is equivalent to <see cref="Default" />.</param>
 36    /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="maxCollectionAllocation" /> is a
 37    /// negative value other than <c>-1</c>, when <paramref name="maxSegmentSize" /> is <c>0</c> or a negative value
 38    /// other than <c>-1</c>, or when <paramref name="maxSegmentSize" /> is greater than <c>int.MaxValue / 8</c>
 39    /// (256 MB) while <paramref name="maxCollectionAllocation" /> is <c>-1</c>.</exception>
 140    public SliceFeature(
 141        SliceEncodeOptions? encodeOptions = null,
 142        int maxCollectionAllocation = -1,
 143        int maxSegmentSize = -1,
 144        ISliceProxy? baseProxy = null,
 145        ISliceFeature? defaultFeature = null)
 146    {
 147        if (maxCollectionAllocation < -1)
 048        {
 049            throw new ArgumentOutOfRangeException(
 050                nameof(maxCollectionAllocation),
 051                $"The value of {nameof(maxCollectionAllocation)} must be greater than or equal to 0, or -1.");
 52        }
 153        if (maxSegmentSize is < -1 or 0)
 054        {
 055            throw new ArgumentOutOfRangeException(
 056                nameof(maxSegmentSize),
 057                $"The value of {nameof(maxSegmentSize)} must be greater than 0, or -1.");
 58        }
 159        if (maxCollectionAllocation == -1 && maxSegmentSize > int.MaxValue / 8)
 060        {
 061            throw new ArgumentOutOfRangeException(
 062                nameof(maxSegmentSize),
 063                $"The value of {nameof(maxSegmentSize)} must be less than or equal to int.MaxValue / 8 when {nameof(maxC
 64        }
 65
 166        defaultFeature ??= Default;
 67
 168        EncodeOptions = encodeOptions ?? defaultFeature.EncodeOptions;
 69
 170        MaxCollectionAllocation = maxCollectionAllocation >= 0 ? maxCollectionAllocation :
 171            (maxSegmentSize > 0 ? 8 * maxSegmentSize : defaultFeature.MaxCollectionAllocation);
 72
 173        MaxSegmentSize = maxSegmentSize > 0 ? maxSegmentSize : defaultFeature.MaxSegmentSize;
 74
 175        BaseProxy = baseProxy ?? defaultFeature.BaseProxy;
 176    }
 77
 78    private class DefaultSliceFeature : ISliceFeature
 79    {
 16180        public ISliceProxy? BaseProxy => null;
 81
 182        public SliceEncodeOptions? EncodeOptions => null;
 83
 18284        public int MaxCollectionAllocation => 8 * MaxSegmentSize;
 85
 40286        public int MaxSegmentSize => 1024 * 1024;
 87    }
 88}