| 71 | }); |
| 72 | |
| 73 | function generateHeader(code: string, name: string, lineLength = 12) { |
| 74 | const bytes = [...Buffer.from(code, 'utf-8')] |
| 75 | .map(c => '0x' + c.toString(16).padStart(2, '0')); |
| 76 | |
| 77 | const formatted = Array<string>(); |
| 78 | for (let i = 0; i < bytes.length; i += lineLength) { |
| 79 | const line = bytes.slice(i, i + lineLength).join(', '); |
| 80 | formatted.push(line); |
| 81 | } |
| 82 | |
| 83 | return `#ifndef _${name.toUpperCase()}_H_ |
| 84 | #define _${name.toUpperCase()}_H_ |
| 85 | |
| 86 | static const unsigned int _${name}_size = ${bytes.length}; |
| 87 | |
| 88 | static const unsigned char _${name}[${bytes.length + 1}] = { |
| 89 | ${formatted.join(',\n ')} |
| 90 | }; |
| 91 | |
| 92 | #endif` |
| 93 | } |