< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.DecoderHelper
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/FramingDecoder.cs
Line coverage
66%
Covered lines: 2
Uncovered lines: 1
Coverable lines: 3
Total lines: 76
Line coverage: 66.6%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
ValidateSize(...)50%2266.66%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/FramingDecoder.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System;
 5using System.IO;
 6
 7namespace CoreWCF.Channels
 8{
 9    internal static class DecoderHelper
 10    {
 11        public static void ValidateSize(int size)
 12        {
 40913            if (size <= 0)
 14            {
 015                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(size), 
 16            }
 40917        }
 18    }
 19
 20    internal struct IntDecoder
 21    {
 22        private int _value;
 23        private short _index;
 24        private const int LastIndex = 4;
 25
 26        public int Value
 27        {
 28            get
 29            {
 30                if (!IsValueDecoded)
 31                {
 32                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.FramingVa
 33                }
 34
 35                return _value;
 36            }
 37        }
 38
 39        public bool IsValueDecoded { get; private set; }
 40
 41        public void Reset()
 42        {
 43            _index = 0;
 44            _value = 0;
 45            IsValueDecoded = false;
 46        }
 47
 48        public int Decode(byte[] buffer, int offset, int size)
 49        {
 50            DecoderHelper.ValidateSize(size);
 51            if (IsValueDecoded)
 52            {
 53                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.FramingValueN
 54            }
 55            int bytesConsumed = 0;
 56            while (bytesConsumed < size)
 57            {
 58                int next = buffer[offset];
 59                _value |= (next & 0x7F) << (_index * 7);
 60                bytesConsumed++;
 61                if (_index == LastIndex && (next & 0xF8) != 0)
 62                {
 63                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(SR.FramingSizeToo
 64                }
 65                _index++;
 66                if ((next & 0x80) == 0)
 67                {
 68                    IsValueDecoded = true;
 69                    break;
 70                }
 71                offset++;
 72            }
 73            return bytesConsumed;
 74        }
 75    }
 76}

Methods/Properties

ValidateSize(System.Int32)