2020-12-31 17:11:21 +01:00
|
|
|
import typing as t
|
|
|
|
|
import construct as cs
|
|
|
|
|
from .generic_wrapper import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TArray(
|
|
|
|
|
Adapter[
|
2021-01-01 13:55:19 +01:00
|
|
|
SubconParsedType,
|
|
|
|
|
SubconBuildTypes,
|
|
|
|
|
t.List[SubconParsedType],
|
|
|
|
|
t.List[SubconParsedType],
|
2020-12-31 17:11:21 +01:00
|
|
|
]
|
|
|
|
|
):
|
|
|
|
|
"""
|
|
|
|
|
Adapter for an Array, that transforms the "ListContainer" to an standard "list" while parsing
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
|
self,
|
|
|
|
|
count: ConstantOrContextLambda[int],
|
2021-01-01 13:55:19 +01:00
|
|
|
subcon: Construct[SubconParsedType, SubconBuildTypes],
|
2020-12-31 17:11:21 +01:00
|
|
|
discard: bool = False,
|
|
|
|
|
) -> None:
|
|
|
|
|
# init adatper
|
|
|
|
|
super(TArray, self).__init__(cs.Array(count, subcon, discard)) # type: ignore
|
|
|
|
|
|
|
|
|
|
def _decode(
|
2021-01-01 15:41:36 +01:00
|
|
|
self, obj: SubconParsedType, context: Context, path: PathType
|
2020-12-31 17:11:21 +01:00
|
|
|
) -> ParsedType:
|
|
|
|
|
return list(obj) # type: ignore
|
|
|
|
|
|
|
|
|
|
def _encode(
|
|
|
|
|
self,
|
2021-01-01 15:41:36 +01:00
|
|
|
obj: t.List[SubconParsedType],
|
2020-12-31 17:11:21 +01:00
|
|
|
context: Context,
|
|
|
|
|
path: PathType,
|
2021-01-01 15:41:36 +01:00
|
|
|
) -> SubconBuildTypes:
|
2020-12-31 17:11:21 +01:00
|
|
|
return obj # type: ignore
|