Repository navigation
Characteristic values as native hermes Uint8Array #1428
lucaswitch
started this conversation in
Ideas
Replies: 1 comment
|
The advantages with that would be the possibility of complete removal of Buffer usage but as pointed inside the docs. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Proposal
The objective of getting characteristic values is to parse them and do something with it, today the current values are given as standard js arrays with 32 bit values. I propose that we add a new way to read characteristic values using Uint8Array as a typed payload.
Why typed arrays:
It have a pre allocated size, it's a contiguous piece of memory in js engine and occupy almost nothing comparable to an 32 bit standard numeric array, it has zero copy operations built in, it's serializable, has a enforced value type without aid of typescript, it has a friendly interop with current TextEncoder api(which is the best way to encode bytes as text currently).
Many bluetooth protocols can have up to 200hz byte arrays transmitted back and forth which can represent a lot in memory/performance/gc in the brief long term.
I guess our little community can benefit a lot from having that built in.
Implementation
To keep the current api backwards compatible we need to keep the current api as it's, and implement these new characteristic values as it is, and enable it through some "keyword" on methods like the keyword "bytes*"
Receiving
Transmitting
Reference:
Uint8Array docs:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
Custom bridge types docs:
https://reactnative.dev/docs/the-new-architecture/custom-cxx-types
All reactions