DependentStructDecoderBuilder
A fluent builder that accumulates field decoders for a struct whose later fields may depend on the values of earlier ones.
Each call to `field` returns a new builder whose accumulated field type is widened by the newly added field. Call `build` to obtain the final Decoder once every field has been declared.
The builder tracks at the type level whether the struct decoded so far has a fixed size. Adding a FixedSizeDecoder preserves that property, while adding a VariableSizeDecoder or a field factory drops the builder to variable size and it stays variable thereafter.
Instances of this type are immutable. Calling field does not mutate the
receiver; it returns a new builder.
See
Type Parameters
| Type Parameter | Description |
|---|---|
TFields extends Record<string, unknown> | The shape of the struct that has been accumulated so far. |
TIsFixedSize extends boolean | true while every field added so far is a FixedSizeDecoder, false once any variable size decoder or factory has been added. |
Methods
build()
Finalizes the builder and returns a Decoder that decodes each declared field in turn, in the order they were added.
Returns a FixedSizeDecoder when every field has been added with a fixed size decoder, and a VariableSizeDecoder otherwise.
Returns
TIsFixedSize extends true ? FixedSizeDecoder<DrainOuterGeneric<TFields>> : VariableSizeDecoder<DrainOuterGeneric<TFields>>
field()
Call Signature
Adds a field decoded by a VariableSizeDecoder. Drops the builder to variable size; subsequent field calls cannot raise it back to fixed size.
Adding a field that has already been declared on this builder is a compile time error.
Type Parameters
| Type Parameter |
|---|
TName extends string |
TValue |
Parameters
| Parameter | Type |
|---|---|
name | TName extends keyof TFields ? never : TName |
decoder | VariableSizeDecoder<TValue> |
Returns
DependentStructDecoderBuilder<DrainOuterGeneric<TFields & { [K in string]: TValue }>, false>
Call Signature
Adds a field whose decoder is built from a frozen snapshot of the fields that precede it. Drops the builder to variable size since the byte length of the produced decoder cannot be known at type time.
Adding a field that has already been declared on this builder is a compile time error.
Type Parameters
| Type Parameter |
|---|
TName extends string |
TValue |
Parameters
| Parameter | Type |
|---|---|
name | TName extends keyof TFields ? never : TName |
factory | DependentStructDecoderFieldFactory<TFields, TValue> |
Returns
DependentStructDecoderBuilder<DrainOuterGeneric<TFields & { [K in string]: TValue }>, false>
Call Signature
Adds a field decoded by a FixedSizeDecoder. Preserves the fixed size property of the builder.
Adding a field that has already been declared on this builder is a compile time error.
Type Parameters
| Type Parameter |
|---|
TName extends string |
TValue |
Parameters
| Parameter | Type |
|---|---|
name | TName extends keyof TFields ? never : TName |
decoder | FixedSizeDecoder<TValue> |
Returns
DependentStructDecoderBuilder<DrainOuterGeneric<TFields & { [K in string]: TValue }>, TIsFixedSize>