Miscellaneous Fields¶
Conditional Fields¶
- class pcapkit.corekit.fields.misc.SwitchField(selector=<function SwitchField.<lambda>>)[source]¶
-
Conditional type-switching field for protocol schema.
- Parameters:
selector (
Callable
[[dict
[str
,Any
]],FieldBase
[TypeVar
(_TC
)]]) – Callable function to select field type, which should accept the current packet as its only argument and return a field instance.
- property default: _TC | NoValueType¶
Field default value.
- __call__(packet)[source]¶
Call field.
- Parameters:
- Return type:
SwitchField
[TypeVar
(_TC
)]- Returns:
New field instance.
This method will return a new instance of
SwitchField
instead of updating the current instance.
- class pcapkit.corekit.fields.misc.ConditionalField(field, condition)[source]¶
-
Conditional value for protocol fields.
- Parameters:
- property default: _TC | 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
ConditionalField
instead of updating the current instance.
- class pcapkit.corekit.fields.misc.ForwardMatchField(field)[source]¶
-
Schema field for non-capturing forward matching.
- property default: _TC | 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
ConditionalField
instead of updating the current instance.
Generic Data Fields¶
- class pcapkit.corekit.fields.misc.SchemaField(length=<function SchemaField.<lambda>>, schema=None, default=<pcapkit.corekit.fields.field.NoValueType object>, packet=None, callback=<function SchemaField.<lambda>>)[source]¶
-
Schema field for protocol schema.
- 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.schema (
Optional
[Type
[TypeVar
(_TS
, bound= Schema)]]) – Field schema.default (
Union
[TypeVar
(_TS
, bound= Schema),NoValueType
,bytes
]) – Default value for field.packet (
Optional
[dict
[str
,Any
]]) – Optional packet data for unpacking and/or packing purposes.callback (
Callable
[[Self
,dict
[str
,Any
]],None
]) – Callback function to process field value, which should accept the current field and the current packet as its arguments.
- __call__(packet)[source]¶
Update field attributes.
This method will return a new instance of
SchemaField
instead of updating the current instance.
- pack(value, packet)[source]¶
Pack field value into
bytes
.- Parameters:
- Return type:
- Returns:
Packed field value.
Notes
We will use
packet
as a__packet__
key in the packet context passed to the underlyingSchema
for packing purposes.
- class pcapkit.corekit.fields.misc.PayloadField(length=<function PayloadField.<lambda>>, default=<pcapkit.corekit.fields.field.NoValueType object>, protocol=None, callback=<function PayloadField.<lambda>>)[source]¶
-
Payload 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
(_TP
, bound= Protocol),NoValueType
,bytes
]) – Field default value.protocol (
Optional
[Type
[TypeVar
(_TP
, bound= Protocol)]]) – Payload protocol.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:
Updated field instance.
This method will return a new instance of
PayloadField
instead of updating the current instance.
Type Variables¶
- pcapkit.corekit.fields.misc._TS: pcapkit.protocols.schema.schema.Schema¶
- pcapkit.corekit.fields.misc._TP: pcapkit.protocols.protocol.Protocol¶
- pcapkit.corekit.fields.misc._TN: pcapkit.corekit.fields.field.NoValueType¶