Struct SpanWriter<T>
Represents simple memory writer backed by Span<T>.
Inherited Members
Namespace: DotNext.Buffers
Assembly: DotNext.dll
Syntax
public ref struct SpanWriter<T>
  Type Parameters
| Name | Description | 
|---|---|
| T | The type of elements in the span.  | 
      
Constructors
| Edit this page 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.  | 
      
SpanWriter(ref T, int)
Initializes a new memory writer.
Declaration
public SpanWriter(ref T reference, int length)
  Parameters
| Type | Name | Description | 
|---|---|---|
| T | reference | Managed pointer to the memory block.  | 
      
| int | length | The length of the elements referenced by the pointer.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentOutOfRangeException | 
  | 
      
Properties
| Edit this page View SourceCurrent
Gets the element at the current position in the underlying memory block.
Declaration
public readonly ref 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 readonly int FreeCapacity { get; }
  Property Value
| Type | Description | 
|---|---|
| int | 
RemainingSpan
Gets the remaining part of the span.
Declaration
public readonly Span<T> RemainingSpan { get; }
  Property Value
| Type | Description | 
|---|---|
| Span<T> | 
Span
Gets underlying span.
Declaration
public readonly 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 { readonly get; set; }
  Property Value
| Type | Description | 
|---|---|
| int | 
WrittenSpan
Gets the span overwritten elements.
Declaration
public readonly Span<T> WrittenSpan { get; }
  Property Value
| Type | Description | 
|---|---|
| Span<T> | The segment of underlying span containing written elements.  | 
      
Methods
| Edit this page View SourceAdd()
Adds single element and returns a reference to it.
Declaration
public ref T Add()
  Returns
| Type | Description | 
|---|---|
| T | The reference to the added element.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| InternalBufferOverflowException | Remaining space in the underlying span is not enough to place the item.  | 
      
Add(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 | 
|---|---|
| InternalBufferOverflowException | Remaining space in the underlying span is not enough to place the item.  | 
      
Advance(int)
Advances the position of this writer.
Declaration
public void Advance(int count)
  Parameters
| Type | Name | Description | 
|---|---|---|
| int | count | The number of written elements.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentOutOfRangeException | 
  | 
      
Reset()
Sets writer position to the first element.
Declaration
public void Reset()
  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 | 
|---|---|
| ArgumentOutOfRangeException | 
  | 
      
Slide(int)
Obtains the portion of underlying span and marks it as written.
Declaration
public Span<T> Slide(int count)
  Parameters
| Type | Name | Description | 
|---|---|---|
| int | count | The size of the segment.  | 
      
Returns
| Type | Description | 
|---|---|
| Span<T> | The portion of the underlying span.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentOutOfRangeException | 
  | 
      
SlideToEnd()
Obtains the tail of the remaining buffer and advances to its end.
Declaration
public Span<T> SlideToEnd()
  Returns
| Type | Description | 
|---|---|
| Span<T> | The tail of the remaining buffer.  | 
      
ToString()
Gets the textual representation of the written content.
Declaration
public override readonly string ToString()
  Returns
| Type | Description | 
|---|---|
| string | The textual representation of the written content.  | 
      
Overrides
| Edit this page View SourceTryAdd(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 | 
|---|---|
| bool | true if item has been placed successfully; false if remaining space in the underlying span is not enough to place the item.  | 
      
TrySlide(int, 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 | 
|---|---|---|
| int | count | The size of the segment.  | 
      
| Span<T> | segment | The portion of the underlying span.  | 
      
Returns
| Type | Description | 
|---|---|
| bool | true if segment is obtained successfully;
false if remaining space in the underlying span is not enough to place   | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentOutOfRangeException | 
  | 
      
TryWrite(scoped ReadOnlySpan<T>)
Copies the elements to the underlying span.
Declaration
public bool TryWrite(scoped ReadOnlySpan<T> input)
  Parameters
| Type | Name | Description | 
|---|---|---|
| ReadOnlySpan<T> | input | The span to copy from.  | 
      
Returns
| Type | Description | 
|---|---|
| bool | true if all elements are copied successfully;
false if remaining space in the underlying span is not enough to place all elements from   | 
      
TryWrite<TArg>(delegate*<TArg, Span<T>, out int, bool>, TArg)
Attempts to write a portion of data.
Declaration
[CLSCompliant(false)]
public bool TryWrite<TArg>(delegate*<TArg, Span<T>, out int, bool> action, TArg arg)
  Parameters
| Type | Name | Description | 
|---|---|---|
| delegate*<TArg, Span<T>, out int, bool> | action | The action responsible for writing elements.  | 
      
| TArg | arg | The state to be passed to the action.  | 
      
Returns
| Type | Description | 
|---|---|
| bool | true if all elements are written successfully; otherwise, false.  | 
      
Type Parameters
| Name | Description | 
|---|---|
| TArg | The type of the argument to be passed to the callback.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentNullException | 
  | 
      
Write(scoped ReadOnlySpan<T>)
Copies the elements to the underlying span.
Declaration
public int Write(scoped ReadOnlySpan<T> input)
  Parameters
| Type | Name | Description | 
|---|---|---|
| ReadOnlySpan<T> | input | The span of elements to copy from.  | 
      
Returns
| Type | Description | 
|---|---|
| int | The number of written elements.  | 
      
Write<TArg>(delegate*<TArg, Span<T>, void>, TArg, int)
Writes a portion of data.
Declaration
[CLSCompliant(false)]
public void Write<TArg>(delegate*<TArg, Span<T>, void> action, TArg arg, int count)
  Parameters
| Type | Name | Description | 
|---|---|---|
| delegate*<TArg, Span<T>, void> | action | The action responsible for writing elements.  | 
      
| TArg | arg | The state to be passed to the action.  | 
      
| int | count | The number of the elements to be written.  | 
      
Type Parameters
| Name | Description | 
|---|---|
| TArg | The type of the argument to be passed to the callback.  | 
      
Exceptions
| Type | Condition | 
|---|---|
| ArgumentNullException | 
  | 
      
| ArgumentOutOfRangeException | 
  |