std/yaml/encoder
std/yaml/src/encoder.trb
YamlEncoder: an Encoder that builds the YAML tree of a value, which the writer then writes.
A value has no identity, so it is written without anchors and aliases. Every string is written so that YAML 1.2 and
YAML 1.1 read it back as the same string: plain where that is safe, in double quotes where a reader would take it for
something else (no, on, 0777, 1_000, 12:30, ~), and as a literal block where it has several lines.
type YamlEncoder
type YamlEncoder with Encoder
An Encoder that builds a YamlNode. A record is a mapping, and a record that announces no field its one value.
field naming
naming: Naming = Naming.Unchanged
How the names of record fields are spelled in the mapping.
field tags
tags: List<YamlTag> = []
The local tags that are written for records and cases whose type they stand for.
field flagNames
flagNames: Bool = false
Whether a Flags is written as the list of its case names and not as its mask (Encoder.flagsAsNames).
fn flagsAsNames
fn flagsAsNames(): Bool
The flagsAsNames option of Yaml.
fn result
fn result(): YamlNode
What was written. The null scalar when nothing was.
fn nothing
var fn nothing()
Writes the plain scalar null.
fn bool
var fn bool(value: Bool)
Writes the plain scalar true or false.
fn int
var fn int(value: Int64)
Writes the decimal digits of the number as a plain scalar.
fn unsigned
var fn unsigned(value: UInt64)
Writes the decimal digits of the count as a plain scalar.
fn float
var fn float(value: Float64)
Writes the number as a plain scalar; infinity and NaN are .inf, -.inf and .nan (see floatText).
fn decimal
var fn decimal(value: Decimal)
Writes the exact digits of the decimal as a plain scalar.
fn string
var fn string(value: String)
Writes the text as a scalar in the style styleOf picks, so that both YAML versions read it back as a text.
fn bytes
var fn bytes(value: Bytes)
Bytes are a !!binary scalar of base64.
fn sequence
var fn sequence(length: Int?)
Opens a sequence; the values written until YamlEncoder.finish are its items. The length is not needed.
fn map
var fn map(length: Int?)
Opens a mapping; the values written until YamlEncoder.finish are its keys and values, alternating.
fn record
var fn record(typeName: String)
Opens a record of the type typeName, a mapping tagged with the type's tag where tags has one.
fn variant
var fn variant(typeName: String, name: String)
Opens the case name of the type typeName; it is written by its tag or by its name, as the type's tags say.
fn field
var fn field(name: String)
Announces the key, spelled by the naming, of the next value written into the open record or case.
fn finish
var fn finish()
Closes the innermost sequence, map, record or case and writes its node into the one around it.