Protocol Chain

pcapkit.corekit.protochain contains special protocol collection class ProtoChain.

class pcapkit.corekit.protochain.ProtoChain(proto, alias=None, *, basis=None)[source]

Bases: Sequence

Protocols chain.

Parameters:
  • proto (Union[ProtocolBase, Type[ProtocolBase]]) – New protocol class on the top stack.

  • alias (Optional[str]) – New protocol alias on the top stack.

  • basis (Optional[ProtoChain]) – Original protocol chain as base stacks.

  • proto – New protocol class on the top stack.

  • alias – New protocol alias on the top stack.

  • basis – Original protocol chain as base stacks.

property protocols: tuple[Type[ProtocolBase], ...][source]

List of protocols in the chain.

property aliases: tuple[str, ...][source]

Protocol names.

property chain: str

Protocol chain string.

classmethod from_list(data)[source]

Create a protocol chain from a list.

Parameters:

data (list[Union[ProtocolBase, Type[ProtocolBase]]]) – Protocol chain list.

Return type:

Self

index(value, start=None, stop=None)[source]

First index of value.

Parameters:
Raises:

IndexNotFound – If the value is not present.

Return type:

int

count(value)[source]

Number of occurrences of value.

Parameters:

value (Union[str, ProtocolBase, Type[ProtocolBase]]) – Value to search.

Return type:

int

__str__()[source]

Returns formatted hex representation of source data stream. :rtype: str

Example

>>> protochain
ProtoChain(Ethernet, IPv6, Raw)
>>> print(protochain)
Ethernet:IPv6:Raw
__repr__()[source]

Returns representation of protocol chain data. :rtype: str

Example

>>> protochain
ProtoChain(Ethernet, IPv6, Raw)
__add__(other)[source]

Merge protocol chain by appending protocols from other.

Parameters:

other (ProtoChain) – Protocol chain to be merged.

Return type:

ProtoChain

Returns:

Merged protocol chain.

__contains__(name)[source]

Returns if name is in the chain.

Parameters:

name (Union[str, ProtocolBase, Type[ProtocolBase]]) – Name to search.

Return type:

bool

Returns:

Whether name is in the chain.