Last active
February 16, 2019 18:41
-
-
Save C47D/6b157424db5417b0cc2131c536ba32c0 to your computer and use it in GitHub Desktop.
Test script to convert from a Python ByteArray to a C array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
oggDataArray = [] | |
ogg_decoded_file = 'ogg_decoded' | |
output_file = 'test.c' | |
print('Opening {}.'.format(ogg_decoded_file)) | |
with open(ogg_decoded_file, 'rb') as f: | |
byte = f.read(1) | |
while byte: | |
oggDataArray.append(byte) | |
byte = f.read(1) | |
print('Dumping data to {}.'.format(output_file)) | |
with open(output_file, 'w+') as f: | |
f.write('const uint8_t array[] = {\n') | |
f.write(''.join(['0x%02X, ' % ord(x) for x in oggDataArray]).strip()) | |
f.write('\n}') | |
print('Done!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment