Coder Social home page Coder Social logo

brcc's Introduction

Binary Resources for C++ Compiler (BRCC)

Version 1.3.2.

The Binary Resources for C++ Compiler is a simple cross platform compiler that converts binary files to C++ header and source files for inclusion in other projects.

I found other solutions to this problem deficient. xxd doesn't allow you to set the name of the variables to anything other than the files name. objdump, ld, both have the same issues in general.

BRCC is a cross platform, more predictable solution. It allows you to compile as many binaries into a single output .cpp file as you want, and creates a corresponding .hpp file. You can manually set the header guard and it doesn't gum up your code with autogeneration comments.

Usage: brcc output_basename HEADER_GUARD [-h|-o] [(-c|-i|-s|-v) symbol_prefix binary_file]...

Example:

brcc ./build/gen/binary_resources GAME_BINARY_RESOURCES_HH -s bin_vertex_shader ./src/vertex_shader.glsl \
bin_fragment_shader ./src/fragment_shader.glsl

Creates files './build/gen/binary_resources.hpp' and './build/gen/binary_resources.cpp', which have std::strings that import the data.

Execution options:

  • -h Generate only a header file (does not append .hpp).
  • -o Generate only a source file (does not append .cpp).

Symbol Options:

  • -s Stores the binary data in a std::string.
  • -c Stores the binary data in a C style array.
  • -i Stores the binary data in a std::initializer_list<std::uint8_t>.
  • -v Stores the binary data in a std::vector<std::uint8_t>.

Note that the order of options is mandatory, you cannot put -h or -o in any location except after the header guard.

The output test-brcc.cpp file after I ran brcc ./test-brcc GUARD_HH bin_test ~/test_binary1.bin arbitrary_symbol /etc/issue:

#ifndef GUARD_HH
#define GUARD_HH
#include <cstdint>

extern std::uint8_t const arbitrary_symbol[30];
extern std::uint8_t const bin_test[13];

#endif
std::uint8_t const arbitrary_symbol[30] = {
  0x4c, 0x69, 0x6e, 0x75, 0x78, 0x20, 0x4d, 0x69, 0x6e, 0x74, 0x20, 0x31, 0x38, 0x2e, 0x33, 0x20,
  0x53, 0x79, 0x6c, 0x76, 0x69, 0x61, 0x20, 0x5c, 0x6e, 0x20, 0x5c, 0x6c, 0x0a, 0x0a
};
std::uint8_t const bin_test[13] = {
  0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0x0a
};

brcc's People

Contributors

exaeta avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.