Module std::encoding::wire

Shared types of the data codecs, and the #[wire] schema layer.

The format modules encode and decode: std.encoding.json, yaml, toml, msgpack and cbor each offer encode(value) and decode<T>(document) over any data type. A decode that fails returns this module's DecodeError, which names the path of the value that failed:

import std.encoding.json;

type Config { name: string; retries: i64; }

fn main() {
    println(json.encode(Config { name: "api", retries: 3 }));   // {"name":"api","retries":3}
    match json.decode<Config>("{\"name\":\"api\",\"retries\":\"x\"}") {
        .Ok(config) => println(config.name),
        .Err(e) => println(e),     // Type: .retries: expected integer, found string
    }
}

#[wire] on a record or enum gives it a stable schema for remote actors: every field and variant carries a @N tag, assigned once and never reused. A required Option<T> always emits its key and encodes None as null; only Option<T> @N optional may omit the key for None. Check schema compatibility between two versions with hew wire check <file.hew> --against <baseline.hew>. See the #[wire] section of docs/hew-language-guide.md.

Contents

Types

Enum DecodeError

Why a document did not decode as the requested type. Paths start at the document root: .field, [index], ["key"].

Variants

Syntax { offset: i64, line: Option<i64>, column: Option<i64>, reason: string }

The input is not well-formed in its format. Text formats fill line and column; binary formats leave them None.

Type { path: string, expected: string, found: string }

A value has the wrong kind for its target.

Missing { path: string }

A required key is absent.

Range { path: string, value: string, target: string }

A number does not fit its target type.

UnknownVariant { path: string, name: string }

A variant name or tag matches no variant.

Duplicate { path: string, key: string }

A map key or set element repeats.

Invalid { path: string, reason: string }

A representation override refused its representation.