base

Base receiver implementation for the coding experiments library.

This module provides a base implementation of the Receiver protocol that handles message decoding and tracking. It can be extended with additional functionality like error detection, validation, or statistics collection.

class codinglab.receivers.base.BaseReceiver(decoder, logger=<codinglab.logger.NullLogger object>)[source]

Bases: Receiver[SourceChar, ChannelChar]

Base implementation of the Receiver protocol.

This class provides common functionality for receiving and decoding messages from a channel. It tracks the last successfully decoded message and can be extended with additional processing logic.

Parameters:
__init__(decoder, logger=<codinglab.logger.NullLogger object>)[source]

Initialize the base receiver with a decoder and logger.

Parameters:
  • decoder (Decoder[TypeVar(SourceChar), TypeVar(ChannelChar)]) – Decoder instance for converting channel symbols back to source messages

  • logger (TransmissionLogger) – Logger for recording transmission events (defaults to NullLogger)

Return type:

None

receive_stream(messages)[source]

Receive and decode a stream of messages.

This implementation decodes each message and yields True for successful decoding. It logs both the reception and decoding events.

Parameters:

messages (Iterator[Message[TypeVar(ChannelChar)]]) – Iterator of messages received from a channel

Yields:

True for each successfully received and decoded message

Return type:

Iterator[bool]

Note

This implementation always returns True; subclasses may override to perform validation and return False for failed messages.

get_last_message()[source]

Get the last successfully decoded message.

Return type:

Optional[Message[TypeVar(SourceChar)]]

Returns:

The last decoded source message, or None if no messages have been successfully decoded yet