Replace ByteArray with native ES6 TypedArray
I believe it's possible to replace the
ByteArray module with a native ES6 TypedArray: in particular,
Currently, C functions with
GByteArray input parameters take a
uint8_t* type are converted to a
GBytes type end up as a
My proposal would be to replace
Uint8Array everywhere. The
imports.byteArray module would still exist, and provide the same
ByteArray.fromGBytes() static methods as before, which would now return
Uint8Arrays. It would also provide
ByteArray.toGBytes() static methods to replace the
ByteArray instance methods of the same names.
A legacy shim would provide
ByteArray as an alias for
Uint8Array and add
toGBytes() methods to
Uint8Array.protoytpe for compatibility with existing code. It would also provide a
ByteArray.fromArray() static method for compatibility, though that is entirely equivalent to
Uint8Array.from(). These legacy methods would be considered deprecated from the start.
This should allow removing quite a lot of C++ code. However, unlike the existing custom
ByteArrays would need to be changed. The changes required should be trivial in most cases.
As an alternative that would preserve more compatibility, I might be able to write a shim that keeps existing
ByteArray code mostly working by implementing a separate
ByteArray class in JS, but it's not going to be possible to stay 100% compatible because in the end you have to return either a
ByteArray or a
Uint8Array instance from C functions with byte array return values.