Exemple #1
0
        public void ValidInputOnlyMultiByte()
        {
            Span <byte> inputSpan = new byte[1000];

            Base64TestHelper.InitalizeDecodableBytes(inputSpan);
            int         requiredLength = Base64.GetMaxDecodedFromUtf8Length(inputSpan.Length);
            Span <byte> expected       = new byte[requiredLength];

            Assert.Equal(OperationStatus.Done, Base64.DecodeFromUtf8(inputSpan, expected, out int bytesConsumed, out int bytesWritten));

            byte[][] input = new byte[10][];

            int[] split = { 100, 102, 98, 101, 2, 97, 101, 1, 2, 396 };

            int sum = 0;

            for (int i = 0; i < split.Length; i++)
            {
                int splitter = split[i];
                input[i] = inputSpan.Slice(sum, splitter).ToArray();
                sum     += splitter;
            }
            Assert.Equal(1000, sum);

            var(first, last) = BufferList.Create(input);

            var output = new TestOutput();

            Base64Experimental.Utf8ToBytesDecoder.Pipe(new ReadOnlyBuffer <byte>(first, 0, last, last.Memory.Length), output);

            var expectedArray = expected.ToArray();
            var array         = output.GetBuffer.ToArray();

            Assert.True(expected.SequenceEqual(output.GetBuffer.Slice(0, requiredLength)));
        }
Exemple #2
0
        private static void StichingTestNoStichingNeeded(int inputBufferSize)
        {
            Span <byte> source = new byte[inputBufferSize];

            Base64TestHelper.InitalizeDecodableBytes(source);
            Span <byte> expected = new byte[inputBufferSize];

            Base64.DecodeFromUtf8(source, expected, out int expectedConsumed, out int expectedWritten);

            Base64TestHelper.SplitSourceIntoSpans(source, false, out ReadOnlySpan <byte> source1, out ReadOnlySpan <byte> source2);

            Span <byte> destination = new byte[inputBufferSize]; // Plenty of space

            int bytesConsumed = 0;
            int bytesWritten  = 0;

            foreach (var iteration in Benchmark.Iterations)
            {
                using (iteration.StartMeasurement())
                {
                    for (int i = 0; i < Benchmark.InnerIterationCount; i++)
                    {
                        Base64TestHelper.DecodeNoNeedToStich(source1, source2, destination, out bytesConsumed, out bytesWritten);
                    }
                }
            }

            Assert.Equal(expectedConsumed, bytesConsumed);
            Assert.Equal(expectedWritten, bytesWritten);
            Assert.True(expected.SequenceEqual(destination));
        }