You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to convert JArray<jbyte> to Uint8List efficiently? #990
When convert Uint8List to JArray, we can use the JArray<jbyte>.setRange extension method.
But I don't know how to do the opposite way.
Currently I can do this by use a for-loop, but I think this will spend a lot when convert a large byte array.
If the Struct containing the Array is created from a Pointer, you can use asTypedList on that pointer if you know the offset of the array in the struct.
In general we should support something like what you're asking for. I've filed dart-lang/sdk#55170 to track that feature.
What @mkustermann said is possible. We can support the getRange operation as well.
I first wrote something wrong about using JByteBuffers, that's not currently possible, because we can only convert direct JByteBuffers into Uint8Lists.
If you don't have to use an array, you can use JByteBuffer directly, maybe that simplifies your code.
final buffer =JByteBuffer.fromList(list);
final list = buffer.asUint8List();
What @mkustermann said is possible. We can support the getRange operation as well.
I first wrote something wrong about using JByteBuffers, that's not currently possible, because we can only convert direct JByteBuffers into Uint8Lists.
If you don't have to use an array, you can use JByteBuffer directly, maybe that simplifies your code.
final buffer =JByteBuffer.fromList(list);
final list = buffer.asUint8List();
The JByteArray is returned by a Kotlin method, so I can't use JByteBuffer instead, I think provide a getRange extension will be nice.
Activity
dcharkes commentedon Mar 12, 2024
Hi @yanshouwang!
If theStructcontaining theArrayis created from aPointer, you can useasTypedListon that pointer if you know the offset of the array in the struct.In general we should support something like what you're asking for. I've filed dart-lang/sdk#55170 to track that feature.Edit: wait, this is asking for
JArraynotArray!@HosseinYousefi over to you!
mkustermann commentedon Mar 12, 2024
Right now we have JArray:
Maybe this just needs a
that is then implemented via
Jni.env.GetByteArrayRegionto get C pointers to memory and then copy it to a dart typed list.HosseinYousefi commentedon Mar 12, 2024
What @mkustermann said is possible. We can support the
getRangeoperation as well.I first wrote something wrong about using
JByteBuffers, that's not currently possible, because we can only convert directJByteBuffers intoUint8Lists.If you don't have to use an array, you can use
JByteBufferdirectly, maybe that simplifies your code.yanshouwang commentedon Mar 13, 2024
The JByteArray is returned by a Kotlin method, so I can't use JByteBuffer instead, I think provide a
getRangeextension will be nice.[jnigen] Add `getRange` method to `JArray<JPrimitive>` and change the…
Squashed commit of the following: