libero/etf/codegen_erl

Codegen for the per-consumer wire-transformers Erlang module.

Emits one Erlang module per consumer (e.g. <consumer>_wire.erl) containing per-type encode_<type>/1 and decode_<type>/1 functions. These translate between BEAM-shape (bare atom tags from Gleam constructors) and wire-shape (hashed atoms from wire_identity.wire_hash).

The wire identity for each variant is the SHA-256-based hash from wire_identity.wire_identity, computed at codegen time and baked into the generated tuple tag. The runtime carries no global lookup tables for type identity.

Function names use walker.qualified_atom_name so that two modules with same-named types produce distinct transformer functions in the same Erlang module. The wire atom on the generated tuple is the 10-char hash; the function name is the codegen-internal symbol used for cross-type recursion.

Types

A page tag → type atom mapping used to generate encode_push/2. page_tag is the binary string the runtime uses to identify the page (e.g. “Home”), type_atom is the qualified atom name of the per-type encoder (e.g. “pages_home__to_client”).

pub type PushDispatch {
  PushDispatch(page_tag: String, type_atom: String)
}

Constructors

  • PushDispatch(page_tag: String, type_atom: String)

Values

pub fn generate(
  module_name module_name: String,
  discovered discovered: List(walker.DiscoveredType),
  endpoints endpoints: List(scanner.HandlerEndpoint),
  push_dispatches push_dispatches: List(PushDispatch),
) -> Result(String, gen_error.GenError)

Generate the source of a <consumer>_wire.erl module containing per-type encode/decode parent transformers for every discovered user type.

Returns Error(GenError) on the first wire-safety violation found (unsupported Dict key, unresolved TypeVar) or hash collision. The emitter assumes its inputs are wire-safe; rejecting up-front keeps the output codegen logic narrow and free of runtime fallbacks.

Search Document