Base Engine

This is the abstract base class implementation for all engine support functionality.

class pcapkit.foundation.engines.engine.Engine(extractor)[source]

Bases: EngineBase[_T], Generic[_T]

Base class for engine support.

Example

Use keyword argument name to specify the engine name at class definition:

class MyEngine(Engine, name='my_engine'):
    ...
Parameters:

extractor (Extractor) – Extractor instance.

See also

For more information on customisation and extension, please refer to Customisation & Extensions.

property name: str

Engine name.

Note

This property is also available as a class variable. Its value can be set by __engine_name__ class attribute.

property module: str

Engine module name.

Note

This property is also available as a class variable. Its value can be set by __engine_module__ class attribute.

property extractor: Extractor

Extractor instance.

abstract run()

Start extraction.

This method is the entry point for file extraction. It is to be used for preparing the extraction process, such as parsing the file header and setting up the extraction engines.

Return type:

None

abstract read_frame()

Read frame.

This method is to be used for reading a frame from the file. It is to read a frame from the file using the prepared engine instance and return the parsed frame.

Return type:

TypeVar(_T)

close()

Close engine.

This method is to be used for closing the engine instance. It is to close the engine instance after the extraction process is finished.

Return type:

None

__call__()

Start extraction.

This method will directly call run() to start the extraction process.

Return type:

None

classmethod __init_subclass__(name=None, *args, **kwargs)[source]

Initialise subclass.

This method is to be used for registering the engine class to Extractor class.

Parameters:
  • name (Optional[str]) – Engine name, default to class name.

  • *args (Any) – Arbitrary positional arguments.

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type:

None

See also

For more details, please refer to pcapkit.foundation.extraction.Extractor.register_engine().

__engine_name__: str

Engine name.

__engine_module__: str

Engine module name.

Internal Definitions

class pcapkit.foundation.engines.engine.EngineBase(extractor)[source]

Bases: Generic[_T]

Base class for engine support.

Parameters:

extractor (Extractor) – Extractor instance.

Note

This class is for internal use only. For customisation, please use Engine instead.

class pcapkit.foundation.engines.engine.EngineMeta(name, bases, namespace, /, **kwargs)[source]

Bases: ABCMeta, Generic[_T]

Meta class to add dynamic support to EngineBase.

This meta class is used to generate necessary attributes for the EngineBase class. It can be useful to reduce unnecessary registry calls and simplify the customisation process.

Type Variables

pcapkit.foundation.engines.engine._T: Any