Class BufferWriter<T>
Represents memory-backed output sink which T
data can be written.
Implements
Inherited Members
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 SourceCapacity
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 |
|
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 |
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 |
|
ObjectDisposedException | This writer has been disposed. |
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 |
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 |
|
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 SourceAdd(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. |
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. |
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 |
|
InvalidOperationException | Attempts to advance past the end of the underlying buffer. |
ObjectDisposedException | This writer has been disposed. |
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. |
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. |
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
| Edit this page View SourceGetEnumerator()
Gets enumerator over all written elements.
Declaration
public IEnumerator<T> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<T> | The enumerator over all written elements. |
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 |
Exceptions
Type | Condition |
---|---|
OutOfMemoryException | The requested buffer size is not available. |
ObjectDisposedException | This writer has been disposed. |
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 |
Exceptions
Type | Condition |
---|---|
OutOfMemoryException | The requested buffer size is not available. |
ObjectDisposedException | This writer has been disposed. |
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 |
|
ToString()
Gets the textual representation of this buffer.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | The textual representation of this buffer. |