Skip to content

Unix Utility for Transforming a Stream into a C++20 Array, Vector, or Array of Strings

License

Notifications You must be signed in to change notification settings

lostjared/bin2cpp20

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bin2cpp20 - Binary to C++20 Source Conversion Tool

Overview

bin2cpp20 is a versatile command-line utility designed to convert binary files/string data into C++20 compliant source code. This enables the embedding of binary/string data directly within C++ applications in a portable and efficient manner. The tool offers flexibility in output formats, including vectors, arrays, and strings, and supports additional options like sorting and Unicode handling.

Motivation

The motivation for this application was to be able to quickly generate arrays of binary/string data that I could embed in my C++20 code. Also to test out my new argument parsing header file argz.hpp.

Demonstration

Here is a video demo of the application: https://youtu.be/umDLwADWRmM

Requirements

  • Fully C++20 compliant environment

Compilation

To compile bin2cpp20, use the following command:

make -f Makefile.ux 

or

mkdir build && cd build
cmake ..
make -j4
sudo make install 

Usage

The basic usage of the tool can be invoked as follows:

bin2cpp20 [options]

Key Features

  • Input from file or standard input: Specify an input binary file or use standard input.
  • Output to standard output or file: Direct the converted C++ source to standard output or a specified file.
  • Variable naming: Define custom variable names for the generated code.
  • Output formats: Choose between vector, array, or string representations of the binary data.
  • Sorting and Unicode options: Sort strings in the output or handle Unicode data correctly.

Options

  • -i, --input <file/stdin>: Specify the input source. Use "stdin" to read from standard input.
  • -o, --output <file>: Specify the output file. If not provided, output will be directed to standard output.
  • -v, --variable <name>: Set the name of the generated variable. This is required.
  • -s, --string output: Generate output as a string.
  • -z, --sort: Sort the output string. Applicable only with string output.
  • -u, --unicode: Treat the input as Unicode. Applicable only with string output.
  • -h, --help: Display the help message and exit.

Examples

Convert a binary file to a array:

bin2cpp20 -i path/to/input/file -o path/to/output.hpp -v variable_name

Convert standard input to a sorted Unicode string:

cat path/to/input | bin2cpp20 -i stdin -s -u -z -v variable_name -o path/to/output.hpp

Additional Notes

  • Ensure variable names are valid C++ identifiers.
  • Input files are read in binary mode, preserving the integrity of binary data.
  • The tool automatically appends .hpp to output filenames if not present.