IGrowableBuffer<T>
public interface IGrowableBuffer<T> : IReadOnlySpanConsumer<T>, ISupplier<ReadOnlyMemory<T>, CancellationToken, ValueTask>, IDisposable
Represents common interface for growable buffer writers.
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
namespace DotNext.Buffers
{
[System.Runtime.CompilerServices.NullableContext(1)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public interface IGrowableBuffer<[System.Runtime.CompilerServices.Nullable(2)] T> : IReadOnlySpanConsumer<T>, ISupplier<ReadOnlyMemory<T>, CancellationToken, ValueTask>, IDisposable
{
const int DefaultInitialBufferSize = 128;
long WrittenCount { get; }
long? Capacity => null;
void Write([System.Runtime.CompilerServices.Nullable(new byte[] {
0,
1
})] ReadOnlySpan<T> input);
void IReadOnlySpanConsumer<T>.Invoke([System.Runtime.CompilerServices.Nullable(new byte[] {
0,
1
})] ReadOnlySpan<T> input)
{
Write(input);
}
void Write(T value)
{
Write(MemoryMarshal.CreateReadOnlySpan<T>(ref value, 1));
}
void CopyTo<TConsumer>(TConsumer consumer) where TConsumer : IReadOnlySpanConsumer<T>;
ValueTask CopyToAsync<TConsumer>(TConsumer consumer, CancellationToken token) where TConsumer : ISupplier<ReadOnlyMemory<T>, CancellationToken, ValueTask>;
int CopyTo([System.Runtime.CompilerServices.Nullable(new byte[] {
0,
1
})] Span<T> output);
void Clear();
bool TryGetWrittenContent([System.Runtime.CompilerServices.Nullable(new byte[] {
0,
1
})] out ReadOnlyMemory<T> block);
int? GetBufferSize(int sizeHint, int capacity, int writtenCount)
{
if (sizeHint < 0)
throw new ArgumentOutOfRangeException("sizeHint");
if (sizeHint == 0)
sizeHint = 1;
if (sizeHint > capacity - writtenCount) {
int num = Math.Max(capacity, sizeHint);
if (capacity == 0)
num = Math.Max(num, 128);
int num2 = capacity + num;
if ((uint)num2 > 2147483647) {
num2 = capacity + sizeHint;
if ((uint)num2 > 2147483647)
throw new InsufficientMemoryException();
}
return num2;
}
return null;
}
}
}