MessagePack Serializer
MessagePack-based network packet serializer module.
The MessagePack is an alternative representation of the JSON data models.
See also
- Optional Dependencies
Explains how to install
msgpackextra.
- class easynetwork.serializers.msgpack.MessagePackSerializer
Bases:
FileBasedPacketSerializer[Any,Any]A serializer built on top of the
msgpackmodule.Needs
msgpackextra dependencies.- __init__(packer_config: MessagePackerConfig | None = None, unpacker_config: MessageUnpackerConfig | None = None, *, limit: int = DEFAULT_SERIALIZER_LIMIT, debug: bool = False) None
- Parameters:
packer_config (MessagePackerConfig | None) – Parameter object to configure the
Packer.unpacker_config (MessageUnpackerConfig | None) – Parameter object to configure the
Unpacker.limit (int) – Maximum buffer size. Used in incremental serialization context.
debug (bool) – If
True, add information toDeserializeErrorvia theerror_infoattribute.
- final serialize(packet: Any) bytes
Returns the MessagePack representation of the Python object packet.
Roughly equivalent to:
def serialize(self, packet): return msgpack.packb(packet)
- final deserialize(data: bytes) Any
Creates a Python object representing the raw MessagePack packet from data.
Roughly equivalent to:
def deserialize(self, data): return msgpack.unpackb(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:
- final dump_to_file(packet: Any, file: IO[bytes]) None
Write the MessagePack representation of packet to file.
Roughly equivalent to:
def dump_to_file(self, packet, file): msgpack.pack(packet, file)
- Parameters:
packet (Any) – The Python object to serialize.
file (IO[bytes]) – The binary file to write to.
Configuration
- class easynetwork.serializers.msgpack.MessagePackerConfig
Bases:
objectA dataclass with the Packer options.
See
msgpack.Packerfor details.
- class easynetwork.serializers.msgpack.MessageUnpackerConfig
Bases:
objectA dataclass with the Unpacker options.
See
msgpack.Unpackerfor details.- __init__(*, raw: bool = False, use_list: bool = True, timestamp: int = 0, strict_map_key: bool = True, unicode_errors: str = 'strict', object_hook: Callable[[dict[Any, Any]], Any] | None = None, object_pairs_hook: Callable[[list[tuple[Any, Any]]], Any] | None = None, ext_hook: Callable[[int, bytes], Any] | None = None) None