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)

See also

pcapkit.protocols.protocol.Protocol._read_packet()

Parameters

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

Return type

Callable[P, 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)

See also

pcapkit.protocols.protocol.Protocol._decode_next_layer()

Parameters

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

Return type

Callable[P, R]

Important

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