Struct SequenceReader
Represents binary reader for the sequence of bytes.
Inherited Members
Namespace: DotNext.IO
Assembly: DotNext.IO.dll
Syntax
public struct SequenceReader : IAsyncBinaryReader, IResettable
Remarks
Initializes a new sequence reader.
Constructors
| Edit this page View SourceSequenceReader(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
Properties
| Edit this page View SourceIsEmpty
Indicates that the current reader has no more data to read.
Declaration
public readonly bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Position
Gets position in the underlying sequence.
Declaration
public readonly SequencePosition Position { get; }
Property Value
| Type | Description |
|---|---|
| SequencePosition |
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 SourceDecode(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. |
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
| 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 |
| TResult | The type of the parsing result. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| EndOfStreamException | The underlying source doesn't contain necessary amount of bytes to decode the value. |
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 |
Exceptions
| Type | Condition |
|---|---|
| EndOfStreamException |
|
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. |
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. |
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. |
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. |
ReadByte()
Reads single byte.
Declaration
public byte ReadByte()
Returns
| Type | Description |
|---|---|
| byte | A byte. |
Exceptions
| Type | Condition |
|---|---|
| EndOfStreamException | Unexpected end of sequence. |
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. |
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. |
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. |
Reset()
Resets the reader so it can be used again.
Declaration
public void Reset()
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 |
|
| EndOfStreamException | Unexpected end of sequence. |
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
| Edit this page View SourceTryRead(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 |
Returns
| Type | Description |
|---|---|
| bool | true if next chunk is obtained successfully; false if the end of the stream reached. |
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. |