Interface: StructFieldOptions
Per-field options, the third element of a StructField entry.
Properties
asPointer?
optionalasPointer?:boolean
For a nested StructDef field: store the address of a buffer of
its own instead of laying the struct out inline, i.e. C's
struct limits *. A null pointer unpacks as null.
condition?
optionalcondition?: () =>boolean
Answered once, when the struct is defined: a field whose condition
returns false is not part of the struct at all, so it neither shows
up in the layout nor shifts the fields after it. This is how a member
only some platforms have is expressed.
Returns
boolean
default?
optionaldefault?:any
Value to pack when the field is absent from the object. Absent means
undefined: null is a value a 'pointer' or 'cstring' field
takes, and is packed as a null address. Wins over optional.
lengthOf?
optionallengthOf?:string
Names the field this one holds the element count of — a
[ elementType ] field, or a 'cstring' field, which pairs into C's
counted string. The count is written by the field it counts, so this
field's own value is never read from the object being packed, and
default, optional, validate and packTransform are rejected on
it.
optional?
optionaloptional?:boolean
When true, an absent field is zeroed instead of throwing — which
unpacks back as 0, false, or null for a pointer or a string.
packTransform?
optionalpackTransform?: (value) =>any
Maps the value the caller gave to the one the field stores.
Parameters
value
any
Returns
any
unpackTransform?
optionalunpackTransform?: (value) =>any
Maps the stored value back on the way out of unpack.
Parameters
value
any
Returns
any
validate?
optionalvalidate?:StructValidator|StructValidator[]
One validator, or a list of them; every one runs.