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