diff --git a/construct_typed/tstruct.py b/construct_typed/tstruct.py index d818b74..4e18fa6 100644 --- a/construct_typed/tstruct.py +++ b/construct_typed/tstruct.py @@ -93,7 +93,7 @@ class _TStruct(Adapter[t.Any, t.Any, ContainerType, BuildTypes]): def __init__( self, container_type: t.Type[ContainerType], - swapped: bool = False, + reverse: bool = False, add_offsets: bool = False, ) -> None: if not issubclass(container_type, TContainerMixin): @@ -107,12 +107,12 @@ class _TStruct(Adapter[t.Any, t.Any, ContainerType, BuildTypes]): "'{}' has to be a 'dataclasses.dataclass'".format(repr(container_type)) ) self.container_type = container_type - self.swapped = swapped + self.reverse = reverse self.add_offsets = add_offsets # get all fields from the dataclass fields = dataclasses.fields(self.container_type) - if self.swapped: + if self.reverse: fields = tuple(reversed(fields)) # extract the construct formats from the struct_type @@ -192,7 +192,7 @@ class TStruct(_TStruct[ContainerType, ContainerType]): def __new__( cls, container_type: t.Type[ContainerType], - swapped: bool = False, + reverse: bool = False, add_offsets: bool = False, ) -> "TStruct[ContainerType]": ... @@ -213,7 +213,7 @@ class TBitStruct(_TStruct[ContainerType, ContainerType]): def __new__( cls, container_type: t.Type[ContainerType], - swapped: bool = False, + reverse: bool = False, add_offsets: bool = False, ) -> "TBitStruct[ContainerType]": ... diff --git a/tests/test_typed.py b/tests/test_typed.py index acff21d..ab16b2f 100644 --- a/tests/test_typed.py +++ b/tests/test_typed.py @@ -99,21 +99,21 @@ def test_tstruct() -> None: assert c.b.subcon is cs.Int8ub -def test_tstruct_swapped() -> None: +def test_tstruct_reverse() -> None: @dataclasses.dataclass class TestContainer(cst.TContainerMixin): a: int = cst.sfield(cs.Int16ub) b: int = cst.sfield(cs.Int8ub) common( - cst.TStruct(TestContainer, swapped=True), + cst.TStruct(TestContainer, reverse=True), b"\x02\x00\x01", TestContainer(a=1, b=2), 3, ) normal = cst.TStruct(TestContainer) - swapped = cst.TStruct(TestContainer, swapped=True) - assert str(normal.parse(b"\x00\x01\x02")) == str(swapped.parse(b"\x02\x00\x01")) + reverse = cst.TStruct(TestContainer, reverse=True) + assert str(normal.parse(b"\x00\x01\x02")) == str(reverse.parse(b"\x02\x00\x01")) def test_tstruct_add_offsets() -> None: