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