public void DecodeInPlace() { var list = new List <byte>(); for (int value = 0; value < 256; value++) { list.Add((byte)value); } var testBytes = list.ToArray(); for (int value = 0; value < 256; value++) { var sourceBytes = testBytes.AsSpan().Slice(0, value + 1); var buffer = new byte[Base64Encoder.ComputeEncodedLength(sourceBytes.Length)]; var bufferSlice = buffer.AsSpan(); Base64Encoder.TryEncode(sourceBytes, bufferSlice, out int consumed, out int written); var encodedText = Text.Encoding.ASCII.GetString(bufferSlice.ToArray()); var expectedText = Convert.ToBase64String(testBytes, 0, value + 1); Assert.Equal(expectedText, encodedText); var decodedByteCount = Base64Encoder.DecodeInPlace(bufferSlice); Assert.Equal(sourceBytes.Length, decodedByteCount); for (int i = 0; i < decodedByteCount; i++) { Assert.Equal(sourceBytes[i], buffer[i]); } } }