Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy Rebuild with non-progressive lambdas #1011

Open
ev1313 opened this issue Jan 18, 2023 · 2 comments
Open

Lazy Rebuild with non-progressive lambdas #1011

ev1313 opened this issue Jan 18, 2023 · 2 comments

Comments

@ev1313
Copy link

ev1313 commented Jan 18, 2023

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.

@JayFoxRox
Copy link

Probably meant to be closed by #1030

@arekbulski arekbulski changed the title LazyRebuild Lazy Rebuild with non-progressive lambdas Oct 22, 2023
@arekbulski
Copy link
Member

This PR is not going to happen because I dont understand what it does...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants