Skip to content

Commit

Permalink
Rename data_length to be more descriptive
Browse files Browse the repository at this point in the history
  • Loading branch information
kg583 committed Sep 8, 2023
1 parent fb3384d commit c8753d7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion tivars/types/gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions tivars/types/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions tivars/types/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
18 changes: 9 additions & 9 deletions tivars/var.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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:
"""
Expand All @@ -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
"""
Expand Down Expand Up @@ -520,15 +520,15 @@ 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:
"""
: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']:
Expand Down Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit c8753d7

Please sign in to comment.