Show / Hide Table of Contents

Struct SpanReader<T>

Represents simple memory reader backed by ReadOnlySpan<T>.

Inherited Members
ValueType.Equals(Object)
ValueType.GetHashCode()
ValueType.ToString()
Object.Equals(Object, Object)
Object.GetType()
Object.ReferenceEquals(Object, Object)
Namespace: DotNext.Buffers
Assembly: DotNext.dll
Syntax
public struct SpanReader<T>
Type Parameters
Name Description
T

The type of elements in the span.

Constructors

| Improve this Doc 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.

Properties

| Improve this Doc View Source

ConsumedCount

Gets the number of consumed elements.

Declaration
public int ConsumedCount { get; }
Property Value
Type Description
Int32
| Improve this Doc View Source

ConsumedSpan

Gets the span over consumed elements.

Declaration
public ReadOnlySpan<T> ConsumedSpan { get; }
Property Value
Type Description
ReadOnlySpan<T>
| Improve this Doc View Source

Current

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 reader is out of range.

| Improve this Doc View Source

RemainingCount

Gets the number of unread elements.

Declaration
public int RemainingCount { get; }
Property Value
Type Description
Int32
| Improve this Doc View Source

Span

Gets underlying span.

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

Methods

| Improve this Doc View Source

Read()

Reads single element from the underlying span.

Declaration
public T Read()
Returns
Type Description
T

The element obtained from the span.

Exceptions
Type Condition
EndOfStreamException

The end of memory block is reached.

| Improve this Doc View Source

Read(Int32)

Reads the portion of data from the underlying span.

Declaration
public ReadOnlySpan<T> Read(int count)
Parameters
Type Name Description
Int32 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
EndOfStreamException

count is greater than RemainingCount.

| Improve this Doc View Source

Read(Span<T>)

Copies elements from the underlying span.

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

The span used to write elements from the underlying span.

Returns
Type Description
Int32

The number of obtained elements.

| Improve this Doc 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.

| Improve this Doc View Source

Reset()

Sets reader position to the first element.

Declaration
public void Reset()
| Improve this Doc 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
Boolean

true if element is obtained successfully; otherwise, false.

| Improve this Doc View Source

TryRead(Int32, 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
Int32 count

The number of elements to read from the underlying span.

ReadOnlySpan<T> result

The segment of the underlying span.

Returns
Type Description
Boolean

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

Exceptions
Type Condition
ArgumentOutOfRangeException

count is negative.

| Improve this Doc View Source

TryRead(Span<T>)

Copies elements from the underlying span.

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

The span used to write elements from the underlying span.

Returns
Type Description
Boolean

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

  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX