latest.ipv8.messaging.lazy_payload

Module Contents

Classes

VariablePayload

A Payload instance which mimics a struct. Useful for when you want a less verbose way to specify Payloads.

Functions

vp_compile(→ type[T])

JIT Compilation of a VariablePayload definition.

class latest.ipv8.messaging.lazy_payload.VariablePayload(*args: Any, **kwargs)

Bases: latest.ipv8.messaging.serialization.Payload

A Payload instance which mimics a struct. Useful for when you want a less verbose way to specify Payloads.

This class requires you to only specify your format in:

  • <MyPayload>.format_list : a list of Serializer format specifications

  • <MyPayload>.names : the field names to use for the given formats

For instance:

class MyPayload(VariablePayload):

format_list = [‘?’] names = [“is_this_a_boolean”]

If you require field-specific pack/unpack operations you can specify them using the fix_pack_* and fix_unpack_* methods. Custom packing and unpacking rules can be useful for compression methods like socket.inet_aton, which you only want to apply when actually sending over the wire.

names: list[str] = []
classmethod from_unpack_list(*args: Any) VariablePayload

Given a list of raw arguments, initialize a new cls instance.

If this class has special rules for certain fields, apply them.

static _to_packlist_fmt(fmt: latest.ipv8.messaging.serialization.FormatListType) str
_fix_pack(name: str) Any

Check if there are custom rules for sending this field.

to_pack_list() list[tuple]

Convert the VariablePayload to a Serializable pack list. This method will automatically pull from the available format names and set instance fields.

Returns:

the pack list

latest.ipv8.messaging.lazy_payload.vp_compile(vp_definition: type[T]) type[T]

JIT Compilation of a VariablePayload definition.