@classmethod<EOL><INDENT>def index(cls, name, default=None, *, namespace=None, reversed=False,<EOL>pack=False, size=<NUM_LIT:4>, signed=False, lilendian=False):<DEDENT>
if isinstance(name, (enum.IntEnum, aenum.IntEnum)):<EOL><INDENT>index = name.value<EOL><DEDENT>elif isinstance(name, numbers.Integral):<EOL><INDENT>index = name<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>if isinstance(namespace, (enum.EnumMeta, aenum.EnumMeta)):<EOL><INDENT>index = namespace[name]<EOL><DEDENT>elif isinstance(namespace, (dict, collections.UserDict, collections.abc.Mapping)):<EOL><INDENT>if reversed:<EOL><INDENT>index = namespace[name]<EOL><DEDENT>else:<EOL><INDENT>index = {v: k for k, v in namespace.items()}[name]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise KeyError<EOL><DEDENT><DEDENT>except KeyError:<EOL><INDENT>if default is None:<EOL><INDENT>raise ProtocolNotImplemented(f'<STR_LIT>') from None<EOL><DEDENT>index = default<EOL><DEDENT><DEDENT>if pack:<EOL><INDENT>return cls.pack(index, size=size, signed=signed, lilendian=lilendian)<EOL><DEDENT>return index<EOL>
Return first index of name from a dict or enumeration.

        Positional arguments:
            * name -- str / int / IntEnum, item to be indexed
            * default -- int, default value

        Keyword arguments:
            * namespace -- dict / EnumMeta, namespace for item
            * reversed -- bool, if namespace is [str -> int] pairs
            * pack -- bool, if need struct.pack
            * size -- int, buffer size (default is 4)
            * signed -- bool, signed flag (default is False)
            * lilendian -- bool, little-endian flag (default is False)