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

1from dataclasses import dataclass 

2from .type import Type 

3from functools import cached_property 

4from .common import Element, FixedLengthElement 

5from typing import override 

6 

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 """ 

13 

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 

17 

18 

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 """ 

24 

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 

31 

32 

33 @cached_property 

34 @override 

35 def total_length(self) -> int: 

36 return self.encoding_type.total_length 

37 

38 @override 

39 def lazy_bind(self, types): 

40 self.encoding_type = types[self.encoding_type_name] 

41