Struct SpanReader<T>
Represents simple memory reader backed by ReadOnlySpan<T>.
Inherited Members
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 SourceSpanReader(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. |
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 |
|
Properties
| Edit this page View SourceConsumedCount
Gets the number of consumed elements.
Declaration
public int ConsumedCount { readonly get; set; }
Property Value
Type | Description |
---|---|
int |
ConsumedSpan
Gets the span over consumed elements.
Declaration
public readonly ReadOnlySpan<T> ConsumedSpan { get; }
Property Value
Type | Description |
---|---|
ReadOnlySpan<T> |
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. |
RemainingCount
Gets the number of unread elements.
Declaration
public readonly int RemainingCount { get; }
Property Value
Type | Description |
---|---|
int |
RemainingSpan
Gets the remaining part of the span.
Declaration
public readonly ReadOnlySpan<T> RemainingSpan { get; }
Property Value
Type | Description |
---|---|
ReadOnlySpan<T> |
Span
Gets underlying span.
Declaration
public readonly ReadOnlySpan<T> Span { get; }
Property Value
Type | Description |
---|---|
ReadOnlySpan<T> |
Methods
| Edit this page View SourceAdvance(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 |
|
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. |
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 |
|
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. |
ReadToEnd()
Reads the rest of the memory block.
Declaration
public ReadOnlySpan<T> ReadToEnd()
Returns
Type | Description |
---|---|
ReadOnlySpan<T> | The rest of the memory block. |
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 |
|
InternalBufferOverflowException |
|
Reset()
Sets reader position to the first element.
Declaration
public void Reset()
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 |
|
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 SourceTryRead(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 |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
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 |
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 |
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 |
|