fixed

Fixed messages sender implementation for the coding experiments library.

This module provides a sender implementation that cycles through a fixed set of pre-defined messages. It’s useful for reproducible experiments and testing scenarios where specific message sequences are required.

class codinglab.senders.fixed.FixedMessagesSender(encoder, messages, logger=<codinglab.logger.NullLogger object>)[source]

Bases: BaseSender[SourceChar, ChannelChar]

Sender that cycles through a fixed set of source messages.

This sender repeatedly sends messages from a provided list, wrapping around to the beginning when the end is reached. Each message is assigned a unique ID for tracking purposes.

Parameters:
_messages

List of source messages to send

_message_id

Counter for assigning unique message IDs

_index

Current position in the messages list

__init__(encoder, messages, logger=<codinglab.logger.NullLogger object>)[source]

Initialize the fixed messages sender.

Parameters:
  • encoder (Encoder[TypeVar(SourceChar), TypeVar(ChannelChar)]) – Encoder instance for converting source to channel symbols

  • messages (List[Sequence[TypeVar(SourceChar)]]) – List of source messages to send

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

Raises:

ValueError – If messages list is empty

Return type:

None

message_stream(stream_len=None)[source]

Generate a stream of encoded messages from the fixed list.

If stream_len is not specified, generates one encoded message for each source message in the list. If stream_len exceeds the number of messages, the sender wraps around to the beginning.

Parameters:

stream_len (Optional[int]) – Number of messages to generate. If None, uses the length of the messages list.

Yields:

Encoded messages wrapped in Message containers with unique IDs

Raises:

ValueError – If stream_len <= 0

Return type:

Iterator[Message[TypeVar(ChannelChar)]]

reset()[source]

Reset the sender to its initial state.

This method resets the message index and ID counter, allowing the sender to restart from the beginning of the messages list.

Return type:

None