Utf8YamlReader Struct

  • Obsolete: Types with embedded references are not supported in this version of your compiler.

A forward-only reader of UTF-8 YAML that records the position of every token and allocates nothing while reading.

[Obsolete("Types with embedded references are not supported in this version of your compiler.", true)]
public ref struct Utf8YamlReader

Remarks

Every byte of the input that is not whitespace, a line break or a comment belongs to a token: the token itself (Utf8YamlReader.TokenStart, Utf8YamlReader.TokenLength), the indicator that precedes it (Utf8YamlReader.IndicatorOffset: -, ?, : or ,), or its properties (Utf8YamlReader.AnchorStart, Utf8YamlReader.TagStart). The gaps between them are the trivia.

Scalars are decoded on demand by Utf8YamlReader.GetString, Utf8YamlReader.CopyValue and Utf8YamlReader.ValueEquals.

Constructors

NameDescription
Utf8YamlReader(ReadOnlySpan<byte>)Initializes a reader over a complete UTF-8 YAML input.
Utf8YamlReader(ReadOnlySpan<byte>, Utf8YamlReaderOptions)Initializes a reader over a complete UTF-8 YAML input.
Utf8YamlReader(ReadOnlySpan<byte>, bool, Utf8YamlReaderState)Initializes a reader over a part of a UTF-8 YAML input.

Utf8YamlReader overloads

Utf8YamlReader(ReadOnlySpan<byte>)

Utf8YamlReader.cs

Initializes a reader over a complete UTF-8 YAML input.

public Utf8YamlReader(ReadOnlySpan<byte> utf8Yaml)
Parameters
utf8Yaml ReadOnlySpan<byte>

Utf8YamlReader(ReadOnlySpan<byte>, Utf8YamlReaderOptions)

Utf8YamlReader.cs

Initializes a reader over a complete UTF-8 YAML input.

public Utf8YamlReader(ReadOnlySpan<byte> utf8Yaml, Utf8YamlReaderOptions options)
Parameters
utf8Yaml ReadOnlySpan<byte>
options Utf8YamlReaderOptions

Utf8YamlReader(ReadOnlySpan<byte>, bool, Utf8YamlReaderState)

Utf8YamlReader.cs

Initializes a reader over a part of a UTF-8 YAML input.

public Utf8YamlReader(ReadOnlySpan<byte> utf8Yaml, bool isFinalBlock, Utf8YamlReaderState state)
Parameters
utf8Yaml ReadOnlySpan<byte>
The bytes not consumed by the previous reader, followed by the new data.
isFinalBlock bool
true when utf8Yaml holds the end of the input.
state Utf8YamlReaderState
The Utf8YamlReader.CurrentState of the previous reader, or a new state for the first block.

Properties

NameDescription
AnchorLengthGets the length of the anchor of the current node, including the &.
AnchorNameGets the name of the anchor of the current node, or of the current alias, without the & or *.
AnchorStartGets the offset of the anchor (&name) of the current node, or -1.
BufferOffsetGets the absolute offset, in the whole input, of the first byte of the current buffer.
BytesConsumedGets the number of bytes of the input that the next reader does not need: the caller can drop them.
CurrentDepthGets the number of collections that contain the current position.
CurrentStateGets the state to pass to the next reader, relative to the input without the first Utf8YamlReader.BytesConsumed bytes.
ExplicitKeyIndicatorOffsetGets the offset of the ? indicator of an explicit key, or -1.
IndicatorOffsetGets the offset of the indicator (-, ?, : or ,) that precedes the current token, or -1.
IsFlowGets a value indicating whether the current collection token belongs to a flow collection.
MaxValueLengthGets the maximum number of bytes Utf8YamlReader.CopyValue writes for the current scalar.
RawValueSpanGets the content of the current scalar as written: without the quotes or the block scalar header, with the escapes and the line breaks.
ScalarStyleGets the style of the current scalar.
TagGets the tag of the current node as written, such as !!str, or an empty span.
TagLengthGets the length of the tag of the current node.
TagStartGets the offset of the tag of the current node, or -1.
TokenFlagsGets the flags of the current token: scalar style, flow collection, implicit document marker.
TokenKindGets the kind of the current token.
TokenLengthGets the length of the current token, 0 for a zero-width token.
TokenSpanGets the bytes of the current token.
TokenStartGets the offset of the first byte of the current token.
ValueIsRawGets a value indicating whether the value of the current scalar is Utf8YamlReader.RawValueSpan unchanged.

AnchorLength

Utf8YamlReader.cs

Gets the length of the anchor of the current node, including the &.

public readonly int AnchorLength { get; }

Property value

int

Gets the name of the anchor of the current node, or of the current alias, without the & or *.

public readonly ReadOnlySpan<byte> AnchorName { get; }

Property value

ReadOnlySpan<byte>

Gets the offset of the anchor (&name) of the current node, or -1.

public readonly int AnchorStart { get; }

Property value

int

BufferOffset

Utf8YamlReader.cs

Gets the absolute offset, in the whole input, of the first byte of the current buffer.

public readonly long BufferOffset { get; }

Property value

long

BytesConsumed

Utf8YamlReader.cs

Gets the number of bytes of the input that the next reader does not need: the caller can drop them.

public readonly int BytesConsumed { get; }

Property value

int

CurrentDepth

Utf8YamlReader.cs

Gets the number of collections that contain the current position.

public readonly int CurrentDepth { get; }

Property value

int

CurrentState

Utf8YamlReader.cs

Gets the state to pass to the next reader, relative to the input without the first Utf8YamlReader.BytesConsumed bytes.

public readonly Utf8YamlReaderState CurrentState { get; }

Property value

Utf8YamlReaderState

ExplicitKeyIndicatorOffset

Utf8YamlReader.cs

Gets the offset of the ? indicator of an explicit key, or -1.

public readonly int ExplicitKeyIndicatorOffset { get; }

Property value

int

IndicatorOffset

Utf8YamlReader.cs

Gets the offset of the indicator (-, ?, : or ,) that precedes the current token, or -1.

public readonly int IndicatorOffset { get; }

Property value

int

Gets a value indicating whether the current collection token belongs to a flow collection.

public readonly bool IsFlow { get; }

Property value

bool

MaxValueLength

Utf8YamlReader.cs

Gets the maximum number of bytes Utf8YamlReader.CopyValue writes for the current scalar.

public readonly int MaxValueLength { get; }

Property value

int

RawValueSpan

Utf8YamlReader.cs

Gets the content of the current scalar as written: without the quotes or the block scalar header, with the escapes and the line breaks.

public readonly ReadOnlySpan<byte> RawValueSpan { get; }

Property value

ReadOnlySpan<byte>

Gets the style of the current scalar.

public readonly ScalarStyle ScalarStyle { get; }

Property value

ScalarStyle

Gets the tag of the current node as written, such as !!str, or an empty span.

public readonly ReadOnlySpan<byte> Tag { get; }

Property value

ReadOnlySpan<byte>

Gets the length of the tag of the current node.

public readonly int TagLength { get; }

Property value

int

Gets the offset of the tag of the current node, or -1.

public readonly int TagStart { get; }

Property value

int

Gets the flags of the current token: scalar style, flow collection, implicit document marker.

public readonly Utf8YamlTokenFlags TokenFlags { get; }

Property value

Utf8YamlTokenFlags

Gets the kind of the current token.

public readonly Utf8YamlTokenKind TokenKind { get; }

Property value

Utf8YamlTokenKind

Gets the length of the current token, 0 for a zero-width token.

public readonly int TokenLength { get; }

Property value

int

Gets the bytes of the current token.

public readonly ReadOnlySpan<byte> TokenSpan { get; }

Property value

ReadOnlySpan<byte>

Gets the offset of the first byte of the current token.

public readonly int TokenStart { get; }

Property value

int

Gets a value indicating whether the value of the current scalar is Utf8YamlReader.RawValueSpan unchanged.

public readonly bool ValueIsRaw { get; }

Property value

bool

Methods

NameDescription
CopyValue(Span<byte>)Writes the UTF-8 value of the current scalar to destination, which must hold at least Utf8YamlReader.MaxValueLength bytes.
GetMark(int)Computes the location of a position of the buffer, like the marks of Parser: UTF-16 index, 0-based line and column.
GetString()Decodes the value of the current scalar.
GetTag()Gets the tag of the current node resolved with the %TAG directives, such as tag:yaml.org,2002:str; ! for the non-specific tag; null without tag.
Read()Reads the next token.
ValueEquals(ReadOnlySpan<byte>)Compares the value of the current scalar with a UTF-8 text without allocating.
ValueEquals(ReadOnlySpan<char>)Compares the value of the current scalar with a text without allocating.
ValueEquals(string)Compares the value of the current scalar with a text without allocating.

CopyValue(Span<byte>)

Utf8YamlReader.cs

Writes the UTF-8 value of the current scalar to destination, which must hold at least Utf8YamlReader.MaxValueLength bytes.

public readonly int CopyValue(Span<byte> destination)

Parameters

destination Span<byte>

Returns

int The number of bytes written.

GetMark(int)

Utf8YamlReader.cs

Computes the location of a position of the buffer, like the marks of Parser: UTF-16 index, 0-based line and column.

public readonly Mark GetMark(int offset)

Parameters

offset int

Returns

Mark

Remarks

This method reads the buffer from its start: it is meant for errors, not for every token.

Decodes the value of the current scalar.

public readonly string GetString()

Returns

string

Gets the tag of the current node resolved with the %TAG directives, such as tag:yaml.org,2002:str; ! for the non-specific tag; null without tag.

public readonly string? GetTag()

Returns

string?

Reads the next token.

public bool Read()

Returns

bool true if a token was read; false at the end of the input.

Exceptions

SyntaxErrorException
The input is not valid YAML.

ValueEquals overloads

ValueEquals(ReadOnlySpan<byte>)

Utf8YamlReader.cs

Compares the value of the current scalar with a UTF-8 text without allocating.

public readonly bool ValueEquals(ReadOnlySpan<byte> utf8Text)
Parameters
utf8Text ReadOnlySpan<byte>
Returns

bool

ValueEquals(ReadOnlySpan<char>)

Utf8YamlReader.cs

Compares the value of the current scalar with a text without allocating.

public readonly bool ValueEquals(ReadOnlySpan<char> text)
Parameters
text ReadOnlySpan<char>
Returns

bool

Remarks

A text with an invalid UTF-16 sequence, such as a lone surrogate, is equal to no value.

ValueEquals(string)

Utf8YamlReader.cs

Compares the value of the current scalar with a text without allocating.

public readonly bool ValueEquals(string text)
Parameters
text string
Returns

bool

Exceptions
ArgumentNullException
text is null.