Skip to content
This repository was archived by the owner on Sep 1, 2021. It is now read-only.
This repository was archived by the owner on Sep 1, 2021. It is now read-only.

MetaFiled requires length attribute to be present on build #18

@ruletko

Description

@ruletko

This is more like a question rather an issue. I'd expect MEtaField's related length fiekd to be autopopulated on building a structure, however this does not happen:

>>> from construct import *
>>> foo = Struct("foo",
... Byte("length"),
... MetaField("data", lambda ctx: ctx["length"])
... )

>>> foo.build(Container(data="test"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/pymodules/python2.6/construct/core.py", line 206, in build
    self.build_stream(obj, stream)
  File "/usr/lib/pymodules/python2.6/construct/core.py", line 214, in build_stream
    self._build(obj, stream, Container())
  File "/usr/lib/pymodules/python2.6/construct/core.py", line 662, in _build
    subobj = getattr(obj, sc.name)
AttributeError: 'Container' object has no attribute 'length'

Could you explain correct behavior?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions