Protocol for encoding Elixir values to wire-safe representations.
This protocol is called during Tree.normalize/1, the single value
encoding pass that converts raw Elixir values into wire-compatible
forms. Widget builders (Build.put_if/3) do NOT call this protocol --
values stay as raw Elixir terms (atoms, tuples, structs) until
normalization.
Key stringification (atom keys to string keys) is NOT handled here.
That happens at the wire boundary in Protocol.Encode.stringify_keys/1,
which runs just before serialization.
Widget authors should implement this protocol for custom value types that need special wire encoding (e.g. a struct that should become a specific map shape on the wire).
Primitive implementations
- Atom:
true/false/nilpass through; other atoms become strings - BitString: pass through
- Integer: pass through
- Float: pass through
- Tuple: converted to list with recursive encoding
- Map: values recursively encoded
- List: elements recursively encoded
- Any: raises
Protocol.UndefinedError(no silent passthrough)
Struct implementations
Struct implementations live alongside their struct definitions:
Plushie.Type.A11y-- strips nil fields, converts atom keys to stringsPlushie.Type.Border-- encodes per-corner radius to string-keyed mapPlushie.Type.Shadow-- encodes offset as[x, y]listPlushie.Type.Font-- encodes struct to wire font map (strips nils)Plushie.Type.Padding-- encodes struct to per-side map (strips nils)Plushie.Type.StyleMap-- encodes status overrides and nested structs
Summary
Functions
Encodes a value for JSON wire format.
Types
@type t() :: term()
All the types that implement this protocol.