Show / Hide Table of Contents

Struct SequenceReader

Represents binary reader for the sequence of bytes.

Implements
IAsyncBinaryReader
IResettable
Inherited Members
ValueType.Equals(object)
ValueType.GetHashCode()
object.Equals(object, object)
object.GetType()
object.ReferenceEquals(object, object)
Namespace: DotNext.IO
Assembly: DotNext.IO.dll
Syntax
public struct SequenceReader : IAsyncBinaryReader, IResettable
Remarks

Initializes a new sequence reader.

Constructors

| Edit this page View Source

SequenceReader(ReadOnlySequence<byte>)

Represents binary reader for the sequence of bytes.

Declaration
public SequenceReader(ReadOnlySequence<byte> sequence)
Parameters
Type Name Description
ReadOnlySequence<byte> sequence

A sequence of elements.

Remarks

Initializes a new sequence reader.

See Also
Create(ReadOnlySequence<byte>)
Create(ReadOnlyMemory<byte>)

Properties

| Edit this page View Source

IsEmpty

Indicates that the current reader has no more data to read.

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

Position

Gets position in the underlying sequence.

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

RemainingSequence

Gets unread part of the sequence.

Declaration
public readonly ReadOnlySequence<byte> RemainingSequence { get; }
Property Value
Type Description
ReadOnlySequence<byte>

Methods

| Edit this page View Source

Decode(in DecodingContext, LengthFormat, MemoryAllocator<char>?)

Decodes a block of characters.

Declaration
public MemoryOwner<char> Decode(in DecodingContext context, LengthFormat lengthFormat, MemoryAllocator<char>? allocator = null)
Parameters
Type Name Description
DecodingContext context

The decoding context containing string characters encoding.

LengthFormat lengthFormat

The format of the string length encoded in the stream.

MemoryAllocator<char> allocator

The allocator of the buffer of characters.

Returns
Type Description
MemoryOwner<char>

The buffer of characters.

Exceptions
Type Condition
EndOfStreamException

The underlying source doesn't contain necessary amount of bytes to decode the value.

| Edit this page View Source

Decode(in DecodingContext, LengthFormat, Memory<char>)

Decodes the sequence of characters.

Declaration
public SequenceReader.DecodingEnumerable Decode(in DecodingContext context, LengthFormat lengthFormat, Memory<char> buffer)
Parameters
Type Name Description
DecodingContext context

The decoding context containing string characters encoding.

LengthFormat lengthFormat

The format of the string length encoded in the stream.

Memory<char> buffer

The buffer of characters.

Returns
Type Description
SequenceReader.DecodingEnumerable

The enumerator of characters.

Exceptions
Type Condition
EndOfStreamException

The underlying source doesn't contain necessary amount of bytes to decode the value.

ArgumentOutOfRangeException

lengthFormat is invalid.

| Edit this page View Source

Decode(in DecodingContext, LengthFormat, Span<char>)

Decodes the sequence of characters.

Declaration
public SequenceReader.SpanDecodingEnumerable Decode(in DecodingContext context, LengthFormat lengthFormat, Span<char> buffer)
Parameters
Type Name Description
DecodingContext context

The decoding context containing string characters encoding.

LengthFormat lengthFormat

The format of the string length encoded in the stream.

Span<char> buffer

The buffer of characters.

Returns
Type Description
SequenceReader.SpanDecodingEnumerable

The enumerator of characters.

Exceptions
Type Condition
EndOfStreamException

The underlying source doesn't contain necessary amount of bytes to decode the value.

ArgumentOutOfRangeException

lengthFormat is invalid.

| Edit this page View Source

Parse<T>(LengthFormat, NumberStyles, IFormatProvider?)

Parses the numeric value from UTF-8 encoded characters.

Declaration
public T Parse<T>(LengthFormat lengthFormat, NumberStyles style, IFormatProvider? provider = null) where T : INumberBase<T>
Parameters
Type Name Description
LengthFormat lengthFormat

The format of the string length (in bytes) encoded in the stream.

NumberStyles style

A combination of number styles.

IFormatProvider provider

Culture-specific formatting information.

Returns
Type Description
T

The result of parsing.

Type Parameters
Name Description
T

The numeric type.

Exceptions
Type Condition
EndOfStreamException

The underlying source doesn't contain necessary amount of bytes to decode the value.

ArgumentOutOfRangeException

lengthFormat is invalid.

| Edit this page View Source

Parse<T>(LengthFormat, IFormatProvider?)

Parses the sequence of characters encoded as UTF-8.

Declaration
public T Parse<T>(LengthFormat lengthFormat, IFormatProvider? provider = null) where T : IUtf8SpanParsable<T>
Parameters
Type Name Description
LengthFormat lengthFormat

The format of the string length (in bytes) encoded in the stream.

IFormatProvider provider

Culture-specific formatting information.

Returns
Type Description
T

The result of parsing.

Type Parameters
Name Description
T

The type that supports parsing from UTF-8.

Exceptions
Type Condition
EndOfStreamException

The underlying source doesn't contain necessary amount of bytes to decode the value.

ArgumentOutOfRangeException

lengthFormat is invalid.

| Edit this page View Source

Parse<T>(in DecodingContext, LengthFormat, NumberStyles, IFormatProvider?, MemoryAllocator<char>?)

Parses the numeric value.

Declaration
public T Parse<T>(in DecodingContext context, LengthFormat lengthFormat, NumberStyles style, IFormatProvider? provider = null, MemoryAllocator<char>? allocator = null) where T : INumberBase<T>
Parameters
Type Name Description
DecodingContext context

The decoding context containing string characters encoding.

LengthFormat lengthFormat

The format of the string length (in bytes) encoded in the stream.

NumberStyles style

A combination of number styles.

IFormatProvider provider

Culture-specific formatting information.

MemoryAllocator<char> allocator

The allocator of internal buffer.

Returns
Type Description
T

The result of parsing.

Type Parameters
Name Description
T

The numeric type.

Exceptions
Type Condition
EndOfStreamException

The underlying source doesn't contain necessary amount of bytes to decode the value.

ArgumentOutOfRangeException

lengthFormat is invalid.

| Edit this page View Source

Parse<TArg, TResult>(TArg, ReadOnlySpanFunc<char, TArg, TResult>, in DecodingContext, LengthFormat, MemoryAllocator<char>?)

Parses a block of characters.

Declaration
public TResult Parse<TArg, TResult>(TArg arg, ReadOnlySpanFunc<char, TArg, TResult> parser, in DecodingContext context, LengthFormat lengthFormat, MemoryAllocator<char>? allocator = null)
Parameters
Type Name Description
TArg arg

The argument to be passed to parser.

ReadOnlySpanFunc<char, TArg, TResult> parser

The parser.

DecodingContext context

The decoding context containing string characters encoding.

LengthFormat lengthFormat

The format of the string length encoded in the stream.

MemoryAllocator<char> allocator

The allocator of the buffer of characters.

Returns
Type Description
TResult

The parsed block of characters.

Type Parameters
Name Description
TArg

The type of the argument to be passed to parser.

TResult

The type of the parsing result.

Exceptions
Type Condition
ArgumentNullException

parser is null.

EndOfStreamException

The underlying source doesn't contain necessary amount of bytes to decode the value.

| Edit this page View Source

Read(long)

Reads the specified number of bytes.

Declaration
public ReadOnlySequence<byte> Read(long count)
Parameters
Type Name Description
long count

The number of bytes to read.

Returns
Type Description
ReadOnlySequence<byte>

The buffer of length count.

Exceptions
Type Condition
EndOfStreamException

count is larger than the available buffer to read.

| Edit this page View Source

Read(Span<byte>)

Copies the bytes from the sequence into contiguous block of memory.

Declaration
public void Read(Span<byte> output)
Parameters
Type Name Description
Span<byte> output

The block of memory to fill.

Exceptions
Type Condition
EndOfStreamException

Unexpected end of sequence.

| Edit this page View Source

ReadBigEndian<T>()

Reads integer encoded in big-endian format.

Declaration
public T ReadBigEndian<T>() where T : IBinaryInteger<T>
Returns
Type Description
T

The integer value.

Type Parameters
Name Description
T

The integer type.

Exceptions
Type Condition
EndOfStreamException

The underlying source doesn't contain necessary amount of bytes to decode the value.

| Edit this page View Source

ReadBlock(LengthFormat)

Reads length-prefixed block of bytes.

Declaration
public ReadOnlySequence<byte> ReadBlock(LengthFormat lengthFormat)
Parameters
Type Name Description
LengthFormat lengthFormat

The format of the block length encoded in the underlying stream.

Returns
Type Description
ReadOnlySequence<byte>

The decoded block of bytes.

Exceptions
Type Condition
EndOfStreamException

Unexpected end of sequence.

| Edit this page View Source

ReadBlock(LengthFormat, MemoryAllocator<byte>?)

Reads length-prefixed block of bytes.

Declaration
public MemoryOwner<byte> ReadBlock(LengthFormat lengthFormat, MemoryAllocator<byte>? allocator)
Parameters
Type Name Description
LengthFormat lengthFormat

The format of the block length encoded in the underlying stream.

MemoryAllocator<byte> allocator

The memory allocator used to place the decoded block of bytes.

Returns
Type Description
MemoryOwner<byte>

The decoded block of bytes.

Exceptions
Type Condition
EndOfStreamException

Unexpected end of sequence.

| Edit this page View Source

ReadByte()

Reads single byte.

Declaration
public byte ReadByte()
Returns
Type Description
byte

A byte.

Exceptions
Type Condition
EndOfStreamException

Unexpected end of sequence.

| Edit this page View Source

ReadLittleEndian<T>()

Reads integer encoded in little-endian format.

Declaration
public T ReadLittleEndian<T>() where T : IBinaryInteger<T>
Returns
Type Description
T

The integer value.

Type Parameters
Name Description
T

The integer type.

Exceptions
Type Condition
EndOfStreamException

The underlying source doesn't contain necessary amount of bytes to decode the value.

| Edit this page View Source

ReadToEnd()

Gets unread part of the buffer and advances the current reader to the end of the buffer.

Declaration
public ReadOnlySequence<byte> ReadToEnd()
Returns
Type Description
ReadOnlySequence<byte>

Unread part of the buffer.

| Edit this page View Source

Read<T>()

Parses the value encoded as a sequence of bytes.

Declaration
public T Read<T>() where T : IBinaryFormattable<T>
Returns
Type Description
T

The parsed value.

Type Parameters
Name Description
T

The type of the result.

| Edit this page View Source

Reset()

Resets the reader so it can be used again.

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

Skip(long)

Skips the specified number of bytes.

Declaration
public void Skip(long length)
Parameters
Type Name Description
long length

The number of bytes to skip.

Exceptions
Type Condition
ArgumentOutOfRangeException

length is less than zero.

EndOfStreamException

Unexpected end of sequence.

| Edit this page View Source

ToString()

Returns the fully qualified type name of this instance.

Declaration
public override readonly string ToString()
Returns
Type Description
string

The fully qualified type name.

Overrides
ValueType.ToString()
| Edit this page View Source

TryRead(int, out ReadOnlyMemory<byte>)

Tries to read the next chunk.

Declaration
public bool TryRead(int maxLength, out ReadOnlyMemory<byte> chunk)
Parameters
Type Name Description
int maxLength

The maximum length of the requested chunk.

ReadOnlyMemory<byte> chunk

The chunk of bytes. Its length is less than or equal to maxLength.

Returns
Type Description
bool

true if next chunk is obtained successfully; false if the end of the stream reached.

| Edit this page View Source

TryRead(out ReadOnlyMemory<byte>)

Tries to read the next chunk.

Declaration
public bool TryRead(out ReadOnlyMemory<byte> chunk)
Parameters
Type Name Description
ReadOnlyMemory<byte> chunk

The chunk of bytes.

Returns
Type Description
bool

true if the next chunk is obtained successfully; false if the end of the stream reached.

Implements

IAsyncBinaryReader
IResettable

Extension Methods

BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, ReadOnlySpan<T>)
Collection.ToAsyncEnumerator<TEnumerator, T>(TEnumerator, CancellationToken)
Collection.ToClassicEnumerator<TEnumerator, T>(TEnumerator)
Enumerator.Skip<TEnumerator, T>(ref TEnumerator, int)
ExpressionBuilder.Const<T>(T)
EndPointFormatter.ReadEndPoint(ref SequenceReader)

See Also

Create(ReadOnlySequence<byte>)
Create(ReadOnlyMemory<byte>)
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾