Protocols
Communication protocol objects module.
- class easynetwork.protocol.BufferedStreamProtocol
Bases:
GenericA specialization of
StreamProtocolin order to use a buffered incremental serializer.- __init__(serializer: BufferedIncrementalPacketSerializer[SentPacket, ReceivedPacket, BufferType], converter: None = None) None
- __init__(serializer: BufferedIncrementalPacketSerializer[SentDTOPacket, ReceivedDTOPacket, BufferType], converter: AbstractPacketConverterComposite[SentPacket, ReceivedPacket, SentDTOPacket, ReceivedDTOPacket]) None
- Parameters:
serializer – The buffered incremental serializer to use.
converter – The converter to use.
- create_buffer(sizehint: int) BufferType
Called to allocate a new receive buffer.
See
BufferedIncrementalPacketSerializer.create_deserializer_buffer()for details.- Return type:
BufferType
- generate_chunks(packet: SentPacket) Generator[bytes]
Serializes a Python object to a raw packet part by part.
- build_packet_from_buffer(buffer: BufferType) Generator[int | None, int, tuple[ReceivedPacket, Buffer]]
Creates a Python object representing the raw packet.
- Parameters:
buffer (BufferType) – 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:
- class easynetwork.protocol.DatagramProtocol
Bases:
GenericA protocol object class for datagram communication.
- __init__(serializer: AbstractPacketSerializer[SentPacket, ReceivedPacket], converter: None = None) None
- __init__(serializer: AbstractPacketSerializer[SentDTOPacket, ReceivedDTOPacket], converter: AbstractPacketConverterComposite[SentPacket, ReceivedPacket, SentDTOPacket, ReceivedDTOPacket]) None
- Parameters:
serializer – The serializer to use.
converter – The converter to use.
- build_packet_from_datagram(datagram: bytes) 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:
ReceivedPacket
- class easynetwork.protocol.StreamProtocol
Bases:
GenericA protocol object class for connection-oriented stream communication.
- __init__(serializer: AbstractIncrementalPacketSerializer[SentPacket, ReceivedPacket], converter: None = None) None
- __init__(serializer: AbstractIncrementalPacketSerializer[SentDTOPacket, ReceivedDTOPacket], converter: AbstractPacketConverterComposite[SentPacket, ReceivedPacket, SentDTOPacket, ReceivedDTOPacket]) None
- Parameters:
serializer – The incremental serializer to use.
converter – The converter to use.
- generate_chunks(packet: SentPacket) Generator[bytes]
Serializes a Python object to a raw packet part by part.
- build_packet_from_chunks() Generator[None, bytes, tuple[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.