Core API: Special

construct.Embedded(subcon)

Embeds a struct into the enclosing struct, merging fields. Can also embed sequences into sequences, merging items. Name is inherited from subcon.

Warning

You can use Embedded(Switch(…)) but not Switch(Embedded(…)). Sames applies to If and IfThenElse macros.

Parameters:subcon – the inner struct to embed inside outer struct or sequence

Example:

>>> d = Struct("a"/Byte, Embedded(Struct("b"/Byte)), "c"/Byte)
>>> d.parse(b"abc")
Container(a=97)(b=98)(c=99)
construct.Renamed(newname, subcon)

Renames an existing construct. This creates a wrapper so underlying subcon retains it’s original name, which by default is just None. Can be used to give same construct few different names. Used internally by / operator.

Also this wrapper is responsible for building a path (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.

Parameters:
  • newname – the new name, as string
  • subcon – the subcon to rename

Example:

>>> "name" / Int32ul
<Renamed: name>