Kolby Kunz
05/08/2023, 9:22 PMCPointer<uint8_tVar>
as input, the wrapper will take in a string value that will need to be converted to this type. I am currently doing the following
fun storeGenerateRawKey(key: String): String? {
var byteArray = key.encodeToByteArray()
var uIntArray = UIntArray(byteArray.size) { i -> byteArray[i].toUInt()}
memScoped {
val buffer = cValue<ByteBuffer>{
data = uIntArray.refTo(0) as CPointer<uint8_tVar>
len = uIntArray.size.toLong()
}
}
... some more opertations ...
return some string or null
}
where the byteBuffer is the struct defined in the library that I am importing. My main concern is the type cast and if this is the correct and safe way to do this conversion.Jeff Lockhart
05/08/2023, 9:37 PMKolby Kunz
05/08/2023, 9:41 PMJeff Lockhart
05/09/2023, 2:02 AMdata = uIntArray.refTo(0).getPointer(this@memScoped).reinterpret<uint8_tVar>()
Jeff Lockhart
05/09/2023, 2:04 AMmemScoped
block though.Kolby Kunz
05/09/2023, 2:04 AMKolby Kunz
05/09/2023, 3:04 PM.cstr
property and then taking that and making a uint8_tVar
array with allocArray in my memscope and just coping over each byte to the array with uIntByteBuffer[i] = cstring.ptr[i].toUByte()
inside a for loop. This resulted in a correctly typed array for what the c struct was expecting. Hopefully that is enough information if someone needs to do this in the future.