Lyricdev
GitHub

interface Decoder

pub interface Decoder

The reading side of a format, pull-based: a conformance asks for the form it expects, and the format answers it or throws TypeMismatch. The containers: beginSeq() answers the count where the format knows it, seqHasNext() whether an element follows — which is how a format that does not know the count ends a sequence —; beginMap()/mapHasNext() the same, a key and a value read in turn; beginStruct(name, fields) positions on a struct, structField(name) on one of its fields — false where the data has none —, endStruct(denyUnknown) leaves it and, where asked, refuses a field the data has and the type has not; beginVariant(enum, variants) answers the index of the variant the data holds (or throws UnknownVariant), variantHasPayload() whether one follows. A format without names in its data (one that reads structs in field order) answers structField by position. A read that mismatches leaves the value where it was: the next ask sees it again, which is how Value reads whatever comes.

Methods

mut fn isNull(): bool throws DecodeError

Returns whether the next value is null, without taking it.

mut fn decodeNull(): void throws DecodeError
mut fn decodeBool(): bool throws DecodeError
mut fn decodeInt(): int throws DecodeError
mut fn decodeUint(): uint throws DecodeError
mut fn decodeFloat(): float throws DecodeError
mut fn decodeString(): string throws DecodeError
mut fn decodeBytes(): uint8[] throws DecodeError
mut fn beginSeq(): ?int throws DecodeError
fn seqHasNext(): bool throws DecodeError
mut fn endSeq(): void throws DecodeError
mut fn beginMap(): ?int throws DecodeError
fn mapHasNext(): bool throws DecodeError
mut fn endMap(): void throws DecodeError
mut fn beginStruct(name: string, fields: string[]): void throws DecodeError
mut fn structField(name: string): bool throws DecodeError
mut fn endStruct(denyUnknown: bool): void throws DecodeError
mut fn beginVariant(enumName: string, variants: string[]): int throws DecodeError
fn variantHasPayload(): bool throws DecodeError
mut fn endVariant(): void throws DecodeError
fn path(): string

Returns where the decoder stands, for an error: "" at the root, users[0].mail below.