< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.CorrelationIdGenerator
Assembly: CoreWCF.NetNamedPipe
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetNamedPipe/src/CoreWCF/Channels/CorrelationIdGenerator.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 19
Coverable lines: 19
Total lines: 43
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%110%
GetNextId()100%110%
GenerateId(...)100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetNamedPipe/src/CoreWCF/Channels/CorrelationIdGenerator.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.Collections.Generic;
 6using System.Text;
 7using System.Threading;
 8
 9namespace CoreWCF.Channels
 10{
 11    internal static class CorrelationIdGenerator
 12    {
 13        // Base32 encoding - in ascii sort order for easy text based sorting
 014        private static readonly char[] s_encode32Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUV".ToCharArray();
 15
 16        // Seed the _lastConnectionId for this application instance with
 17        // the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001
 18        // for a roughly increasing _lastId over restarts
 019        private static long _lastId = DateTime.UtcNow.Ticks;
 20
 021        public static string GetNextId() => GenerateId(Interlocked.Increment(ref _lastId));
 22
 23        private static string GenerateId(long id)
 24        {
 025            char[] encode32Chars = s_encode32Chars;
 026            Span<char> buffer = stackalloc char[13];
 027            buffer[12] = encode32Chars[id & 31];
 028            buffer[11] = encode32Chars[(id >> 5) & 31];
 029            buffer[10] = encode32Chars[(id >> 10) & 31];
 030            buffer[9] = encode32Chars[(id >> 15) & 31];
 031            buffer[8] = encode32Chars[(id >> 20) & 31];
 032            buffer[7] = encode32Chars[(id >> 25) & 31];
 033            buffer[6] = encode32Chars[(id >> 30) & 31];
 034            buffer[5] = encode32Chars[(id >> 35) & 31];
 035            buffer[4] = encode32Chars[(id >> 40) & 31];
 036            buffer[3] = encode32Chars[(id >> 45) & 31];
 037            buffer[2] = encode32Chars[(id >> 50) & 31];
 038            buffer[1] = encode32Chars[(id >> 55) & 31];
 039            buffer[0] = encode32Chars[(id >> 60) & 31];
 040            return buffer.ToString();
 41        }
 42    }
 43}