Skip to content

packet

Packetized data streams.

Packet

Bases: StructLayout

Payload shape for a packetized data stream.

Parameters:

Name Type Description Default
data_shape ShapeLike

Shape of a data token.

8
semantics Semantics

Semantics of the packetized data stream.

LAST
Source code in katsuo/stream/packet.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class Packet(data.StructLayout):
    '''Payload shape for a packetized data stream.

    Args:
        data_shape: Shape of a data token.
        semantics: Semantics of the packetized data stream.
    '''

    class Semantics(enum.Enum):
        '''Semantics of the packetized data stream.'''

        LAST = enum.auto()
        '''Payload has a `last` field that's asserted during the last data transfer of a packet.'''

        FIRST = enum.auto()
        '''Payload has a `first` field that's asserted during the first data transfer of a packet.'''

        FIRST_LAST = enum.auto()
        '''Payload has both `first` and `last` fields.'''

        END = enum.auto()
        '''Payload has an `end` field that's asserted during a separate transfer after the last data transfer of a packet.'''

        @property
        def has_first(self):
            '''True if the semantics includes a `first` field.'''
            return self in {self.FIRST, self.FIRST_LAST}

        @property
        def has_last(self):
            '''True if the semantics includes a `last` field.'''
            return self in {self.LAST, self.FIRST_LAST}

        @property
        def has_end(self):
            '''True if the semantics includes an `end` field.'''
            return self in {self.END}

    def __init__(self, data_shape: ShapeLike = 8, *, semantics: Semantics = Semantics.LAST):
        if not isinstance(semantics, self.Semantics):
            raise TypeError(f'semantics must be of type Packet.Semantics, not {type(semantics)}')

        self.semantics = semantics

        layout = {'data': data_shape}
        if semantics.has_first:
            layout['first'] = 1
        if semantics.has_last:
            layout['last'] = 1
        if semantics.has_end:
            layout['end'] = 1

        super().__init__(layout)

Semantics

Bases: Enum

Semantics of the packetized data stream.

Source code in katsuo/stream/packet.py
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
46
class Semantics(enum.Enum):
    '''Semantics of the packetized data stream.'''

    LAST = enum.auto()
    '''Payload has a `last` field that's asserted during the last data transfer of a packet.'''

    FIRST = enum.auto()
    '''Payload has a `first` field that's asserted during the first data transfer of a packet.'''

    FIRST_LAST = enum.auto()
    '''Payload has both `first` and `last` fields.'''

    END = enum.auto()
    '''Payload has an `end` field that's asserted during a separate transfer after the last data transfer of a packet.'''

    @property
    def has_first(self):
        '''True if the semantics includes a `first` field.'''
        return self in {self.FIRST, self.FIRST_LAST}

    @property
    def has_last(self):
        '''True if the semantics includes a `last` field.'''
        return self in {self.LAST, self.FIRST_LAST}

    @property
    def has_end(self):
        '''True if the semantics includes an `end` field.'''
        return self in {self.END}

END = enum.auto() class-attribute instance-attribute

Payload has an end field that's asserted during a separate transfer after the last data transfer of a packet.

FIRST = enum.auto() class-attribute instance-attribute

Payload has a first field that's asserted during the first data transfer of a packet.

FIRST_LAST = enum.auto() class-attribute instance-attribute

Payload has both first and last fields.

LAST = enum.auto() class-attribute instance-attribute

Payload has a last field that's asserted during the last data transfer of a packet.

has_end property

True if the semantics includes an end field.

has_first property

True if the semantics includes a first field.

has_last property

True if the semantics includes a last field.