socha.api.networking.xml_protocol_interface

Here are all incoming byte streams and all outgoing protocol objects handled.

Module Contents

Classes

XMLProtocolInterface

Serialize and deserialize objects to and from XML.

Functions

map_object(data, params)

map_last_move(last_move, params)

custom_class_factory(clazz, params)

Attributes

socha.api.networking.xml_protocol_interface.map_object(data: socha.api.protocol.protocol.Data, params: dict)
socha.api.networking.xml_protocol_interface.map_last_move(last_move: socha.api.protocol.protocol.LastMove, params: dict)
socha.api.networking.xml_protocol_interface.custom_class_factory(clazz, params: dict)
socha.api.networking.xml_protocol_interface.PROTOCOL_PREFIX
class socha.api.networking.xml_protocol_interface.XMLProtocolInterface(host: str, port: int)

Serialize and deserialize objects to and from XML.

connect()

Creates a TCP connection with the server.

disconnect()

Sends a closing xml to the server and closes the connection afterward.

_receive()

Gets a receiving byte stream from the server and deserializes it into an object.

Rückgabe:

The next object in the stream, or None if the server returns an empty response.

send(obj: socha.api.protocol.protocol_packet.ProtocolPacket) None

Sends an object to the server.

Parameter:

obj – The object to send. Must not be None.

_encode_context() Iterator[Callable[[Any], bytes]]

A context manager that yields a function for encoding objects as bytes.

_deserialize_object(byte_stream: bytes) socha.api.protocol.protocol_packet.ProtocolPacket

Deserialize a xml byte stream to a ProtocolPacket. :param byte_stream: The byte stream to deserialize. :return: The deserialized ProtocolPacket child.

_serialize_object(object_class: object) bytes

Serialize a ProtocolPacket child to a xml byte stream. :param object_class: The ProtocolPacket child to serialize. :return: The serialized byte stream.