Coverage for sbe2/schema/set.py: 100%
25 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-21 19:48 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-21 19:48 +0200
1from dataclasses import dataclass
2from .type import Type
3from functools import cached_property
4from .common import Element, FixedLengthElement
5from typing import override
7@dataclass
8class Choice(Element):
9 """
10 Represents a choice element in the schema.
11 This is used to define a set of alternatives where only one can be selected.
12 """
14 value: int
15 since_version: int = 0 # Version since this choice is present
16 deprecated: int | None = None # Version this choice was deprecated, if applicable
19@dataclass
20class Set(FixedLengthElement):
21 """Represents a set element in the schema.
22 This is used to define a collection of choices that can be selected.
23 """
25 encoding_type_name: str
26 choices: list[Choice]
27 encoding_type: Type = None # Set lazily
28 offset: int | None = None
29 since_version: int = 0
30 deprecated: int | None = None
33 @cached_property
34 @override
35 def total_length(self) -> int:
36 return self.encoding_type.total_length
38 @override
39 def lazy_bind(self, types):
40 self.encoding_type = types[self.encoding_type_name]