[plum.structure] Module Reference

Interpret bytes as a structure with uniquely named and typed members.

class plum.structure.StructureType

Structure type metaclass.

Create custom Structure subclass. For example:

>>> from plum.structure import Structure
>>> from plum.int.little import UInt16, UInt8
>>> class MyStruct(Structure):
...     m0: UInt16
...     m1: UInt8
...
>>>
class plum.structure.Structure(mapping, **kwargs)

Interpret bytes as a list of uniquely typed items.

Parameters:iterable (iterable) – items
class plum.structure.BitFieldMember(*, cls, default=None)

Bit field structure member definition.

Parameters:
  • cls (BitFields) – BitFields class that incorporates member
  • default (object) – initial value when unspecified
class plum.structure.DimsMember(*, cls=None, ignore=False)

Array dimension structure member definition.

Parameters:
  • cls (Plum) – member type
  • ignore (bool) – ignore member during comparisons
class plum.structure.Member(*, cls=None, default=None, ignore=False, setter=None)

Structure member definition.

Parameters:
  • cls (Plum) – member type (or factory function)
  • default (object) – initial value when unspecified
  • ignore (bool) – ignore member during comparisons
  • setter (function) – callback when member set via setattr()
class plum.structure.SizeMember(*, cls=None, ratio=1, offset=0, ignore=False)

Size structure member definition.

Parameters:
  • cls (Plum) – member type
  • ratio (int) – number of bytes per increment of member
  • offset (int) – difference in size (in bytes)
  • ignore (bool) – ignore member during comparisons
class plum.structure.TypeMember(*, mapping, cls=None, ignore=False)

Structure member holding a type map for another member.

Parameters:
  • mapping (dict) – type member value (key) to Plum type (value) mapping
  • cls (PlumType) – member type
  • ignore (bool) – ignore member during comparisons
  • decipher (function) –
class plum.structure.VariableDimsMember(*, dims_member, cls=None, default=None, ignore=False)

Variable dimensions array structure member definition.

Parameters:
  • dims_member (DimsMember) – array dimensions member name
  • cls (Plum) – undimensioned array base class (or factory function)
  • default (object) – initial value when unspecified
  • ignore (bool) – ignore member during comparisons
class plum.structure.VariableSizeMember(*, size_member, cls=None, default=None, ignore=False)

Variable sized member definition.

Parameters:
  • size_member (SizeMember) – size member definition
  • cls (Plum) – member type (or factory function)
  • default (object) – initial value when unspecified
  • ignore (bool) – ignore member during comparisons
class plum.structure.VariableTypeMember(*, type_member, default=None, ignore=False)

Variable type member definition.

Parameters:
  • type_member (TypeMember) – type map member definition
  • default (object) – initial value when unspecified
  • ignore (bool) – ignore member during comparisons