hexrec.records.convert_records#

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

Converts records to another type.

Parameters:
  • records (list of records) – A sequence of Record elements. Sequence generators supported if input_type is specified.

  • input_type (type) – Explicit type of records elements. If None, it is taken from the first element of the (indexable) records sequence.

  • output_type (type) – Explicit output type. If None, it is reassigned as input_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 – Converted records.

Examples

>>> from hexrec.formats.intel import Record as IntelRecord
>>> from hexrec.formats.motorola import Record as MotorolaRecord
>>> motorola = list(MotorolaRecord.split(bytes(range(256))))
>>> intel = list(IntelRecord.split(bytes(range(256))))
>>> converted = convert_records(motorola, output_type=IntelRecord)
>>> converted == intel
True
>>> from hexrec.formats.intel import Record as IntelRecord
>>> from hexrec.formats.motorola import Record as MotorolaRecord
>>> motorola = list(MotorolaRecord.split(bytes(range(256))))
>>> intel = list(IntelRecord.split(bytes(range(256))))
>>> converted = convert_records(intel, output_type=MotorolaRecord)
>>> converted == motorola
True