BaseNcoding.BaseN.Decode C# (CSharp) Метод

Decode() публичный Метод

public Decode ( string data ) : byte[]
data string
Результат byte[]
        public override byte[] Decode(string data)
        {
            if (string.IsNullOrEmpty(data))
                return new byte[0];

            int globalBitsLength = ((data.Length - 1) * BlockBitsCount / BlockCharsCount + 8) / 8 * 8;
            int mainBitsLength = globalBitsLength / BlockBitsCount * BlockBitsCount;
            int tailBitsLength = globalBitsLength - mainBitsLength;
            int mainCharsCount = mainBitsLength * BlockCharsCount / BlockBitsCount;
            int tailCharsCount = (tailBitsLength * BlockCharsCount + BlockBitsCount - 1) / BlockBitsCount;
            ulong tailBits = CharsToBits(data, mainCharsCount, tailCharsCount);
            if (tailBits >> tailBitsLength != 0)
            {
                globalBitsLength += 8;
                mainBitsLength = globalBitsLength / BlockBitsCount * BlockBitsCount;
                tailBitsLength = globalBitsLength - mainBitsLength;
                mainCharsCount = mainBitsLength * BlockCharsCount / BlockBitsCount;
                tailCharsCount = (tailBitsLength * BlockCharsCount + BlockBitsCount - 1) / BlockBitsCount;
            }
            int iterationCount = mainCharsCount / BlockCharsCount;

            byte[] result = new byte[globalBitsLength / 8];

            if (!Parallel)
            {
                DecodeBlock(data, result, 0, iterationCount);
            }
            else
            {
                int processorCount = Math.Min(iterationCount, Environment.ProcessorCount);
                System.Threading.Tasks.Parallel.For(0, processorCount, i =>
                {
                    int beginInd = i * iterationCount / processorCount;
                    int endInd = (i + 1) * iterationCount / processorCount;
                    DecodeBlock(data, result, beginInd, endInd);
                });
            }

            if (tailCharsCount != 0)
            {
                ulong bits = CharsToBits(data, mainCharsCount, tailCharsCount);
                AddBits64(result, bits, mainBitsLength, tailBitsLength);
            }

            return result;
        }