hexrec.records.blocks_to_records#

hexrec.records.blocks_to_records(blocks, record_type, split_args=None, split_kwargs=None, build_args=None, build_kwargs=None)[source]#

Converts blocks to records.

Parameters:
  • blocks (list of blocks) – A sequence of non-contiguous blocks, sorted by start address.

  • record_type (type) – Output record type.

  • split_args (list) – Positional arguments for Record.split().

  • split_kwargs (dict) – Keyword arguments for Record.split().

  • build_args (list) – Positional arguments for Record.build_standalone().

  • build_kwargs (dict) – Keyword arguments for Record.build_standalone().

Returns:

list of records – Records holding data from blocks.

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