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:
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
),NoValueType
]) – Field default value, if any.callback (
Callable
[[Self
,dict
[str
,Any
]],None
]) – Callback function to be called uponself.__call__
.
- class pcapkit.corekit.fields.field.FieldBase(*args, **kwargs)[source]¶
-
Internal base class for protocol fields.
Important
A negative value of
length
indicates that the field is variable-length (i.e., length unspecified) and thuspack()
should be considerate of the template format and the actual value provided for packing.- Parameters:
- property default: _T | NoValueType¶
Field default value.
- __call__(packet)[source]¶
Update field attributes.
- Parameters:
- 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:
Auxiliaries¶
- pcapkit.corekit.fields.field.NoValue¶
Default value for
FieldBase.default
.- Type:
Internal Definitions¶
- class pcapkit.corekit.fields.field.FieldMeta(name, bases, namespace, /, **kwargs)[source]¶
-
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.