This release re-implemented the prepack stage. Before this release, the executing orders for prepack
functions are:
prepack
functions from embedded structures in the base structureprepack
functions of baseprepack
functions from embedded structures in the extended (children) structureprepack
functions of extended (children) structureprepack
functions of named fields (when packing)
After this release, the prepack stage executes on every parts and fields in the structure, strictly following this order:
prepack
stages of named fields and embedded structures from base and extension (children) are executed recursively, in the definition order (or the serialization order)prepack
functions of base are executedprepack
functions of extensions are executed, from base to children
This gives chances to prepack
functions in fields and embedded structures to change the size of some fields without corrupting the calculation of structure size.
For example, s2
defined in the following code
s1 = nstruct(
(nstruct(prepack=p1), 'field1'), # field
(nstruct(
(nstruct(prepack=p2), 'field2'), # embedded field
prepack=p3),), # embedded structure
(nstruct(
(nstruct(prepack=p4), 'field3'), # field of field
prepack=p5), 'field4'), # field
name='s1',
prepack=p6)
s2 = nstruct(
(nstruct(prepack=p7), 'field5'), # field
(nstruct(
(nstruct(prepack=p8), 'field6'), # embedded field
prepack=p9),), # embedded structure
(nstruct(
(nstruct(prepack=p10), 'field7'), # field of field
prepack=p11), 'field8'), # field
name='s2',
base=s1,
criteria=lambda x: True,
prepack=p12)
The old executing order for prepack functions are: p3, p6, p9, p12, p1, p2, p5, p4, p7, p8, p11, p10
The new executing order of prepack functions are: p1, p2, p3, p4, p5, p7, p8, p9, p10, p11, p6, p12
You can use an empty embedded structure with prepack functions to ensure it executes in the desirable order.