aion/codec
Typed codecs for values crossing the Aion workflow boundary.
Types
A typed encoder/decoder pair over the string form consumed by the FFI boundary.
Encoders produce the canonical string payload sent to the engine. Decoders
turn that string payload back into the expected Gleam value and report a
typed DecodeError on malformed input or schema mismatch.
pub type Codec(a) {
Codec(
encode: fn(a) -> String,
decode: fn(String) -> Result(a, DecodeError),
)
}
Constructors
-
Codec( encode: fn(a) -> String, decode: fn(String) -> Result(a, DecodeError), )
A typed boundary decode failure.
reason describes the failing expectation and path points at the nested
JSON field or index when the underlying decoder can provide one.
pub type DecodeError {
DecodeError(reason: String, path: List(String))
}
Constructors
-
DecodeError(reason: String, path: List(String))
Values
pub fn json_codec(
encoder: fn(a) -> json.Json,
decoder: decode.Decoder(a),
) -> Codec(a)
Build a Codec from a gleam_json encoder and decoder.
Malformed JSON and decoder mismatches are mapped to DecodeError values;
decode failures are returned as data.