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

18 statements  

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

1from .common import FixedLengthElement 

2from dataclasses import dataclass 

3from functools import cached_property 

4from typing import override 

5 

6@dataclass 

7class Composite(FixedLengthElement): 

8 """ 

9 Represents a composite element in the schema. 

10 """ 

11 

12 elements: list[FixedLengthElement] # List of elements contained in this composite 

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

14 since_version: int = 0 # Version since this composite is present 

15 deprecated: int|None = None # Version this composite was deprecated, if applicable 

16 

17 @cached_property 

18 @override 

19 def total_length(self) -> int: 

20 """ 

21 Returns the total length of the composite in bytes. 

22 This is the sum of the lengths of all contained elements. 

23 """ 

24 # TODO: handle offset of elements 

25 return sum(element.total_length for element in self.elements) 

26 

27 @override 

28 def lazy_bind(self, types): 

29 for element in self.elements: 

30 element.lazy_bind(types)