if the data you’re including in your extension is lots of number arrays, then you should absolutely use buffers instead. they are way more efficient than arrays in terms of both memory usage and code size. however, if your data is a bunch of strings or images then you probably won’t gain anything by converting them to hex buffers.
here’s a little bit of code to get you started if you do have some number arrays you want to convert. this code will convert a number array into the string representation of a hex buffer and print it out in the console:
const hexChars = "0123456789ABCDEF";
const testValues = [1, 2, 3, 4];
console.log(convertNumberArrayToHex(testValues));
function convertNumberArrayToHex(values: number[]) {
// you can change this variable to control how many bytes you need
// for each number in your array. ask yourself, what is the range of
// the values i'm trying to store? are there no negative numbers? if so,
// use unsigned integers instead of signed (UInt instead of Int). do you need
// the full range of 32 bit numbers? for example, if the range of
// numbers is less than -32768..32767 for signed integers or 0..65535 for
// unsigned integers, use the 16 bit option instead of 32 bit to save
// double the space! does your code use floating point numbers? then
// consider converting them to fixed point numbers instead if possible!
const numberFormat = NumberFormat.UInt32LE;
const bytesPerNumber = Buffer.sizeOfNumberFormat(numberFormat);
const buffer = control.createBuffer(bytesPerNumber * values.length);
for (let i = 0; i < values.length; i++) {
buffer.setNumber(numberFormat, i * bytesPerNumber, values[i]);
}
return bufferToString(buffer);
}
function bufferToString(buf: Buffer) {
let bytes = "";
for (let i = 0; i < buf.length; i++) {
bytes += toHex(buf[i]);
}
return `hex\`${bytes}\``;
}
function toHex(byte: number) {
return hexChars.charAt(byte >> 4) + hexChars.charAt(byte & 0xf);
}
note that the above code is just meant for you to use as a script to convert the buffers you already have, you should not run this code at runtime. in other words, this code should not be anywhere in your extension at the end of the day!