< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.IntDecoder
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/FramingDecoder.cs
Line coverage
87%
Covered lines: 21
Uncovered lines: 3
Coverable lines: 24
Total lines: 76
Line coverage: 87.5%
Branch coverage
66%
Covered branches: 8
Total branches: 12
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
Reset()100%11100%
Decode(...)70%101087.5%

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        {
 13            if (size <= 0)
 14            {
 15                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(size), 
 16            }
 17        }
 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            {
 40930                if (!IsValueDecoded)
 31                {
 032                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.FramingVa
 33                }
 34
 40935                return _value;
 36            }
 37        }
 38
 155539        public bool IsValueDecoded { get; private set; }
 40
 41        public void Reset()
 42        {
 32843            _index = 0;
 32844            _value = 0;
 32845            IsValueDecoded = false;
 32846        }
 47
 48        public int Decode(byte[] buffer, int offset, int size)
 49        {
 40950            DecoderHelper.ValidateSize(size);
 40951            if (IsValueDecoded)
 52            {
 053                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.FramingValueN
 54            }
 40955            int bytesConsumed = 0;
 45356            while (bytesConsumed < size)
 57            {
 45358                int next = buffer[offset];
 45359                _value |= (next & 0x7F) << (_index * 7);
 45360                bytesConsumed++;
 45361                if (_index == LastIndex && (next & 0xF8) != 0)
 62                {
 063                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataException(SR.FramingSizeToo
 64                }
 45365                _index++;
 45366                if ((next & 0x80) == 0)
 67                {
 40968                    IsValueDecoded = true;
 40969                    break;
 70                }
 4471                offset++;
 72            }
 40973            return bytesConsumed;
 74        }
 75    }
 76}