Text Fields#

Bytes-based Fields#

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

Bases: _TextField[bytes]

Bytes value for protocol fields.

Parameters:
pre_process(value, packet)[source]#

Process field value before construction (packing).

Parameters:
Return type:

bytes

Returns:

Processed field value.

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

Bases: BytesField

Bytes value for protocol fields.

Parameters:

String-based Fields#

class pcapkit.corekit.fields.strings.StringField(length, default=<pcapkit.corekit.fields.field.NoValueType object>, encoding=None, errors='strict', unquote=False, callback=<function StringField.<lambda>>)[source]#

Bases: _TextField[str]

String value for protocol fields.

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.

  • default (str | NoValueType) – Field default value, if any.

  • encoding (Optional[str]) – The encoding with which to decode the bytes. If not provided, pcapkit will first try detecting its encoding using chardet. The fallback encoding would is UTF-8.

  • errors (Literal['strict', 'ignore', 'replace']) – The error handling scheme to use for the handling of decoding errors. The default is 'strict' meaning that decoding errors raise a UnicodeDecodeError. Other possible values are 'ignore' and 'replace' as well as any other name registered with codecs.register_error() that can handle UnicodeDecodeError.

  • unquote (bool) – Whether to unquote the decoded string as a URL. Should decoding failed , the method will try again replacing '%' with '\x' then decoding the url as 'utf-8' with 'replace' for error handling.

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

pre_process(value, packet)[source]#

Process field value before construction (packing).

Parameters:
  • value (str) – Field value.

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

Return type:

bytes

Returns:

Processed field value.

post_process(value, packet)[source]#

Process field value after parsing (unpacked).

Parameters:
Return type:

str

Returns:

Processed field value.

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

Bases: _TextField[dict[str, Any]]

Bit value for protocol fields.

Parameters:
pre_process(value, packet)[source]#

Process field value before construction (packing).

Parameters:
Return type:

bytes

Returns:

Processed field value.

post_process(value, packet)[source]#

Process field value after parsing (unpacked).

Parameters:
Return type:

dict[str, Any]

Returns:

Processed field value.

Internal Definitions#

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

Bases: Field[_T], Generic[_T]

Internal text value for protocol fields.

Parameters:
__call__(packet)[source]#

Update field attributes.

Parameters:

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

Return type:

Self

Returns:

New instance of _TextField.

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

Type Variables#

pcapkit.corekit.fields.strings._T: str | bytes | dict[str, Any]#