Pickle Serializer
pickle-based packet serializer module.
Danger
Read the security considerations for using pickle module.
- class easynetwork.serializers.pickle.PickleSerializer
Bases:
AbstractPacketSerializer[Any,Any]A one-shot serializer built on top of the
picklemodule.See also
- How-to — Serializer Combinations
This class cannot be used directly with a
StreamProtocol. This page explains possible workarounds.
- __init__(pickler_config: PicklerConfig | None = None, unpickler_config: UnpicklerConfig | None = None, *, pickler_cls: type[TypeAliasForwardRef('pickle.Pickler')] | None = None, unpickler_cls: type[TypeAliasForwardRef('pickle.Unpickler')] | None = None, pickler_optimize: bool = False, debug: bool = False) None
- Parameters:
pickler_config (PicklerConfig | None) – Parameter object to configure the
Pickler.unpickler_config (UnpicklerConfig | None) – Parameter object to configure the
Unpickler.pickler_cls (type[TypeAliasForwardRef('pickle.Pickler')] | None) – The
Picklerclass to use (see Pickling Class Instances).unpickler_cls (type[TypeAliasForwardRef('pickle.Unpickler')] | None) – The
Unpicklerclass to use (see Restricting Globals).pickler_optimize (bool) – If True,
pickletools.optimize()will be applied topickle.Pickler.dump()output.debug (bool) – If
True, add information toDeserializeErrorvia theerror_infoattribute.
- final serialize(packet: Any) bytes
Returns the pickle representation of the Python object packet.
Roughly equivalent to:
def serialize(self, packet): return pickle.dumps(packet)
- final deserialize(data: bytes) Any
Creates a Python object representing the raw pickle packet from data.
Roughly equivalent to:
def deserialize(self, data): return pickle.loads(data)
- Parameters:
data (bytes) – The byte sequence to deserialize.
- Raises:
DeserializeError – Too little or too much data to parse.
DeserializeError – An unrelated deserialization error occurred.
- Returns:
the deserialized Python object.
- Return type:
Configuration
- class easynetwork.serializers.pickle.PicklerConfig
Bases:
objectA dataclass with the Pickler options.
See
pickle.Picklerfor details.
- class easynetwork.serializers.pickle.UnpicklerConfig
Bases:
objectA dataclass with the Unpickler options.
See
pickle.Unpicklerfor details.