19 lines
786 B
Python
19 lines
786 B
Python
def calculate_offsets(db_struct, current_offset=0, parent=None):
|
|
"""
|
|
Recursively calculate byte offsets for each field in the DB structure considering special types.
|
|
"""
|
|
last_key_was_bool = False
|
|
last_bit_offset = 0 # To track bit offsets within a byte
|
|
if isinstance(db_struct, dict):
|
|
for key, value in list(db_struct.items()):
|
|
if isinstance(value, dict):
|
|
if "type" in value and not "offset" in value:
|
|
|
|
current_offset = calculate_offsets(
|
|
value, current_offset, value
|
|
) # Recurse into nested structs
|
|
|
|
elif isinstance(db_struct, list):
|
|
for item in db_struct:
|
|
current_offset = calculate_offsets(item, current_offset, parent)
|
|
return current_offset |