Protocols

Communication protocol objects module.

class easynetwork.protocol.BufferedStreamProtocol

Bases: Generic

A specialization of StreamProtocol in 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:
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.

Parameters:

packet (SentPacket) – The packet as a Python object to serialize.

Yields:

all the parts of the packet.

Return type:

Generator[bytes]

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:
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[ReceivedPacket, Buffer]]

class easynetwork.protocol.DatagramProtocol

Bases: Generic

A 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:
make_datagram(packet: SentPacket) bytes

Serializes a Python object to a raw datagram packet.

Parameters:

packet (SentPacket) – The packet as a Python object to serialize.

Returns:

the serialized packet.

Return type:

bytes

build_packet_from_datagram(datagram: bytes) ReceivedPacket

Creates a Python object representing the raw datagram packet.

Parameters:

datagram (bytes) – The datagram packet to deserialize.

Raises:
Returns:

the deserialized packet.

Return type:

ReceivedPacket

class easynetwork.protocol.StreamProtocol

Bases: Generic

A 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:
generate_chunks(packet: SentPacket) Generator[bytes]

Serializes a Python object to a raw packet part by part.

Parameters:

packet (SentPacket) – The packet as a Python object to serialize.

Yields:

all the parts of the packet.

Return type:

Generator[bytes]

build_packet_from_chunks() Generator[None, bytes, tuple[ReceivedPacket, bytes]]

Creates a Python object representing the raw packet.

Raises:
Yields:

None until the whole packet has been deserialized.

Returns:

a tuple with the deserialized Python object and the unused trailing data.

Return type:

Generator[None, bytes, tuple[ReceivedPacket, bytes]]


See also

How-to — Communication Protocols

Describes where and when a protocol object is used.