Skip to main content

Module default_zig

Module default_zig 

Source
Expand description

The value a Zig member takes when the stream does not carry it.

Table 9 of DDS-XTypes 1.3, as Zig — deliberately a further derivation and not a call into any sibling’s, because the columns are compared against each other and a shared helper would make them agree about a mistake.

§The shape is the D column’s, with two Zig differences

A defaulter returns Table 9’s value and the caller assigns it; emit/zig.rs’s decoder opens with var v: T = try zd_def_T(r.heap);.

An aggregate’s body is one struct literal, not a declaration and assignments: Zig has no default-initialised T v; — a local is either fully written or undefined — so the literal is where every member’s value is stated. An @optional member is left out of it: the field carries = null in the type declaration, and absence is §7.2.2.4.4.4.8’s default state. A union’s unselected branches take undefined: no read reaches one — the encoder writes the selected branch, the dumper prints it — and a defaulter call there would recurse forever on a self-referential @external branch.

A defaulter takes an allocator. A non-optional @external member is Table 9’s value behind the column’s indirection — try zdwire.zdPtr(zd_al, try zd_def_T(zd_al)) — and Zig has no garbage collector to hide the allocation behind. The decoder hands its reader’s arena; a defaulter for a type with no such member simply discards the parameter.

Functions§

defaulter_from_decoder
The defaulter that goes with a decoder, by name.
defaulter_name
The defaulter function name for a type, keyed the way the decoder is: by the IDL kind for a primitive and by the codec tag for everything else.
member_default
One member’s default — its @default, or its type’s — assigned into place. §7.2.2.4.4.4.9 puts the explicit one first. An @external member’s value goes through zdwire.zdPtr with alloc; an @optional one takes the bare value, which Zig coerces into the ?T on its own.
zig_defaulters_called_by
The defaulters decls call, and exactly those — read off the emitted calls rather than derived a second time from the model.
zig_defaulters_over
Build the defaulter for each of types, once per name.