Decorator Functions

pcapkit.utilities.decorators contains several useful decorators, including seekset() and beholder().

@pcapkit.utilities.decorators.seekset(func)[source]

Read file from start then set back to original.

Important

This decorator function is designed for decorating class methods.

The decorator will keep the current offset of self._file, then call the decorated function. Afterwards, it will rewind the offset of self._file to the original and returns the return value from the decorated function.

Note

The decorated function should have following signature:

func(self, *args, **kw)
Parameters

func (Callable[[Protocol, ParamSpec(P)], TypeVar(R)]) – decorated function

Return type

Callable[[ParamSpec(P)], TypeVar(R)]

@pcapkit.utilities.decorators.beholder(func)[source]

Behold extraction procedure.

Important

This decorator function is designed for decorating class methods.

This decorate first keep the current offset of self._file, then try to call the decorated function. Should any exception raised, it will re-parse the self._file as Raw protocol.

Note

The decorated function should have following signature:

func(self, proto, length, *args, **kwargs)
Parameters

func (Callable[[Protocol, int, Optional[int], ParamSpec(P)], TypeVar(R)]) – decorated function

Return type

Callable[[ParamSpec(P)], TypeVar(R)]

Important

pcapkit.utilities.decorators.seekset() and pcapkit.utilities.decorators.beholder() are designed for decorating class methods.