base
Base sender implementation for the coding experiments library.
This module provides a base implementation of the Sender protocol that can be extended by concrete sender implementations. It handles common functionality like encoder integration and message tracking.
- class codinglab.senders.base.BaseSender(encoder, logger=<codinglab.logger.NullLogger object>)[source]
Bases:
Sender[SourceChar,ChannelChar]Base implementation of the Sender protocol.
This class provides common functionality for all sender implementations, including encoder integration and tracking of the last generated message. Concrete sender implementations should inherit from this class and implement the message_stream method.
- Parameters:
encoder (Encoder[SourceChar, ChannelChar])
logger (TransmissionLogger)
- _encoder
Encoder instance for converting source to channel symbols
- _last_message
The last generated source message, if any
- _logger
A TransmissionLogger instance, default NullLogger
- __init__(encoder, logger=<codinglab.logger.NullLogger object>)[source]
Initialize the base sender with an encoder.
- Parameters:
encoder (
Encoder[TypeVar(SourceChar),TypeVar(ChannelChar)]) – Encoder instance for converting source messages to channel symbolslogger (TransmissionLogger)
- Return type:
None
- property alphabet: Sequence[SourceChar]
Get the source alphabet from the encoder’s code table.
This implementation extracts the alphabet from the encoder’s code table. If no code table is available, returns an empty list.
- Returns:
Sequence of source symbols that can appear in messages
Note
Subclasses may override this to provide a different alphabet source or validation mechanism.