|
1 | | -# bin2cpp20 |
2 | | -Convert streams to C++20 Arrays, Vectors, or Strings. |
| 1 | +# bin2cpp20 - Binary to C++20 Source Conversion Tool |
3 | 2 |
|
| 3 | +## Overview |
4 | 4 |
|
5 | | -To compile for me using GCC (Homebrew on MacOS) |
6 | | -I use |
| 5 | +`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. |
7 | 6 |
|
8 | | - % mkdir build |
9 | | - % export CXX=g++-13 |
10 | | - % cd build |
11 | | - % cmake .. |
12 | | - % make -j4 |
13 | | - % make install |
| 7 | +## Requirements |
| 8 | + |
| 9 | +- Fully C++20 compliant environment |
| 10 | + |
| 11 | +## Compilation |
| 12 | + |
| 13 | +To compile `bin2cpp20`, use the following command: |
| 14 | + |
| 15 | +```sh |
| 16 | +make -f Makefile.ux |
| 17 | +``` |
| 18 | +or |
| 19 | +```sh |
| 20 | +mkdir build && cd build |
| 21 | +cmake .. |
| 22 | +make -j4 |
| 23 | +sudo make install |
| 24 | +``` |
| 25 | + |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +The basic usage of the tool can be invoked as follows: |
| 30 | + |
| 31 | +```sh |
| 32 | +bin2cpp20 [options] |
| 33 | +``` |
| 34 | + |
| 35 | +### Key Features |
| 36 | + |
| 37 | +- **Input from file or standard input**: Specify an input binary file or use standard input. |
| 38 | +- **Output to standard output or file**: Direct the converted C++ source to standard output or a specified file. |
| 39 | +- **Variable naming**: Define custom variable names for the generated code. |
| 40 | +- **Output formats**: Choose between vector, array, or string representations of the binary data. |
| 41 | +- **Sorting and Unicode options**: Sort strings in the output or handle Unicode data correctly. |
| 42 | + |
| 43 | +### Options |
| 44 | + |
| 45 | +- `-i, --input <file/stdin>`: Specify the input source. Use "stdin" to read from standard input. |
| 46 | +- `-o, --output <file>`: Specify the output file. If not provided, output will be directed to standard output. |
| 47 | +- `-v, --variable <name>`: Set the name of the generated variable. This is required. |
| 48 | +- `-s, --string output`: Generate output as a string. |
| 49 | +- `-z, --sort`: Sort the output string. Applicable only with string output. |
| 50 | +- `-u, --unicode`: Treat the input as Unicode. Applicable only with string output. |
| 51 | +- `-h, --help`: Display the help message and exit. |
| 52 | + |
| 53 | +### Examples |
| 54 | + |
| 55 | +**Convert a binary file to a arrau:** |
| 56 | + |
| 57 | +```sh |
| 58 | +bin2cpp20 -i path/to/input/file -o path/to/output.hpp -v variable_name |
| 59 | +``` |
| 60 | + |
| 61 | +**Convert standard input to a sorted Unicode string:** |
| 62 | + |
| 63 | +```sh |
| 64 | +cat path/to/input | bin2cpp20 -i stdin -s -u -z -v variable_name -o path/to/output.hpp |
| 65 | +``` |
| 66 | + |
| 67 | +## Additional Notes |
| 68 | + |
| 69 | +- Ensure variable names are valid C++ identifiers. |
| 70 | +- Input files are read in binary mode, preserving the integrity of binary data. |
| 71 | +- The tool automatically appends `.hpp` to output filenames if not present. |
0 commit comments