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:
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 (
Union[TypeVar(_T, str, bytes, dict[str, Any]),NoValueType]) – Field default value, if any.callback (
Callable[[Self,dict[str,Any]],None]) – Callback function to be called uponself.__call__.
- class pcapkit.corekit.fields.strings.PaddingField(length, default=<pcapkit.corekit.fields.field.NoValueType object>, callback=<function _TextField.<lambda>>)[source]¶
Bases:
BytesFieldBytes 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 (
Union[TypeVar(_T, str, bytes, dict[str, Any]),NoValueType]) – Field default value, if any.callback (
Callable[[Self,dict[str,Any]],None]) – Callback function to be called uponself.__call__.
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 thebytes. If not provided,pcapkitwill first try detecting its encoding usingchardet. 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 aUnicodeDecodeError. Other possible values are'ignore'and'replace'as well as any other name registered withcodecs.register_error()that can handleUnicodeDecodeError.unquote (
bool) – Whether to unquote the decoded string as a URL. Should decoding failed , the method will try again replacing'%'with'\x'then decoding theurlas'utf-8'with'replace'for error handling.callback (
Callable[[Self,dict[str,Any]],None]) – Callback function to be called uponself.__call__.
- 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:
length (
int) – Field size (in bytes).default (
dict[str,Any] |NoValueType) – Field default value, if any.namespace (
Optional[dict[str,Tuple[int,int]]]) – Field namespace (a dict mapping field name to a tuple of start index, and length of the subfield).callback (
Callable[[Self,dict[str,Any]],None]) – Callback function to be called uponself.__call__.
Internal Definitions¶
- class pcapkit.corekit.fields.strings._TextField(length, default=<pcapkit.corekit.fields.field.NoValueType object>, callback=<function _TextField.<lambda>>)[source]¶
-
Internal text 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 (
Union[TypeVar(_T, str, bytes, dict[str, Any]),NoValueType]) – Field default value, if any.callback (
Callable[[Self,dict[str,Any]],None]) – Callback function to be called uponself.__call__.
- __call__(packet)[source]¶
Update field attributes.
- Parameters:
- Return type:
Self- Returns:
New instance of
_TextField.
This method will return a new instance of
_TextFieldinstead of updating the current instance.