Coverage for sbe2/schema/enum.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-21 19:48 +0200

1from .common import FixedLengthElement, Element 

2from .type import Type 

3from dataclasses import dataclass 

4from functools import cached_property 

5from typing import override 

6 

7@dataclass 

8class ValidValue(Element): 

9 """ 

10 Represents a valid value for an enumeration. 

11 This is used to define the named values in an enum. 

12 """ 

13 

14 value: int | bytes # The integer or char value associated with this name 

15 since_version: int = 0 # Version since this value is present 

16 deprecated: int | None = None # Version this value was deprecated, if applicable 

17 enum: 'Enum' = None # set lazily during parsing 

18 

19@dataclass 

20class Enum(FixedLengthElement): 

21 """ 

22 Represents an enumeration element in the schema. 

23 This is used to define a set of named values. 

24 """ 

25 

26 valid_values: list[ValidValue] 

27 

28 encoding_type_name: str # The name of encoding type for the enum values 

29 encoding_type:Type = None # The encoding type for the enum values. Set lazily. 

30 since_version: int = 0 # Version since this enum is present 

31 deprecated: int|None = None # Version this enum was deprecated, if applicable  

32 offset: int|None = None # Offset in bytes, if applicable 

33 

34 @cached_property 

35 @override 

36 def total_length(self): 

37 return self.encoding_type.total_length 

38 

39 @override 

40 def lazy_bind(self, types): 

41 self.encoding_type = types[self.encoding_type_name]