libero/walker
Types
A custom type discovered by the walker, grouping all its variants.
pub type DiscoveredType {
DiscoveredType(
module_path: String,
type_name: String,
type_params: List(String),
variants: List(DiscoveredVariant),
)
}
Constructors
-
DiscoveredType( module_path: String, type_name: String, type_params: List(String), variants: List(DiscoveredVariant), )
A single discovered variant, used in typed decoder codegen.
pub type DiscoveredVariant {
DiscoveredVariant(
module_path: String,
variant_name: String,
atom_name: String,
float_field_indices: List(Int),
fields: List(FieldType),
)
}
Constructors
-
DiscoveredVariant( module_path: String, variant_name: String, atom_name: String, float_field_indices: List(Int), fields: List(FieldType), )Arguments
- module_path
-
Gleam module path, e.g. “shared/discount”.
- variant_name
-
PascalCase constructor name, e.g. “AdminData”.
- atom_name
-
snake_case atom name, e.g. “admin_data”.
- float_field_indices
-
0-based indices of fields whose Gleam type is Float. Used by the JS ETF encoder to distinguish Int from Float (JS erases this distinction at runtime).
- fields
-
Structured types of each field, in declaration order.
The Gleam type of a single variant field, resolved to a structured form.
pub type FieldType {
UserType(
module_path: String,
type_name: String,
args: List(FieldType),
)
ListOf(element: FieldType)
OptionOf(inner: FieldType)
ResultOf(ok: FieldType, err: FieldType)
DictOf(key: FieldType, value: FieldType)
TupleOf(elements: List(FieldType))
IntField
FloatField
StringField
BoolField
BitArrayField
NilField
TypeVar(name: String)
}
Constructors
Values
pub fn to_snake_case(name: String) -> String
Convert a PascalCase variant name to snake_case for the wire atom.
“AdminData” → “admin_data”, “One” → “one”, “TwoOrMore” → “two_or_more”.
Handles consecutive uppercase: “XMLParser” → “xml_parser”.
Must stay aligned with snakeCase() in rpc_ffi.mjs.
pub fn variant_field_type(
field: glance.VariantField,
) -> glance.Type
Extract the type from a variant field, whether labelled or unlabelled.
pub fn walk_message_registry_types(
message_modules message_modules: List(scanner.MessageModule),
module_files module_files: dict.Dict(String, String),
) -> Result(List(DiscoveredType), List(gen_error.GenError))
Walk the type graph rooted at MsgFromClient/MsgFromServer message types. Seeds the BFS walker from all variants of MsgFromClient and MsgFromServer custom types in each message module, then walks their field types transitively.
Both the MsgFromClient/MsgFromServer types themselves (and their constructors) and all transitively reachable types are included in the discovered list, since they all need codec registration.