private unsafe static void WriteAsciiMultiWrite(ref WritableBufferWriter buffer, string data) { var remaining = data.Length; fixed(char *input = data) { var inputSlice = input; while (remaining > 0) { var writable = Math.Min(remaining, buffer.Span.Length); if (writable == 0) { buffer.Ensure(); continue; } fixed(byte *output = &buffer.Span.DangerousGetPinnableReference()) { EncodeAsciiCharsToBytes(inputSlice, output, writable); } inputSlice += writable; remaining -= writable; buffer.Advance(writable); } } }
public void EnsureAllocatesSpan() { _buffer = _pipe.Writer.Alloc(); var writer = new WritableBufferWriter(_buffer); writer.Ensure(10); Assert.True(writer.Span.Length > 10); Assert.Equal(new byte[] {}, Read()); }