forked from MostAwesomeDude/construct
-
Notifications
You must be signed in to change notification settings - Fork 165
Closed
Labels
Description
Hi,
currently something like this is not possible:
d = Struct(
"foo" / Int32ul,
"bar" / Rebuild(Int32ul, lambda ctx: ctx.baz),
"baz" / Rebuild(Int32ul, lambda ctx: ctx.foo),You'd need to create custom Padding + Pointer for this behaviour.
The above can probably made possible by modifying Rebuild, Container and ListContainer:
Rebuild will not evaluate the lambda directly, but instead will set the lambda as value in the Container.
When any value is accessed in the Container (in getattr) which is callable, the lambda gets called with the context. Something like this in getattr:
def __getattr__(self, name):
try:
if name in self.__slots__:
ret = object.__getattribute__(self, name)
if callable(ret):
return ret(self)
return ret
else:
ret = self[name]
if callable(ret):
return ret(self)
return ret
except KeyError:
raise AttributeError(name)This would especially be helpful in reconstructing offsets.