Core API: Special

construct.Embedded(subcon)

Special wrapper that allows outer multiple-subcons construct to merge fields from another multiple-subcons construct. Embedded does not change a field, only wraps it like a candy with a flag.

Warning

Can only be used between Struct Sequence FocusedSeq Union LazyStruct, although they can be used interchangably, for example Struct can embed fields from a Sequence. There is also EmbeddedSwitch macro that pseudo-embeds a Switch. Its not possible to embed IfThenElse.

Parsing building and sizeof are deferred to subcon.

Parameters:subcon – Construct instance, its fields to embed inside a struct or sequence

Example:

>>> outer = Struct(
...     Embedded(Struct(
...         "data" / Bytes(4),
...     )),
... )
>>> outer.parse(b"1234")
Container(data=b'1234')
construct.Renamed(subcon, newname=None, newdocs=None, newparsed=None)

Special wrapper that allows a Struct (or other similar class) to see a field as having a name (or a different name) or having a parsed hook. Library classes do not have names (its None). Renamed does not change a field, only wraps it like a candy with a label. Used internally by / and * operators.

Also this wrapper is responsible for building a path info (a chain of names) that gets attached to error message when parsing, building, or sizeof fails. Fields that are not named do not appear in the path string.

Parsing building and size are deferred to subcon.

Parameters:
  • subcon – Construct instance
  • newname – optional, string
  • newdocs – optional, string
  • newparsed – optional, lambda

Example:

>>> "number" / Int32ub
<Renamed: number>