gale.net.serialization module
This file contains the default message serializer/deserializer used by gale.net’s Server and Client. Both are plain functions, and both are accepted as constructor parameters, so a game that needs a more compact wire format (for a latency-critical action game, say) can swap them out without changing anything else.
Author: Alejandro Mujica (aledrums@gmail.com)
- gale.net.serialization.json_serialize(message_type, payload)[source]
- Parameters:
message_type (str) – The message type/name.
payload (Dict[str, Any]) – The message’s data.
- Returns:
The UTF-8 encoded JSON representation of {“type”: message_type, “payload”: payload}.
- Return type:
bytes
- gale.net.serialization.json_deserialize(data)[source]
- Parameters:
data (bytes) – Bytes produced by json_serialize (or a wire-compatible encoder).
- Returns:
A tuple (message_type, payload).
- Raises:
ValueError – If data is not valid JSON or does not have the expected shape.
- Return type:
Tuple[str, Dict[str, Any]]