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

15 statements  

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

1import enum 

2from dataclasses import dataclass 

3 

4class Presence(enum.StrEnum): 

5 'Matches the `presence` attribute in the schema.' 

6 REQUIRED = "required" 

7 OPTIONAL = "optional" 

8 CONSTANT = "constant" 

9 

10class ByteOrder(enum.StrEnum): 

11 'Matches the `byteOrder` attribute in the schema.' 

12 BIG_ENDIAN = "bigEndian" 

13 LITTLE_ENDIAN = "littleEndian" 

14 

15@dataclass 

16class Element: 

17 name: str 

18 description: str 

19 

20 

21@dataclass 

22class FixedLengthElement(Element): 

23 """ 

24 Represents an element with a fixed length in bytes. 

25 This is a base class for elements that have a defined size. 

26 """ 

27 

28 @property 

29 def total_length(self) -> int: # pragma: no cover 

30 """ 

31 Returns the total length of the element in bytes. 

32 This is a placeholder and should be overridden in subclasses. 

33 """ 

34 raise NotImplementedError("Subclasses must implement total_length") 

35 

36 

37 def lazy_bind(self, types: 'Types') -> None: # pragma: no cover 

38 """ 

39 Binds types to other types lazily, so that all types are already defined when this is called. 

40 This is a placeholder and should be overridden in subclasses. 

41 """ 

42 raise NotImplementedError("Subclasses must implement lazy_bind")