Protocols
Communication protocol objects module.
- easynetwork.protocol.AnyStreamProtocolType
Type alias for any connection-oriented stream protocol object classes.
Alias of
Union[StreamProtocol[~_T_SentPacket,~_T_ReceivedPacket],BufferedStreamProtocol[~_T_SentPacket,~_T_ReceivedPacket,Any]]
- class easynetwork.protocol.BufferedStreamProtocol
Bases:
Generic[_T_SentPacket,_T_ReceivedPacket,_T_Buffer]A specialization of
StreamProtocolin order to use a buffered incremental serializer.- __init__(serializer: BufferedIncrementalPacketSerializer[_T_SentPacket, _T_ReceivedPacket, _T_Buffer], converter: None = None) None
- __init__(serializer: BufferedIncrementalPacketSerializer[_T_SentDTOPacket, _T_ReceivedDTOPacket, _T_Buffer], converter: AbstractPacketConverterComposite[_T_SentPacket, _T_ReceivedPacket, _T_SentDTOPacket, _T_ReceivedDTOPacket]) None
- Parameters:
serializer – The buffered incremental serializer to use.
converter – The converter to use.
- create_buffer(sizehint: int) _T_Buffer
Called to allocate a new receive buffer.
See
BufferedIncrementalPacketSerializer.create_deserializer_buffer()for details.- Return type:
_T_Buffer
- generate_chunks(packet: _T_SentPacket) Generator[bytes]
Serializes a Python object to a raw packet part by part.
- build_packet_from_buffer(buffer: _T_Buffer) Generator[int | None, int, tuple[_T_ReceivedPacket, bytes | bytearray | memoryview | collections.abc.Buffer]]
Creates a Python object representing the raw packet.
- Parameters:
buffer (_T_Buffer) – The buffer allocated by
create_buffer().- Raises:
StreamProtocolParseError – in case of deserialization error.
StreamProtocolParseError – in case of conversion error (if there is a converter).
RuntimeError – The serializer raised
DeserializeErrorinstead ofIncrementalDeserializeError.
- Yields:
until the whole packet has been deserialized.
See
BufferedIncrementalPacketSerializer.buffered_incremental_deserialize()for details.- Returns:
a tuple with the deserialized Python object and the unused trailing data.
See
BufferedIncrementalPacketSerializer.buffered_incremental_deserialize()for details.- Return type:
Generator[int | None, int, tuple[_T_ReceivedPacket, bytes | bytearray | memoryview | collections.abc.Buffer]]
- class easynetwork.protocol.DatagramProtocol
Bases:
Generic[_T_SentPacket,_T_ReceivedPacket]A protocol object class for datagram communication.
- __init__(serializer: AbstractPacketSerializer[_T_SentPacket, _T_ReceivedPacket], converter: None = None) None
- __init__(serializer: AbstractPacketSerializer[_T_SentDTOPacket, _T_ReceivedDTOPacket], converter: AbstractPacketConverterComposite[_T_SentPacket, _T_ReceivedPacket, _T_SentDTOPacket, _T_ReceivedDTOPacket]) None
- Parameters:
serializer – The serializer to use.
converter – The converter to use.
- build_packet_from_datagram(datagram: bytes) _T_ReceivedPacket
Creates a Python object representing the raw datagram packet.
- Parameters:
- Raises:
DatagramProtocolParseError – in case of deserialization error.
DatagramProtocolParseError – in case of conversion error (if there is a converter).
- Returns:
the deserialized packet.
- Return type:
_T_ReceivedPacket
- class easynetwork.protocol.StreamProtocol
Bases:
Generic[_T_SentPacket,_T_ReceivedPacket]A protocol object class for connection-oriented stream communication.
- __init__(serializer: AbstractIncrementalPacketSerializer[_T_SentPacket, _T_ReceivedPacket], converter: None = None) None
- __init__(serializer: AbstractIncrementalPacketSerializer[_T_SentDTOPacket, _T_ReceivedDTOPacket], converter: AbstractPacketConverterComposite[_T_SentPacket, _T_ReceivedPacket, _T_SentDTOPacket, _T_ReceivedDTOPacket]) None
- Parameters:
serializer – The incremental serializer to use.
converter – The converter to use.
- generate_chunks(packet: _T_SentPacket) Generator[bytes]
Serializes a Python object to a raw packet part by part.
- build_packet_from_chunks() Generator[None, bytes, tuple[_T_ReceivedPacket, bytes]]
Creates a Python object representing the raw packet.
- Raises:
StreamProtocolParseError – in case of deserialization error.
StreamProtocolParseError – in case of conversion error (if there is a converter).
RuntimeError – The serializer raised
DeserializeErrorinstead ofIncrementalDeserializeError.
- Yields:
- Returns:
a tuple with the deserialized Python object and the unused trailing data.
- Return type:
See also
- How-to — Communication Protocols
Describes where and when a protocol object is used.