Container Fields

Generic List Fields

class pcapkit.corekit.fields.collections.ListField(length=<function ListField.<lambda>>, item_type=None, callback=<function ListField.<lambda>>)[source]

Bases: FieldBase[list[_TL]], Generic[_TL]

Field list for protocol fields.

Parameters:

This field is used to represent a list of fields, as in the case of lists of constrant-length-field items in a protocol.

property length: int

Field size.

property optional: bool

Field is optional.

__call__(packet)[source]

Update field attributes.

Parameters:

packet (dict[str, Any]) – Packet data.

Return type:

Self

Returns:

Updated field instance.

This method will return a new instance of ListField instead of updating the current instance.

pack(value, packet)[source]

Pack field value into bytes.

Parameters:
Return type:

bytes

Returns:

Packed field value.

unpack(buffer, packet)[source]

Unpack field value from bytes.

Parameters:
Return type:

bytes | list[TypeVar(_TL, Schema, FieldBase, bytes)]

Returns:

Unpacked field value.

Option List Fields

class pcapkit.corekit.fields.collections.OptionField(length=<function OptionField.<lambda>>, base_schema=None, type_name='type', registry=None, eool=None, callback=<function OptionField.<lambda>>)[source]

Bases: ListField, Generic[_TS]

Field list for protocol options.

Parameters:
  • length (Union[int, Callable[[dict[str, Any]], int]]) – Field size (in bytes); if a callable is given, it should return an integer value and accept the current packet as its only argument.

  • base_schema (Optional[Type[TypeVar(_TS, bound= Schema)]]) – Base schema for option fields.

  • type_name (str) – Name of the option type field.

  • registry (Optional[defaultdict[int | IntEnum | IntEnum, Type[TypeVar(_TS, bound= Schema)]]]) – Option registry, as in a mapping from option types (enumeration values) to option schemas, with the default value being the unknown option schema.

  • eool (Union[int, IntEnum, IntEnum, None]) – Enumeration of the EOOL (end-of-option-list, or equivalent) option

  • callback (Callable[[Self, dict[str, Any]], None]) – Callback function to be called upon self.__call__.

This field is used to represent a list of fields, as in the case of lists of options and/or parameters in a protocol.

property base_schema: Type[_TS]

Base schema.

property type_name: str

Type name.

property registry: defaultdict[int | IntEnum | IntEnum, Type[_TS]]

Option registry.

property eool: int | IntEnum | IntEnum

EOOL option.

property option_padding: int

Length option padding data.

unpack(buffer, packet)[source]

Unpack field value from bytes.

Parameters:
Return type:

list[TypeVar(_TS, bound= Schema)]

Returns:

Unpacked field value.

Important

If the option list ended before the specified size limit, set self.option_padding as the remaining length to the packet argument such that the next fields can be aware of such informations.

Type Variables

pcapkit.corekit.fields.collections._TL: pcapkit.protocols.schema.schema.Schema | pcapkit.corekit.fields.field.FieldBase | bytes
pcapkit.corekit.fields.collections._TS: pcapkit.protocols.schema.schema.Schema