Show / Hide Table of Contents

Struct SpanWriter<T>

Represents simple memory writer backed by Span<T>.

Inherited Members
ValueType.Equals(object)
ValueType.GetHashCode()
object.Equals(object, object)
object.GetType()
object.ReferenceEquals(object, object)
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 Source

SpanWriter(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.

| Edit this page View Source

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

length is negative.

Properties

| Edit this page View Source

Current

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.

| Edit this page View Source

FreeCapacity

Gets the available space in the underlying span.

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

RemainingSpan

Gets the remaining part of the span.

Declaration
public readonly Span<T> RemainingSpan { get; }
Property Value
Type Description
Span<T>
| Edit this page View Source

Span

Gets underlying span.

Declaration
public readonly Span<T> Span { get; }
Property Value
Type Description
Span<T>
| Edit this page View Source

WrittenCount

Gets the number of occupied elements in the underlying span.

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

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 Source

Add()

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.

| Edit this page View Source

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.

| Edit this page View Source

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

count is greater than the available space in the rest of the memory block.

| Edit this page View Source

Reset()

Sets writer position to the first element.

Declaration
public void Reset()
| 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
ArgumentOutOfRangeException

count is less than zero or greater than WrittenCount.

| Edit this page View Source

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

count is negative or greater than FreeCapacity.

| Edit this page View Source

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.

| Edit this page View Source

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
ValueType.ToString()
| Edit this page View Source

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
bool

true if item has been placed successfully; false if remaining space in the underlying span is not enough to place the item.

| Edit this page View Source

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 count elements.

Exceptions
Type Condition
ArgumentOutOfRangeException

count is negative.

| Edit this page View Source

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 input.

| Edit this page View Source

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

action is zero.

| Edit this page View Source

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.

| Edit this page View Source

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

action is zero.

ArgumentOutOfRangeException

count is negative or greater than FreeCapacity.

  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾