Skip to main content

Module serialisation

Module serialisation 

Source
Expand description

Per-type serialise / deserialise helper generation for workers mode (v0.8 §3.4 / §5.2).

Every Bynk type that crosses a context boundary needs:

  • serialise_<Type>(value): JsonValue — structural lowering.
  • deserialise_<Type>(json): Result<<Type>, BoundaryError> — structural validation + refinement re-validation, then a nominal cast back to the receiving context’s view.

Helpers live in the owning module — commons modules emit helpers for commons types, context modules emit helpers for the types they declare.

Enums§

GenericInst

Functions§

collect_boundary_types
Compute the set of type names (transitively reachable) that need serialise/deserialise helpers for this context: any type used in the argument or return position of a service handler exposed by this context, walked through record fields, sum payloads, and the generic type parameters of Result/Option/Effect.
collect_codec_closure
v0.22b: the codec closure for a set of Json.encode/Json.decode[T] target type-refs — the named types needing per-type helpers (transitively through record fields and sum payloads) plus the generic instantiations needing specialised helpers. The same closure logic as the boundary collectors, rooted at expressions instead of service signatures.
collect_generic_instantiations
Collect the set of Result<A, B> / Option<A> instantiations used in boundary positions so the emitter can synthesise the specialised helpers. v0.18: an instantiation may also appear in the fields of a boundary record or sum payload (e.g. the bynk surface’s Request.contentType: Option[String]) — the per-type serialisers delegate to the specialised generic helpers, so walk those too.
deserialise_expr
v0.22b: an expression-form deserialise call for a codec target. Named types and generic instantiations go through their (module-local) helpers; bases inline the structural check.
emit_generic_helpers
Emit specialised helpers for each Result<A, B> / Option<A> instantiation. They delegate to the named-type serialisers for A and B.
emit_helpers_for_owner
Emit serialise_<T> and deserialise_<T> for every named type the owner declares that crosses a boundary. owner_qualified is the qualified name used as the brand path so that refinement-violation messages identify the origin context.
serialise_expr
v0.22b: an expression-form serialise for a codec target — the same dispatch as a record field’s serialisation.