hexrec.records.merge_records#

hexrec.records.merge_records(records, input_types=None, output_type=None, split_args=None, split_kwargs=None, build_args=None, build_kwargs=None)[source]#

Merges data records.

Merges multiple sequences of data records where each sequence overwrites overlapping data of the previous sequences.

Parameters:
  • records (list of records) – A vector of record sequences. If input_types is not None, sequence generators are supported for the vector and its nested sequences. Only data records are kept.

  • input_types (list of types) – Selects the record type for each of the sequences in data_records. None will choose that of the first element of the (indexable) sequence.

  • output_type (type) – Selects the output record type. None will choose that of the first input_types.

  • 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 – Merged records.

Example

>>> from hexrec.utils import chop_blocks
>>> from bytesparse import Memory
>>> from hexrec.formats.intel import Record as IntelRecord
>>> from hexrec.formats.motorola import Record as MotorolaRecord
>>> data1 = bytes(range(0, 32))
>>> data2 = bytes(range(96, 128))
>>> blocks1 = list(chop_blocks(data1, 16, start=0))
>>> blocks2 = list(chop_blocks(data2, 16, start=96))
>>> records1 = blocks_to_records(blocks1, MotorolaRecord)
>>> records2 = blocks_to_records(blocks2, IntelRecord)
>>> IntelRecord.readdress(records2)
>>> merged_records = merge_records([records1, records2])
>>> merged_blocks = records_to_blocks(merged_records)
>>> merged_blocks == Memory.collapse_blocks(blocks1 + blocks2)
True