esp-nimble-cpp
esp-nimble-cpp copied to clipboard
Return a pointer to the Value object
Otherwise we get a copy, and the copy seems to clobber the data we want
Before this commit, calling getValue() would return a copy of the underlying NimBLEAttValue object. It seems like the copy doesn't necessarily copy the underlying data stored in the value. In this commit, I changed it to just return a pointer (which fixes my application), but maybe the class should know how to copy its underlying data.
I'm not sure if this is the best fix (I'm not a pro C++ developer), but as I said this fixes my app.
Thanks!
Providing a pointer to the underlying data structure is dangerous because it could change at any time, thus the reason for the copy. Could you provide an example of the data being "clobbered" to help find the cause?
@h2zero (I need to preface this by saying I'm not a BLE expert, nor C++ expert). My application is trying to read HID data written to USB from my computer. I'm using libusb to send data to the bluetooth device. I think the problem is that since you can send an arbitrary number of bytes from the computer to the bluetooth device, doing the copy doesn't work as it doesn't know how many bytes to copy (since it's not known at compile time).
I'm using the pointer here.
Without this change, I get an object back with not clobbered, but uninitialized memory (sorry I should have been more clear in the original post).
Thank you for replying, that is certainly odd. I do not see how it would be possible for the data to be uninitialized.
If you changed your code to NimBLEAttValue buff = me->getValue(); it should copy and work in your code as is because it has a copy operator defined.
Closing this as it's not necessary.