Show / Hide Table of Contents

Struct SpanReader<T>

Represents simple memory reader backed by ReadOnlySpan<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 SpanReader<T>
Type Parameters
Name Description
T

The type of elements in the span.

Constructors

| Edit this page View Source

SpanReader(ReadOnlySpan<T>)

Initializes a new memory reader.

Declaration
public SpanReader(ReadOnlySpan<T> span)
Parameters
Type Name Description
ReadOnlySpan<T> span

The span to read from.

| Edit this page View Source

SpanReader(ref T, int)

Initializes a new memory reader.

Declaration
public SpanReader(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

ConsumedCount

Gets the number of consumed elements.

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

ConsumedSpan

Gets the span over consumed elements.

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

Current

Gets the element at the current position in the underlying memory block.

Declaration
public readonly ref readonly T Current { get; }
Property Value
Type Description
T
Exceptions
Type Condition
InvalidOperationException

The position of this reader is out of range.

| Edit this page View Source

RemainingCount

Gets the number of unread elements.

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

RemainingSpan

Gets the remaining part of the span.

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

Span

Gets underlying span.

Declaration
public readonly ReadOnlySpan<T> Span { get; }
Property Value
Type Description
ReadOnlySpan<T>

Methods

| Edit this page View Source

Advance(int)

Advances the position of this reader.

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

The number of consumed elements.

Exceptions
Type Condition
ArgumentOutOfRangeException

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

| Edit this page View Source

Read()

Reads single element from the underlying span.

Declaration
public ref readonly T Read()
Returns
Type Description
T

The element obtained from the span.

Exceptions
Type Condition
InternalBufferOverflowException

The end of memory block is reached.

| Edit this page View Source

Read(int)

Reads the portion of data from the underlying span.

Declaration
public ReadOnlySpan<T> Read(int count)
Parameters
Type Name Description
int count

The number of elements to read from the underlying span.

Returns
Type Description
ReadOnlySpan<T>

The portion of data within the underlying span.

Exceptions
Type Condition
InternalBufferOverflowException

count is greater than RemainingCount.

| Edit this page View Source

Read(scoped Span<T>)

Copies elements from the underlying span.

Declaration
public int Read(scoped Span<T> output)
Parameters
Type Name Description
Span<T> output

The span used to write elements from the underlying span.

Returns
Type Description
int

The number of obtained elements.

| Edit this page View Source

ReadToEnd()

Reads the rest of the memory block.

Declaration
public ReadOnlySpan<T> ReadToEnd()
Returns
Type Description
ReadOnlySpan<T>

The rest of the memory block.

| Edit this page View Source

Read<TResult>(delegate*<ReadOnlySpan<T>, TResult>, int)

Decodes the value from the block of memory.

Declaration
[CLSCompliant(false)]
public TResult Read<TResult>(delegate*<ReadOnlySpan<T>, TResult> reader, int count)
Parameters
Type Name Description
delegate*<ReadOnlySpan<T>, TResult> reader

The decoder.

int count

The numbers of elements to read.

Returns
Type Description
TResult

The decoded value.

Type Parameters
Name Description
TResult

The type of the result.

Exceptions
Type Condition
ArgumentNullException

reader is zero.

InternalBufferOverflowException

count is greater than RemainingCount.

| Edit this page View Source

Reset()

Sets reader position to the first element.

Declaration
public void Reset()
| Edit this page View Source

Rewind(int)

Moves the reader 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 ConsumedCount.

| 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

TryRead(int, out ReadOnlySpan<T>)

Reads the portion of data from the underlying span.

Declaration
public bool TryRead(int count, out ReadOnlySpan<T> result)
Parameters
Type Name Description
int count

The number of elements to read from the underlying span.

ReadOnlySpan<T> result

The segment of the underlying span.

Returns
Type Description
bool

true if count is less than or equal to RemainingCount; otherwise false.

Exceptions
Type Condition
ArgumentOutOfRangeException

count is negative.

| Edit this page View Source

TryRead(scoped Span<T>)

Copies elements from the underlying span.

Declaration
public bool TryRead(scoped Span<T> output)
Parameters
Type Name Description
Span<T> output

The span used to write elements from the underlying span.

Returns
Type Description
bool

true if size of output is less than or equal to RemainingCount; otherwise, false.

| Edit this page View Source

TryRead(out T)

Reads single element from the underlying span.

Declaration
public bool TryRead(out T result)
Parameters
Type Name Description
T result

The obtained element.

Returns
Type Description
bool

true if element is obtained successfully; otherwise, false.

| Edit this page View Source

TryRead<TResult>(delegate*<ReadOnlySpan<T>, TResult>, int, out TResult)

Attempts to decode the value from the block of memory.

Declaration
[CLSCompliant(false)]
public bool TryRead<TResult>(delegate*<ReadOnlySpan<T>, TResult> reader, int count, out TResult result)
Parameters
Type Name Description
delegate*<ReadOnlySpan<T>, TResult> reader

The decoder.

int count

The numbers of elements to read.

TResult result

The decoded value.

Returns
Type Description
bool

true if the value is decoded successfully; otherwise, false.

Type Parameters
Name Description
TResult

The type of the value to be decoded.

Exceptions
Type Condition
ArgumentNullException

reader is zero.

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