diff --git a/tests/__init__.py b/tests/__init__.py index 079cadf..1fb8d31 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -58,14 +58,14 @@ def test_all_sections(self): test_var.entries[0].raw.version + test_var.entries[0].raw.archived) self.assertEqual(test_var.entries[0].meta, - test_var.entries[0].raw.data_length + test_var.entries[0].raw.type_id + + test_var.entries[0].raw.calc_data_length + test_var.entries[0].raw.type_id + test_var.entries[0].raw.name + test_var.entries[0].raw.version + test_var.entries[0].raw.archived) self.assertEqual(test_var.entries[0].raw.calc_data, bytearray(b'\x03\x00\xef\x001')) self.assertEqual(test_var.entries[0].bytes(), test_var.entries[0].raw.meta_length + test_var.entries[0].raw.meta + - test_var.entries[0].raw.data_length + test_var.entries[0].raw.calc_data) + test_var.entries[0].raw.calc_data_length + test_var.entries[0].raw.calc_data) self.assertEqual(test_var.checksum, b'M\x03') diff --git a/tivars/types/gdb.py b/tivars/types/gdb.py index 0e70a06..4c1fc78 100644 --- a/tivars/types/gdb.py +++ b/tivars/types/gdb.py @@ -289,7 +289,7 @@ def equation(self) -> TIEquation: :return: The `TIEquation` component of this GDB equation """ - return TIEquation(self.bytes()[:-self.data_length] + self.bytes()[-self.data_length + 1:]) + return TIEquation(self.bytes()[:-self.calc_data_length] + self.bytes()[-self.calc_data_length + 1:]) @Loader[str] def load_string(self, string: str, *, model: TIModel = None): diff --git a/tivars/types/list.py b/tivars/types/list.py index 06da015..3c89585 100644 --- a/tivars/types/list.py +++ b/tivars/types/list.py @@ -155,9 +155,9 @@ def supported_by(self, model: TIModel) -> bool: def load_bytes(self, data: bytes | BytesIO): super().load_bytes(data) - if self.data_length // self._E.min_data_length != self.length: + if self.calc_data_length // self._E.min_data_length != self.length: warn(f"The list has an unexpected length " - f"(expected {self.data_length // self._E.min_data_length}, got {self.length}).", + f"(expected {self.calc_data_length // self._E.min_data_length}, got {self.length}).", BytesWarning) @Loader[list] diff --git a/tivars/types/matrix.py b/tivars/types/matrix.py index b23d4d9..9cb341e 100644 --- a/tivars/types/matrix.py +++ b/tivars/types/matrix.py @@ -131,9 +131,9 @@ def supported_by(self, model: TIModel) -> bool: def load_bytes(self, data: bytes | BytesIO): super().load_bytes(data) - if self.data_length // RealEntry.min_data_length != self.size: + if self.calc_data_length // RealEntry.min_data_length != self.size: warn(f"The matrix has an unexpected size " - f"(expected {self.data_length // RealEntry.min_data_length}, got {self.size}).", + f"(expected {self.calc_data_length // RealEntry.min_data_length}, got {self.size}).", BytesWarning) def load_data_section(self, data: BytesIO): diff --git a/tivars/var.py b/tivars/var.py index 2896de8..97898c1 100644 --- a/tivars/var.py +++ b/tivars/var.py @@ -272,7 +272,7 @@ class Raw: __slots__ = "meta_length", "type_id", "name", "version", "archived", "calc_data" @property - def data_length(self) -> bytes: + def calc_data_length(self) -> bytes: """ :return: The length of this entry's data portion """ @@ -301,9 +301,9 @@ def bytes(self) -> bytes: :return: The bytes contained in this entry """ - return self.meta_length + self.data_length + \ + return self.meta_length + self.calc_data_length + \ self.type_id + self.name + self.version + self.archived + \ - self.data_length + self.calc_data + self.calc_data_length + self.calc_data def __init__(self, init=None, *, for_flash: bool = True, name: str = "UNNAMED", @@ -414,7 +414,7 @@ def __len__(self) -> int: :return: The total length of this entry's bytes """ - return 2 + self.meta_length + 2 + self.data_length + return 2 + self.meta_length + 2 + self.calc_data_length def __str__(self) -> str: """ @@ -432,7 +432,7 @@ def meta_length(self) -> int: """ @property - def data_length(self) -> int: + def calc_data_length(self) -> int: """ The length of the data section of the entry """ @@ -520,7 +520,7 @@ def is_empty(self) -> bool: :return: Whether this entry's data is empty """ - return self.data_length == 0 + return self.calc_data_length == 0 @property def meta(self) -> bytes: @@ -528,7 +528,7 @@ def meta(self) -> bytes: :return: The meta section of this entry """ - return self.raw.data_length + self.raw.type_id + self.raw.name + self.raw.version + self.raw.archived + return self.raw.calc_data_length + self.raw.type_id + self.raw.name + self.raw.version + self.raw.archived @classmethod def get_type(cls, type_id: int) -> Type['TIEntry']: @@ -582,7 +582,7 @@ def clear(self): """ self.raw.calc_data = bytearray(self.leading_bytes) - self.raw.calc_data.extend(bytearray(self.min_data_length - self.data_length)) + self.raw.calc_data.extend(bytearray(self.min_data_length - self.calc_data_length)) def get_min_os(self, data: bytes = None) -> OsVersion: """ @@ -1159,7 +1159,7 @@ def data(self) -> bytes: def clear(self): self.raw.calc_data = bytearray([0, 0, *self.leading_bytes]) - self.raw.calc_data.extend(bytearray(self.min_data_length - self.data_length)) + self.raw.calc_data.extend(bytearray(self.min_data_length - self.calc_data_length)) self.length = len(self.leading_bytes) + len(self.data) def load_bytes(self, data: ByteString):