Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/dissect/cstruct/types/void.py: 68%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

28 statements  

1from __future__ import annotations 

2 

3from typing import TYPE_CHECKING, Any, BinaryIO 

4 

5from dissect.cstruct.types.base import BaseArray, BaseType 

6 

7if TYPE_CHECKING: 

8 from typing_extensions import Self 

9 

10 

11class VoidArray(list, BaseArray): 

12 """Array type representing void elements, primarily used for no-op reading and writing operations.""" 

13 

14 @classmethod 

15 def __default__(cls) -> Self: 

16 return cls() 

17 

18 @classmethod 

19 def _read(cls, stream: BinaryIO, context: dict[str, Any] | None = None) -> Self: 

20 return cls() 

21 

22 @classmethod 

23 def _write(cls, stream: BinaryIO, data: bytes) -> int: 

24 return 0 

25 

26 

27class Void(BaseType): 

28 """Void type.""" 

29 

30 ArrayType = VoidArray 

31 

32 def __bool__(self) -> bool: 

33 return False 

34 

35 def __eq__(self, value: object) -> bool: 

36 return isinstance(value, Void) 

37 

38 @classmethod 

39 def _read(cls, stream: BinaryIO, context: dict[str, Any] | None = None) -> Self: 

40 return cls.__new__(cls) 

41 

42 @classmethod 

43 def _write(cls, stream: BinaryIO, data: Void) -> int: 

44 return 0