Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Lazy Rebuild with non-progressive lambdas #1011

Copy link
Copy link
@ev1313

Description

@ev1313
Issue body actions

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.