Skip to content

packet_sequencer

PacketSequencer

A class for generating packet sequences.

Source code in src/eolib/packet/packet_sequencer.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class PacketSequencer:
    """A class for generating packet sequences."""

    _start: SequenceStart
    _counter: int

    def __init__(self, start: SequenceStart):
        """
        Constructs a new PacketSequencer with the provided SequenceStart.

        Args:
            start (SequenceStart): The sequence start.
        """
        self._start = start
        self._counter = 0

    def next_sequence(self) -> int:
        """
        Returns the next sequence value, updating the sequence counter in the process.

        Note:
            This is not a monotonic operation. The sequence counter increases from 0 to 9 before
            looping back around to 0.

        Returns:
            int: The next sequence value.
        """
        result = self._start.value + self._counter
        self._counter = (self._counter + 1) % 10
        return result

    def set_sequence_start(self, start: SequenceStart) -> None:
        """
        Sets the sequence start, also known as the "starting counter ID".

        Note:
            This does not reset the sequence counter.

        Args:
            start (SequenceStart): The new sequence start.
        """
        self._start = start

__init__(start)

Constructs a new PacketSequencer with the provided SequenceStart.

Parameters:

Name Type Description Default
start SequenceStart

The sequence start.

required
Source code in src/eolib/packet/packet_sequencer.py
10
11
12
13
14
15
16
17
18
def __init__(self, start: SequenceStart):
    """
    Constructs a new PacketSequencer with the provided SequenceStart.

    Args:
        start (SequenceStart): The sequence start.
    """
    self._start = start
    self._counter = 0

next_sequence()

Returns the next sequence value, updating the sequence counter in the process.

Note

This is not a monotonic operation. The sequence counter increases from 0 to 9 before looping back around to 0.

Returns:

Name Type Description
int int

The next sequence value.

Source code in src/eolib/packet/packet_sequencer.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def next_sequence(self) -> int:
    """
    Returns the next sequence value, updating the sequence counter in the process.

    Note:
        This is not a monotonic operation. The sequence counter increases from 0 to 9 before
        looping back around to 0.

    Returns:
        int: The next sequence value.
    """
    result = self._start.value + self._counter
    self._counter = (self._counter + 1) % 10
    return result

set_sequence_start(start)

Sets the sequence start, also known as the "starting counter ID".

Note

This does not reset the sequence counter.

Parameters:

Name Type Description Default
start SequenceStart

The new sequence start.

required
Source code in src/eolib/packet/packet_sequencer.py
35
36
37
38
39
40
41
42
43
44
45
def set_sequence_start(self, start: SequenceStart) -> None:
    """
    Sets the sequence start, also known as the "starting counter ID".

    Note:
        This does not reset the sequence counter.

    Args:
        start (SequenceStart): The new sequence start.
    """
    self._start = start