construct
construct copied to clipboard
Anchor requires key presence in container
When building a Struct which contains an Anchor, not providing the anchor's label as a key in the Container instance yields an AttributeError.
#!/usr/bin/python2
from construct import *
struct = Struct(None, Anchor('foo_anchor'))
struct.build(Container())
Running the testcase yields: AttributeError: 'Container' object has no attribute 'foo_anchor'
As an anchor's value is solely determined by it's position in the construct, it shouldn't have to be specified in the Container?
Same thing happens with ConstAdapter
and related macros.
There probably should be a flag that informs Struct
to pass None
if the field is not present.
This flag would also make it possible to create constructs that have a default build value and computed build value.
Hm. I haven't messed with Anchor much, but I'll look into this.