Closed dmarku closed 7 months ago
Thank you for the issue and the detailed description. It was indeed an easy fix in dataViewToNumbers.
The fix is released with version 3.1.4.
Thank you very much! I'll upgrade to the new version as soon as I can. This library has helped me a lot in prototyping an app and I'm happy to make a small contribution back. :slightly_smiling_face:
Describe the bug
BleClient.write()
sends all the data of theArrayBuffer
underlying the passedDataView
argument. If theDataView
is a view into only a section of that buffer, i.e. theDataView
has a non-zero offset or a length that is shorter than the buffer's length, data is sent that is outside of the view's boundaries.To Reproduce Steps to reproduce the behavior:
ArrayBuffer
DataView
into it with a non-zero offset and/or a length smaller than the bufferBleClient.write(device, service, characteristic, dataview)
Expected behavior Only the data visible from the DataView is sent.
Plugin version:
Smartphone (please complete the following information):
Additional context I've noticed this when writing a client for a GATT service that receives large-ish data transfers in chunks. I've kept a single ArrayBuffer with all the data and created DataViews for the individual chunks. This kept failing until I tried to copy the chunks into new ArrayBuffers and sending views into those.
While copying the data into new buffers is an acceptable workaround, I didn't expect this behavior, spent many hours debugging it and would like to spare others from this by fixing or documenting the behavior. I've looked into the plugin code and think this could be easily fixable by modifying
dataViewToNumbers()
(https://github.com/capacitor-community/bluetooth-le/blob/387dfa2d7099282ba89e718e6c8d5bd109078f45/src/conversion.ts#L11C1-L13C2).