Show / Hide Table of Contents

Class BufferWriter<T>

Represents memory-backed output sink which T data can be written.

Inheritance
object
Disposable
BufferWriter<T>
PoolingArrayBufferWriter<T>
PoolingBufferWriter<T>
Implements
IBufferWriter<T>
ISupplier<ReadOnlyMemory<T>>
IFunctional<Func<ReadOnlyMemory<T>>>
IReadOnlyList<T>
IReadOnlyCollection<T>
IEnumerable<T>
IEnumerable
IGrowableBuffer<T>
IReadOnlySpanConsumer<T>
ISupplier<ReadOnlyMemory<T>, CancellationToken, ValueTask>
IFunctional<Func<ReadOnlyMemory<T>, CancellationToken, ValueTask>>
IDisposable
IResettable
Inherited Members
Disposable.IsDisposed
Disposable.IsDisposing
Disposable.IsDisposingOrDisposed
Disposable.CreateException()
Disposable.DisposedTask
Disposable.GetDisposedTask<T>()
Disposable.TrySetDisposedException<T>(TaskCompletionSource<T>)
Disposable.TrySetDisposedException(TaskCompletionSource)
Disposable.DisposeAsyncCore()
Disposable.DisposeAsync()
Disposable.TryBeginDispose()
Disposable.Dispose()
Disposable.Dispose(IEnumerable<IDisposable>)
Disposable.DisposeAsync(IEnumerable<IAsyncDisposable>)
Disposable.Dispose<T>(ReadOnlySpan<T>)
Disposable.DisposeAsync(params IAsyncDisposable[])
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
Namespace: DotNext.Buffers
Assembly: DotNext.dll
Syntax
public abstract class BufferWriter<T> : Disposable, IBufferWriter<T>, ISupplier<ReadOnlyMemory<T>>, IFunctional<Func<ReadOnlyMemory<T>>>, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, IGrowableBuffer<T>, IReadOnlySpanConsumer<T>, ISupplier<ReadOnlyMemory<T>, CancellationToken, ValueTask>, IFunctional<Func<ReadOnlyMemory<T>, CancellationToken, ValueTask>>, IDisposable, IResettable
Type Parameters
Name Description
T

The data type that can be written.

Properties

| Edit this page View Source

Capacity

Gets or sets the total amount of space within the underlying memory.

Declaration
public abstract int Capacity { get; init; }
Property Value
Type Description
int
Exceptions
Type Condition
ArgumentOutOfRangeException

value is less than zero.

| Edit this page View Source

FreeCapacity

Gets the amount of space available that can still be written into without forcing the underlying buffer to grow.

Declaration
public int FreeCapacity { get; }
Property Value
Type Description
int
| Edit this page View Source

this[int]

Gets the element at the specified index.

Declaration
public ref readonly T this[int index] { get; }
Parameters
Type Name Description
int index

The index of the element to retrieve.

Property Value
Type Description
T

The element at the specified index.

Exceptions
Type Condition
IndexOutOfRangeException

index the index is invalid.

ObjectDisposedException

This writer has been disposed.

| Edit this page View Source

MeasurementTags

Sets a list of tags to be associated with each measurement.

Declaration
[CLSCompliant(false)]
public virtual TagList MeasurementTags { init; }
Property Value
Type Description
TagList
| Edit this page View Source

WrittenCount

Gets or sets the amount of data written to the underlying memory so far.

Declaration
public int WrittenCount { get; set; }
Property Value
Type Description
int
Exceptions
Type Condition
ArgumentOutOfRangeException

value is greater than Capacity.

| Edit this page View Source

WrittenMemory

Gets the data written to the underlying buffer so far.

Declaration
public abstract ReadOnlyMemory<T> WrittenMemory { get; }
Property Value
Type Description
ReadOnlyMemory<T>
Exceptions
Type Condition
ObjectDisposedException

This writer has been disposed.

Methods

| Edit this page View Source

Add(T)

Writes single element.

Declaration
public void Add(T item)
Parameters
Type Name Description
T item

The element to write.

Exceptions
Type Condition
ObjectDisposedException

This writer has been disposed.

| Edit this page View Source

AddAll(ICollection<T>)

Writes multiple elements.

Declaration
public virtual void AddAll(ICollection<T> items)
Parameters
Type Name Description
ICollection<T> items

The collection of elements to be copied.

Exceptions
Type Condition
ObjectDisposedException

This writer has been disposed.

| Edit this page View Source

Advance(int)

Notifies this writer that count of data items were written.

Declaration
public void Advance(int count)
Parameters
Type Name Description
int count

The number of data items written to the underlying buffer.

Exceptions
Type Condition
ArgumentOutOfRangeException

count is less than zero.

InvalidOperationException

Attempts to advance past the end of the underlying buffer.

ObjectDisposedException

This writer has been disposed.

| Edit this page View Source

Clear(bool)

Clears the data written to the underlying memory.

Declaration
public abstract void Clear(bool reuseBuffer = false)
Parameters
Type Name Description
bool reuseBuffer

true to reuse the internal buffer; false to destroy the internal buffer.

Exceptions
Type Condition
ObjectDisposedException

This writer has been disposed.

| Edit this page View Source

DetachBuffer()

Transfers ownership of the written memory from this writer to the caller.

Declaration
public abstract MemoryOwner<T> DetachBuffer()
Returns
Type Description
MemoryOwner<T>

The object representing all written content.

Remarks

The caller is responsible for the lifetime of the returned buffer. The current state of this writer will be reset.

Exceptions
Type Condition
ObjectDisposedException

This writer has been disposed.

| Edit this page View Source

Dispose(bool)

Releases managed and unmanaged resources associated with this object.

Declaration
protected override void Dispose(bool disposing)
Parameters
Type Name Description
bool disposing

true if called from Dispose(); false if called from finalizer ~Disposable().

Overrides
Disposable.Dispose(bool)
| Edit this page View Source

GetEnumerator()

Gets enumerator over all written elements.

Declaration
public IEnumerator<T> GetEnumerator()
Returns
Type Description
IEnumerator<T>

The enumerator over all written elements.

| Edit this page View Source

GetMemory(int)

Returns the memory to write to that is at least the requested size.

Declaration
public abstract Memory<T> GetMemory(int sizeHint = 0)
Parameters
Type Name Description
int sizeHint

The minimum length of the returned memory.

Returns
Type Description
Memory<T>

The memory block of at least the size sizeHint.

Exceptions
Type Condition
OutOfMemoryException

The requested buffer size is not available.

ObjectDisposedException

This writer has been disposed.

| Edit this page View Source

GetSpan(int)

Returns the memory to write to that is at least the requested size.

Declaration
public virtual Span<T> GetSpan(int sizeHint = 0)
Parameters
Type Name Description
int sizeHint

The minimum length of the returned memory.

Returns
Type Description
Span<T>

The memory block of at least the size sizeHint.

Exceptions
Type Condition
OutOfMemoryException

The requested buffer size is not available.

ObjectDisposedException

This writer has been disposed.

| Edit this page View Source

Rewind(int)

Moves the writer back the specified number of items.

Declaration
public void Rewind(int count)
Parameters
Type Name Description
int count

The number of items.

Exceptions
Type Condition
ObjectDisposedException

This writer has been disposed.

ArgumentOutOfRangeException

count is less than zero or greater than WrittenCount.

| Edit this page View Source

ToString()

Gets the textual representation of this buffer.

Declaration
public override string ToString()
Returns
Type Description
string

The textual representation of this buffer.

Overrides
object.ToString()

Implements

IBufferWriter<T>
ISupplier<TResult>
IFunctional<TDelegate>
IReadOnlyList<T>
IReadOnlyCollection<T>
IEnumerable<T>
IEnumerable
IGrowableBuffer<T>
IReadOnlySpanConsumer<T>
ISupplier<T1, T2, TResult>
IFunctional<TDelegate>
IDisposable
IResettable

Extension Methods

BasicExtensions.As<T>(T)
BasicExtensions.GetUserData<T>(T)
BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, ReadOnlySpan<T>)
ExpressionBuilder.Const<T>(T)
AsyncLockAcquisition.AcquireLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireLockAsync<T>(T, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, bool, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, bool, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, TimeSpan, CancellationToken)
LockAcquisition.AcquireReadLock<T>(T)
LockAcquisition.AcquireReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireUpgradeableReadLock<T>(T)
LockAcquisition.AcquireUpgradeableReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireWriteLock<T>(T)
LockAcquisition.AcquireWriteLock<T>(T, TimeSpan)
BufferWriter.Write<T>(IBufferWriter<T>, in ReadOnlySequence<T>)
Collection.Append<T>(IEnumerable<T>, params T[])
Collection.Copy<T>(IEnumerable<T>, int, MemoryAllocator<T>?)
Collection.ElementAt<T>(IEnumerable<T>, int, out T)
Collection.FirstOrNone<T>(IEnumerable<T>)
Collection.ForEachAsync<T>(IEnumerable<T>, Func<T, CancellationToken, ValueTask>, CancellationToken)
Collection.ForEach<T>(IEnumerable<T>, Action<T>)
Collection.LastOrNone<T>(IEnumerable<T>)
Collection.Prepend<T>(IEnumerable<T>, params T[])
Collection.SequenceHashCode<T>(IEnumerable<T>, bool)
Collection.ToAsyncEnumerable<T>(IEnumerable<T>)
Collection.ToString<T>(IEnumerable<T>, string, string)
Enumerator.GetAsyncEnumerator<T>(IEnumerable<T>, CancellationToken)
Collection.Convert<TInput, TOutput>(IReadOnlyCollection<TInput>, Converter<TInput, TOutput>)
List.Convert<TInput, TOutput>(IReadOnlyList<TInput>, Converter<TInput, TOutput>)
List.IndexerGetter<T>(IReadOnlyList<T>)
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾