Closed sirthias closed 4 months ago
Can you describe how you are using this library? What kind of endpoints do you use? Do you optimize for high throughput or low latency? Do you send many small or rather big packets of data?
If you are optimising for high throughput for a bulk endpoint, I strongly recommend to use an output stream (see USBDevice.openOutputStream()). Since it is an output stream, it offers the kind of interface you are looking for (see OutputStream.write(). And the output stream offers considerably higher throughput as it uses multiple outstanding requests behind the scenes.
If you have a good use case, I'm happy to add the additional transferOut()
method.
The proposal for transferIn()
is more problematic. If the buffer is not big enough for an entire USB packet, which depends on the device and the selected USB speed, difficult to understand errors can occur. The kind of behavior you are proposing ("If the buffer was too small then the returned int will be larger...") can only be achieved by allocating a separate buffer in the implementation. So the buffer copy would still be needed.
Again, for bulk endpoints, I recommend using an input stream. It avoids the copying and will deliver the remaining data in the next call.
In my case I'm talking to a device that can only deal with transfers in 60kb chunks, so larger payloads always needs to be sent in slices, which would entail no copying with the transferOut
overload sketched out above. Without the overload every slice needs to be copied into a fresh array.
I'm assuming that "spoon-feeding" external USB devices from a larger buffer isn't that rare, which is why I think this transferOut
overload should be added.
The proposal for transferIn() is more problematic. ... can only be achieved by allocating a separate buffer in the implementation. So the buffer copy would still be needed.
Yes, I was afraid that this was the case.
If there is no way to directly fill the target array without additional buffering in the JavaDoesUsb
layer, then this second transferIn
overload really doesn't make any sense.
Still wanted to bring it up, because sometimes the intermediate layers can in fact avoid internal buffers if the target buffer is already available.
This has been incorporated into release 0.6.0 and later
Currently
JavaDoesUSB
provides these two core methods on theUSBDevice
class:While they work fine and do their job I'd like to request the addition of these two overloads:
Especially the first method would be great to have as it will reduce the amount of intermediate buffer copying that might otherwise be needed.