Struct SpanWriter<T>
Represents simple memory writer backed by Span<T>.
Inherited Members
Namespace: DotNext.Buffers
Assembly: DotNext.dll
Syntax
public struct SpanWriter<T>
Type Parameters
Name | Description |
---|---|
T | The type of elements in the span. |
Constructors
| Improve this Doc View SourceSpanWriter(Span<T>)
Initializes a new memory writer.
Declaration
public SpanWriter(Span<T> span)
Parameters
Type | Name | Description |
---|---|---|
Span<T> | span | The span used to write elements. |
Properties
| Improve this Doc View SourceCurrent
Gets the element at the current position in the underlying memory block.
Declaration
public T Current { get; }
Property Value
Type | Description |
---|---|
T |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The position of this writer is out of range. |
FreeCapacity
Gets the available space in the underlying span.
Declaration
public int FreeCapacity { get; }
Property Value
Type | Description |
---|---|
Int32 |
Span
Gets underlying span.
Declaration
public Span<T> Span { get; }
Property Value
Type | Description |
---|---|
Span<T> |
WrittenCount
Gets the number of occupied elements in the underlying span.
Declaration
public int WrittenCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
WrittenSpan
Gets the span over written elements.
Declaration
public Span<T> WrittenSpan { get; }
Property Value
Type | Description |
---|---|
Span<T> | The segment of underlying span containing written elements. |
Methods
| Improve this Doc View SourceAdd(T)
Puts single element into the underlying span.
Declaration
public void Add(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to place. |
Exceptions
Type | Condition |
---|---|
EndOfStreamException | Remaining space in the underlying span is not enough to place the item. |
Reset()
Sets writer position to the first element.
Declaration
public void Reset()
Slide(Int32)
Obtains the portion of underlying span and marks it as written.
Declaration
public Span<T> Slide(int count)
Parameters
Type | Name | Description |
---|---|---|
Int32 | count | The size of the segment. |
Returns
Type | Description |
---|---|
Span<T> | The portion of the underlying span. |
Exceptions
Type | Condition |
---|---|
EndOfStreamException | Remaining space in the underlying span is not enough to place |
TryAdd(T)
Puts single element into the underlying span.
Declaration
public bool TryAdd(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to place. |
Returns
Type | Description |
---|---|
Boolean | true if item has beem placed successfully; false if remaining space in the underlying span is not enough to place the item. |
TrySlide(Int32, out Span<T>)
Obtains the portion of underlying span and marks it as written.
Declaration
public bool TrySlide(int count, out Span<T> segment)
Parameters
Type | Name | Description |
---|---|---|
Int32 | count | The size of the segment. |
Span<T> | segment | The portion of the underlying span. |
Returns
Type | Description |
---|---|
Boolean | true if segment is obtained successfully;
false if remaining space in the underlying span is not enough to place |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
TryWrite(ReadOnlySpan<T>)
Copies the elements to the underlying span.
Declaration
public bool TryWrite(ReadOnlySpan<T> input)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<T> | input | The span to copy from. |
Returns
Type | Description |
---|---|
Boolean | true if all elements are copied successfully;
false if remaining space in the underlying span is not enough to place all elements from |
Write(ReadOnlySpan<T>)
Copies the elements to the underlying span.
Declaration
public int Write(ReadOnlySpan<T> input)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<T> | input | The span of elements to copy from. |
Returns
Type | Description |
---|---|
Int32 | The number of written elements. |