--------------------------------- GetHeaderString Returns a string for the file header
| 91 | // Returns a string for the file header |
| 92 | // |
| 93 | std::string GetSourceString(std::vector<uint8> const& data, std::string const& name, std::string const& compiledDataName) |
| 94 | { |
| 95 | std::string ret; |
| 96 | |
| 97 | // begin of file |
| 98 | ret += |
| 99 | "// this file is automatically generated, do not edit!\n" |
| 100 | "#include \"" + name + std::string(".h\"\n" |
| 101 | "\n" |
| 102 | "unsigned char const* GetCompiledData_") + name + std::string("()\n" |
| 103 | "{\n" |
| 104 | "\treturn generated::wrapper::") + compiledDataName + std::string(";\n" |
| 105 | "}\n" |
| 106 | "\n" |
| 107 | "namespace generated { \n" |
| 108 | "\n" |
| 109 | "unsigned char const wrapper::") + compiledDataName + std::string("[] = {"); |
| 110 | |
| 111 | // end of file |
| 112 | std::string eof; |
| 113 | eof += |
| 114 | " };\n" |
| 115 | "\n" |
| 116 | "} // namespace generated\n" |
| 117 | "\n"; |
| 118 | |
| 119 | // make sure our string is allocated enough space in one go |
| 120 | static size_t const s_NumHexChars = 6u;// number of characters per byte |
| 121 | static size_t const s_StringSizeBuffer = 1024u;// number of characters per byte |
| 122 | ret.reserve(ret.size() + data.size() * s_NumHexChars + eof.size() + s_StringSizeBuffer); |
| 123 | |
| 124 | // add the bytes |
| 125 | static size_t const s_BytesPerLine = 16u; |
| 126 | static unsigned char s_HexChars[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; |
| 127 | |
| 128 | for (size_t dataIdx = 0u; dataIdx < data.size(); ++dataIdx) |
| 129 | { |
| 130 | // insert new line or space |
| 131 | if (dataIdx % s_BytesPerLine == 0u) |
| 132 | { |
| 133 | ret += "\n\t"; |
| 134 | } |
| 135 | else if (dataIdx % (s_BytesPerLine / 2) == 0u) |
| 136 | { |
| 137 | ret += " "; |
| 138 | } |
| 139 | else |
| 140 | { |
| 141 | ret += " "; |
| 142 | } |
| 143 | |
| 144 | // indicate hex number |
| 145 | ret += "0x"; |
| 146 | |
| 147 | // generate hex code |
| 148 | uint8 const currentByte = data[dataIdx]; |
| 149 | uint8 const bigEndian = currentByte >> 4u; |
| 150 | uint8 const smallEndian = currentByte & 0x0F; |
no outgoing calls
no test coverage detected