:py:mod:`socha.api.networking.xml_protocol_interface` ===================================================== .. py:module:: socha.api.networking.xml_protocol_interface .. autoapi-nested-parse:: Here are all incoming byte streams and all outgoing protocol objects handled. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: socha.api.networking.xml_protocol_interface.XMLProtocolInterface Functions ~~~~~~~~~ .. autoapisummary:: socha.api.networking.xml_protocol_interface.map_object socha.api.networking.xml_protocol_interface.map_last_move socha.api.networking.xml_protocol_interface.custom_class_factory Attributes ~~~~~~~~~~ .. autoapisummary:: socha.api.networking.xml_protocol_interface.PROTOCOL_PREFIX .. py:function:: map_object(data: socha.api.protocol.protocol.Data, params: dict) .. py:function:: map_last_move(last_move: socha.api.protocol.protocol.LastMove, params: dict) .. py:function:: custom_class_factory(clazz, params: dict) .. py:data:: PROTOCOL_PREFIX .. py:class:: XMLProtocolInterface(host: str, port: int) Serialize and deserialize objects to and from XML. .. py:method:: connect() Creates a TCP connection with the server. .. py:method:: disconnect() Sends a closing xml to the server and closes the connection afterward. .. py:method:: _receive() Gets a receiving byte stream from the server and deserializes it into an object. :return: The next object in the stream, or None if the server returns an empty response. .. py:method:: send(obj: socha.api.protocol.protocol_packet.ProtocolPacket) -> None Sends an object to the server. :param obj: The object to send. Must not be `None`. .. py:method:: _encode_context() -> Iterator[Callable[[Any], bytes]] A context manager that yields a function for encoding objects as bytes. .. py:method:: _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. .. py:method:: _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.