Lyricdev
GitHub

interface Encoder

pub interface Encoder

The writing side of a format: the scalars, and the containers as begin/end around their parts. The sequence of calls a conformance makes is the contract: beginSeq(n), then n values, then endSeq(); beginMap(n), then n times beginKey(), a key and a value, then endMap(); beginStruct(name, n), then n times beginField(name) and a value, then endStruct(); beginVariant(…, hasPayload), then the payload where there is one, then endVariant(). A format that cannot hold a form throws EncodeError, with path() as its place.

Methods

mut fn encodeNull(): void throws EncodeError
mut fn encodeBool(v: bool): void throws EncodeError
mut fn encodeInt(v: int): void throws EncodeError
mut fn encodeUint(v: uint): void throws EncodeError
mut fn encodeFloat(v: float): void throws EncodeError
mut fn encodeString(v: string): void throws EncodeError
mut fn encodeBytes(v: Slice<uint8>): void throws EncodeError
mut fn beginSeq(count: int): void throws EncodeError
mut fn endSeq(): void throws EncodeError
mut fn beginMap(count: int): void throws EncodeError
mut fn beginKey(): void throws EncodeError
mut fn endMap(): void throws EncodeError
mut fn beginStruct(name: string, count: int): void throws EncodeError
mut fn beginField(name: string): void throws EncodeError
mut fn endStruct(): void throws EncodeError
mut fn beginVariant(
    enumName: string,
    variant: string,
    index: int,
    hasPayload: bool
): void throws EncodeError
mut fn endVariant(): void throws EncodeError
fn path(): string

Returns where the encoder stands, for an error: "" at the root.