Skip to content

Commit

Permalink
handle VLSD samples split between SDBLOCKs
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhrisca committed Aug 26, 2024
1 parent 498065f commit 117550e
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/asammdf/blocks/mdf_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,13 +1228,13 @@ def _load_signal_data(
"""

data = []

if group is not None and index is not None:
info_blocks = group.signal_data[index]

if info_blocks is not None:
if start_offset is None and end_offset is None:
data = []

for info in group.get_signal_data_blocks(index):
address, original_size, compressed_size, block_type, param = (
info.address,
Expand Down Expand Up @@ -1267,9 +1267,15 @@ def _load_signal_data(

data.append(new_data)

data = b"".join(data)

else:

data = bytearray()

start_offset = int(start_offset)
end_offset = int(end_offset)
last_sample_start = end_offset - start_offset

current_offset = 0

Expand Down Expand Up @@ -1307,22 +1313,23 @@ def _load_signal_data(
elif block_type == v4c.DZ_BLOCK_LZ:
new_data = lz_decompress(new_data)

if current_offset + original_size > end_offset:
start_index = max(0, start_offset - current_offset)
(last_sample_size,) = UINT32_uf(new_data, end_offset - current_offset)
data.append(new_data[start_index : end_offset - current_offset + last_sample_size + 4])
if start_offset > current_offset:
data.extend(new_data[start_offset - current_offset :])
else:
data.extend(new_data)

break
current_offset += original_size

else:
if start_offset > current_offset:
data.append(new_data[start_offset - current_offset :])
else:
data.append(new_data)
if (current_data_size := len(data)) >= last_sample_start + 4:
(last_sample_size,) = UINT32_uf(data, last_sample_start)
required_size = last_sample_start + 4 + last_sample_size
if required_size <= current_data_size:
data = bytes(data[:required_size])
break

current_offset += original_size
else:
data = bytes(data)

data = b"".join(data)
else:
data = b""
else:
Expand Down

0 comments on commit 117550e

Please sign in to comment.