|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -from typing import Any, BinaryIO |
| 3 | +from typing import TYPE_CHECKING, Any, BinaryIO |
4 | 4 |
|
5 | | -from dissect.cstruct.types.base import BaseType |
| 5 | +from dissect.cstruct.types.base import BaseArray, BaseType |
| 6 | + |
| 7 | +if TYPE_CHECKING: |
| 8 | + from typing_extensions import Self |
| 9 | + |
| 10 | + |
| 11 | +class 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 |
6 | 25 |
|
7 | 26 |
|
8 | 27 | class Void(BaseType): |
9 | 28 | """Void type.""" |
10 | 29 |
|
| 30 | + ArrayType = VoidArray |
| 31 | + |
11 | 32 | def __bool__(self) -> bool: |
12 | 33 | return False |
13 | 34 |
|
14 | 35 | def __eq__(self, value: object) -> bool: |
15 | 36 | return isinstance(value, Void) |
16 | 37 |
|
17 | 38 | @classmethod |
18 | | - def _read(cls, stream: BinaryIO, context: dict[str, Any] | None = None) -> Void: |
| 39 | + def _read(cls, stream: BinaryIO, context: dict[str, Any] | None = None) -> Self: |
19 | 40 | return cls.__new__(cls) |
20 | 41 |
|
21 | | - @classmethod |
22 | | - def _read_0(cls, stream: BinaryIO, context: dict[str, Any] | None = None) -> Void: |
23 | | - return [cls.__new__(cls)] |
24 | | - |
25 | 42 | @classmethod |
26 | 43 | def _write(cls, stream: BinaryIO, data: Void) -> int: |
27 | 44 | return 0 |
0 commit comments