Base Fields#

class pcapkit.corekit.fields.field.Field(length, default=<pcapkit.corekit.fields.field.NoValueType object>, callback=<function Field.<lambda>>)[source]#

Bases: FieldBase[_T], Generic[_T]

Base class for protocol fields.

Parameters:
property template: str#

Field template.

__call__(packet)[source]#

Update field attributes.

Parameters:

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

Return type:

Self

Returns:

New instance of Field.

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

class pcapkit.corekit.fields.field.FieldBase(*args, **kwargs)[source]#

Bases: Generic[_T]

Internal base class for protocol fields.

Important

A negative value of length indicates that the field is variable-length (i.e., length unspecified) and thus pack() should be considerate of the template format and the actual value provided for packing.

Parameters:
  • *args (Any) – Arbitrary positional arguments.

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

property name: str#

Field name.

property default: _T | NoValueType#

Field default value.

property template: str#

Field template.

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 FieldBase instead of updating the current instance.

__set_name__(owner, name)[source]#

Set field name and update field list (if applicable).

This method is to be called by the metaclass during class creation. It is used to set the field name and update the field list, i.e., Schema.__fields__ mapping dictionary.

Return type:

None

pre_process(value, packet)[source]#

Process field value before construction (packing).

Parameters:
Return type:

Any

Returns:

Processed field value.

pack(value, packet)[source]#

Pack field value into bytes.

Parameters:
Return type:

bytes

Returns:

Packed field value.

post_process(value, packet)[source]#

Process field value after parsing (unpacking).

Parameters:
  • value (Any) – Field value.

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

Return type:

TypeVar(_T)

Returns:

Processed field value.

unpack(buffer, packet)[source]#

Unpack field value from bytes.

Parameters:
Return type:

TypeVar(_T)

Returns:

Unpacked field value.

Auxiliaries#

class pcapkit.corekit.fields.field.NoValueType[source]#

Bases: object

Default value for fields.

pcapkit.corekit.fields.field.NoValue#

Default value for FieldBase.default.

Type:

NoValueType

Internal Definitions#

class pcapkit.corekit.fields.field.FieldMeta(name, bases, namespace, /, **kwargs)[source]#

Bases: ABCMeta, Generic[_T]

Meta class to add dynamic support to FieldBase.

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

Type Variables#

pcapkit.corekit.fields.field._T: Any#