Expand description
The value a C# member takes when the stream does not carry it.
Table 9 of DDS-XTypes 1.3, as C#. crate::default_c is the same
table as C, crate::default_java as Java and
crates/wire-probe/src/default.rs as the reflective column; that
module carries the clause quotations and the reasoning for the three
kinds Table 9 does not list. Deliberately a fifth derivation and not
a call into any of them: the columns are compared against each
other, and a shared helper would make them agree about a mistake.
§Why it is a generated method and not a literal
A literal cannot carry an aggregate. “A structure without any of the
optional members and with other members set to their default values”
is a new S() and one assignment per member, and writing that at
every position a member can go missing would put the same answer in
the generated file as many times as the type is reached — where two
copies can differ.
§Why it answers with the value instead of filling one
C’s defaulter is void zd_def_T(T *v): it writes through a pointer.
C# has ref and out and neither is usable at the call sites the
walk produces — a property cannot be passed as either (CS0206), and
a Nullable<T> member is not an out T. So the method returns
Table 9’s value and the caller assigns it, which is the same decision
one step later, and it is what makes the reader’s shape work: every
generated decoder opens with T v = zd_def_T();, so a position the
stream does not carry is already what Table 9 says before a single
octet is read.
§What C# settles that Java could not
Every zero row of Table 9 is spelled by the member’s own width,
because the mapping is one to one — an octet is a byte and an
unsigned long is a uint, where the Java column has to write both
as the next signed type up. What is left is the two rows C# spells
differently from every other column: a float needs its f suffix
because a real literal is a double and there is no implicit
narrowing even for a constant, and an enumeration’s default is a real
enum member rather than an int.
A sequence<T> is a T[] and its “zero-length sequence” is
new T[0] and not a null: null is what an @optional member’s
absence means here, and one value cannot mean both. §7.2.2.4.4.4.7
asks for a zero-length sequence, and §7.2.2.4.4.4.8’s
“Implementations shall not provide a default value” for an
@optional member is the null.
Functions§
- csharp_
defaulters_ called_ by - The defaulters
memberscall, and exactly those. - csharp_
defaulters_ over - Build the defaulter for each of
types, once per name. - default_
into place = zd_def_<T>();- defaulter_
from_ decoder - The defaulter that goes with a decoder, by name.
- defaulter_
name - The defaulter method name for a type.
- member_
default - One member’s default: its
@default, or its type’s.