std/yaml/decoder

std/yaml/src/decoder.trb

YamlDecoder: a Decoder over an expanded YAML tree, in which the target type resolves each scalar.

no is the text "no" where a String is read and an error where a Bool is - unless the document says %YAML 1.1, whose truth values yes, no, on and off are. A quoted scalar is always a text, and an explicit tag of the core schema (!!int "5") is honoured.

type YamlDecoder

type YamlDecoder with Decoder

A Decoder over a YAML node whose aliases and merge keys are resolved already. schema is the one of the document's version - Core, or Yaml11 for %YAML 1.1 - and says how null, truth values and numbers are spelled.

field line

protected var line: Int = 0

The line of the node that was taken last: where a failure points.

fn of

static fn of(node: YamlNode, schema: YamlSchema = YamlSchema.Core, naming: Naming = Naming.Unchanged, strict: Bool = false, tags: List<YamlTag> = [], flagsAsNames: Bool = false): Self

A decoder that reads node, with the options of the format.

fn flagsAsNames

fn flagsAsNames(): Bool

The flagsAsNames option of Yaml.

fn nothing

var fn nothing(): Bool

Takes the next node and answers whether it is null; a node that is not null stays to be read.

fn bool

var fn bool(): Result<Bool, DecodeError>

A plain or !!bool scalar the schema spells as a truth value (true, TRUE; yes, on in 1.1).

fn int

var fn int(): Result<Int64, DecodeError>

A whole number of the schema; a float that is exactly whole is accepted, and a value beyond Int64 fails.

fn unsigned

var fn unsigned(): Result<UInt64, DecodeError>

A whole number of the schema that is not negative; a negative one fails as not being a count.

fn float

var fn float(): Result<Float64, DecodeError>

A floating point or whole number of the schema, including .inf, -.inf and .nan.

fn decimal

var fn decimal(): Result<Decimal, DecodeError>

The text of a plain, !!float or !!int scalar read as an exact Decimal, without a detour through a float.

fn string

var fn string(): Result<String, DecodeError>

Any scalar is a text where a text is read: the target type decides.

fn bytes

var fn bytes(): Result<Bytes, DecodeError>

A !!binary scalar or a base64 text, or a sequence of numbers that each fit into a byte.

fn sequence

var fn sequence(): Result<Int?, DecodeError>

A sequence, the keys of a !!set, the bytes of a !!binary scalar as a sequence of numbers - which is what a Bytes reads - or nothing at all, which is an empty sequence.

fn map

var fn map(): Result<Int?, DecodeError>

A mapping, or nothing at all, which is an empty map. Its keys are nodes, read as the key type asks.

fn hasNext

var fn hasNext(): Result<Bool, DecodeError>

Whether the innermost open sequence or map has an item left; false when nothing is open.

fn record

var fn record(typeName: String): Result<Void, DecodeError>

A mapping's entries are the record's fields. Nothing at all is a record of defaults, and any other node a wrapper: the one value the record holds. A local tag has to stand for this type.

fn variant

var fn variant(typeName: String): Result<String, DecodeError>

A case: a local tag that tags names for one (!circle \{radius: 2\}), a plain scalar that is the case's name, or a mapping of one entry whose key is the name and whose value holds the fields (Circle: \{radius: 2\}).

fn field

var fn field(name: String): Result<Bool, DecodeError>

Selects the entry named name (spelled by the naming) of the open record as the next value; false if absent.

fn finish

var fn finish(): Result<Void, DecodeError>

Closes the innermost sequence, map, record or case; in strict mode a field of the document nothing read fails.