mltk.utils.bin2header

Utilities for generating a “C” header file from binary data

See the source code on Github: mltk/utils/bin2header.py

Functions

bin2header(input[, output_path, var_name, ...])

Generate C header file from binary input file

main()

bin2header(input, output_path=None, var_name='DATA', length_var_name='DATA_LENGTH', dtype='const unsigned char', attributes=None, prepend_lines=None, fmt_str=None, prepend_header=True)[source]

Generate C header file from binary input file

Parameters:
  • input (Union[str, bytes, List[int], List[float]]) – Either path to binary file or binary contents of previously loaded file, or list of integers or floats

  • output_path (Union[bool, str, IOBase]) – Output file path or io stream. Use input with .h appended if True

  • var_name (str) – Name of C array

  • length_var_name (str) – Name of variable to hold length of C array in bytes

  • attributes (str) – Attributes to prepend C array variable

  • dtype (str) – The data type of the C array

  • prepend_lines (List[int]) – List of C lines of code to prepend before the generated array data e.g.: #include <stdint.h>

  • fmt_str (str) – The formatting string to use for each entry in the data, e.g.: 0x{:02X} If omitted then it is automatically determined based on the given data

Return type:

str

Returns:

Generated header as a string

main()[source]