dissect.cstruct.types.enum

Module Contents

Classes

EnumMetaType

Metaclass for Enum

Enum

Enum type supercharged with cstruct functionality.

Attributes

dissect.cstruct.types.enum.PY_311
dissect.cstruct.types.enum.PY_312
class dissect.cstruct.types.enum.EnumMetaType

Bases: enum.EnumMeta, dissect.cstruct.types.base.MetaType

Metaclass for Enum

type: dissect.cstruct.types.base.MetaType
__call__(value: dissect.cstruct.cstruct.cstruct | int | BinaryIO | bytes = None, name: str | None = None, type_: dissect.cstruct.types.base.MetaType | None = None, *args, **kwargs) EnumMetaType

Either returns an existing member, or creates a new enum class.

This method is used both when an enum class is given a value to match to an enumeration member (i.e. Color(3)) and for the functional API (i.e. Color = Enum(‘Color’, names=’RED GREEN BLUE’)).

When used for the functional API:

value will be the name of the new class.

names should be either a string of white-space/comma delimited names (values will start at start), or an iterator/mapping of name, value pairs.

module should be set to the module this class is being created in; if it is not set, an attempt to find that module will be made, but if it fails the class will not be picklable.

qualname should be set to the actual location this class can be found at in its module; by default it is set to the global scope. If this is not correct, unpickling will fail in some circumstances.

type, if set, will be mixed in as the first base class.

__getitem__(name: str | int) Enum | dissect.cstruct.types.base.Array

Create a new array with the given number of entries.

__len__

Return the byte size of the type.

__contains__(value: Any) bool
class dissect.cstruct.types.enum.Enum

Bases: dissect.cstruct.types.base.BaseType, enum.IntEnum

Enum type supercharged with cstruct functionality.

Enums are (mostly) compatible with the Python 3 standard library IntEnum with some notable differences:
  • Duplicate members are their own unique member instead of being an alias

  • Non-existing values are allowed and handled similarly to IntFlag: <Enum: 0>

  • Enum members are only considered equal if the enum class is the same

Enums can be made using any integer type.

Example

When using the default C-style parser, the following syntax is supported:

enum <name> [: <type>] {
    <values>
};

For example, an enum that has A=1, B=5 and C=6 could be written like so:

enum Test : uint16 {
    A, B=5, C
};
__repr__() str

Return repr(self).

__eq__(other: int | Enum) bool

Return self==value.

__ne__(value: int | Enum) bool

Return self!=value.

__hash__() int

Return hash(self).