1
0
mirror of synced 2025-01-05 13:34:22 +01:00

classes.py: Refactor how raw_bytes is constructed

This commit is contained in:
Viv 2023-07-31 08:55:12 -04:00
parent d7a817b9ea
commit 5e52e5c71d

View File

@ -336,18 +336,17 @@ class FumenHeader:
@property @property
def raw_bytes(self) -> bytes: def raw_bytes(self) -> bytes:
"""Represent the header values as a string of raw bytes.""" """Represent the header values as a string of raw bytes."""
value_list = [] format_string, value_list = '', []
format_string = self.order
for byte_field in fields(self): for byte_field in fields(self):
value = getattr(self, byte_field.name) value = getattr(self, byte_field.name)
if byte_field.name == "order": if byte_field.name == "order":
pass format_string = value + format_string
elif byte_field.name == "b000_b431_timing_windows": elif byte_field.name == "b000_b431_timing_windows":
value_list.extend(list(value))
format_string += "f" * len(value) format_string += "f" * len(value)
value_list.extend(list(value))
else: else:
value_list.append(value)
format_string += "i" format_string += "i"
value_list.append(value)
raw_bytes = struct.pack(format_string, *value_list) raw_bytes = struct.pack(format_string, *value_list)
assert len(raw_bytes) == 520 assert len(raw_bytes) == 520
return raw_bytes return raw_bytes