Пример #1
0
        /// <inheritdoc/>
        public override int GetByteCount(ReadOnlySpan <char> chars)
        {
            var         decoder      = new Base16Decoder(Settings);
            Span <byte> outputBuffer = stackalloc byte[1024];

            int           inputOffset  = 0;
            int           inputCount   = chars.Length;
            int           outputLength = 0;
            ConvertStatus convertStatus;

            do
            {
                convertStatus = decoder.ConvertData(chars, inputOffset, inputCount,
                                                    outputBuffer, 0, outputBuffer.Length,
                                                    true,
                                                    out var inputUsed,
                                                    out var outputUsed);

                outputLength += outputUsed;
                inputOffset  += inputUsed;
                inputCount   -= inputUsed;
            } while (!convertStatus);

            return(outputLength);
        }
        public void ConstructorAlphabetTest()
        {
            char[]        testAlphabet = new char[] { 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H' };
            Base16Decoder decoder      = new Base16Decoder(testAlphabet);

            Common.AreEqual(testAlphabet, decoder.Alphabet);
        }
Пример #3
0
        /// <inheritdoc/>
        public override byte[] GetBytes(ReadOnlySpan <char> chars)
        {
            // GetBytes converts in two passes so that it can perform a single allocation
            // for the final array of bytes...

            int bytesRequired = GetByteCount(chars);

            if (bytesRequired == 0)
            {
                return(Array.Empty <byte>());
            }

            var outputBytes = new byte[bytesRequired];

            var decoder       = new Base16Decoder(Settings);
            var convertStatus = decoder.ConvertData(chars, 0, chars.Length,
                                                    outputBytes.AsSpan(), 0, outputBytes.Length,
                                                    true,
                                                    out var inputUsed,
                                                    out var outputUsed);

            System.Diagnostics.Debug.Assert(convertStatus);
            System.Diagnostics.Debug.Assert(inputUsed == chars.Length);
            System.Diagnostics.Debug.Assert(outputUsed == outputBytes.Length);

            return(outputBytes);
        }
        public void GetInputEncodingTest()
        {
            Base16Decoder decoder = new Base16Decoder();

            System.Text.Encoding encoding = decoder.GetInputEncoding();
            Assert.IsNotNull(encoding);
            Assert.AreEqual(System.Text.Encoding.ASCII, encoding);
        }
        public void GetEncoderTest()
        {
            Base16Decoder decoder = new Base16Decoder();
            Encoder       encoder = decoder.GetEncoder();

            Assert.IsNotNull(encoder);
            Assert.IsInstanceOf(typeof(Base16Encoder), encoder);
        }
        public void IsCaseSensitiveTest()
        {
            Base16Decoder decoder = new Base16Decoder();

            Assert.IsFalse(decoder.IsCaseSensitive);
        }
        public void ConstructorDefaultTest()
        {
            Base16Decoder decoder = new Base16Decoder();

            Common.AreEqual(Base16Encoder.StandardAlphabet, decoder.Alphabet);
        }
        public void AlphabetShortTest()
        {
            Base16Decoder decoder = new Base16Decoder();

            decoder.Alphabet = new char[1];
        }
        public void AlphabetNullTest()
        {
            Base16Decoder decoder = new Base16Decoder();

            decoder.Alphabet = null;
        }
        public void MissingCharacterTest()
        {
            Base16Decoder decoder = new Base16Decoder();

            decoder.Decode("ABCDE");
        }
        public void InvalidCharacterTest()
        {
            Base16Decoder decoder = new Base16Decoder();

            decoder.Decode("ABCDE!");
        }
Пример #12
0
 public Decoder(Base16Settings settings)
 {
     _codecDecoder = new Base16Decoder(settings);
 }