Expand description
The value a TypeScript member takes when the stream does not carry it.
Table 9 of DDS-XTypes 1.3, as TypeScript. crate::default_c is the
same table as C, crate::default_java as Java, crate::default_cpp
as C++, and crates/wire-probe/src/default.rs is the reflective
column’s; 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 function 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 newS() 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. One function per type is one answer per type,
which is what the C and Java columns do and for the same reason.
§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.
TypeScript has no pointer and no out-parameter, and half of Table 9’s
rows are values a callee cannot mutate at all — a number, a
string, an array whose length has to change. So the function
returns Table 9’s value and the caller assigns it, which is the
same decision one step later. It is also what makes the reader’s own
shape work: every generated decoder opens with
let v: T = zd_def_T();, so a position the stream does not carry is
already what Table 9 says before a single octet is read.
§What TypeScript forces that Java does not
Nothing is constructed at all. The materialiser emits no
TypeScript class for an IDL data type — DDS-TS 1.0 §7.4 forbids one —
so there is no new anywhere in this column. A union’s defaulter
answers with an object literal, because the materialiser declares a
union as a type over object types and a type is erased; every
other aggregate has a factory function beside its interface, and it
is that function the defaulter calls:
crate::adapter::typescript::factory_path names it.
An absent @optional member is a missing property and not a
null. §7.2.2.4.4.4.8’s “Implementations shall not provide a default
value” is delete v.field here, and delete rather than
v.field = undefined because the materialiser declares the field
field?: T: under exactOptionalPropertyTypes — which
runtime/typescript/tsconfig.json sets — assigning undefined to
such a field is a tsc error, while deleting it is the operation the
declaration was written for.
A fixed<P,S> is a decimal string. Table 9’s zero for it is the
one spelling crates/wire-probe/src/canonical.rs accepts for that
scale — "0.00" for a fixed<5,2> — and not the empty string, which
is not a decimal at all.
Functions§
- case_
label a.b.Tag.TAG_A— the constant a union case label of an enumeration discriminator is compared against.- default_
into place = zd_def_<T>();- defaulter_
from_ decoder - The defaulter that goes with a decoder, by name.
- defaulter_
name - The defaulter function name for a type.
- enumerator_
constant a.b.Enum.LITERAL— theas constobject the materialiser declared, written from the file root.- explicit_
default - An explicit
@defaultas a TypeScript expression fortype_. - member_
default - One member’s default: its
@default, or its type’s. - typescript_
defaulters_ called_ by - The defaulters
declscall, and exactly those. - typescript_
defaulters_ over - Build the defaulter for each of
types, once per name.