hexrec.records.records_to_blocks#
- hexrec.records.records_to_blocks(records)[source]#
Converts records to blocks.
Extracts all the data records, collapses them in the order they compare in records, and merges the collapsed blocks. Returns sequence of non-contiguous blocks, sorted by start address.
- Parameters:
records (list of records) – Sequence of records to convert to blocks.
- Returns:
list of blocks – Blocks holding data from records.
Example
>>> from hexrec.utils import chop_blocks >>> from bytesparse import Memory >>> from hexrec.formats.motorola import Record as MotorolaRecord >>> data = bytes(range(256)) >>> blocks = list(chop_blocks(data, 16)) >>> records = blocks_to_records(blocks, MotorolaRecord) >>> records_to_blocks(records) == Memory.collapse_blocks(blocks) True