Hopefully quick question, as I am new to Native - ...
# kotlin-native
s
Hopefully quick question, as I am new to Native - given a C function returning "unsigned char *", cinterop stub returns CPointer<UByteVar> which makes sense. And the pointer this function is returning points to a string of UTF-8 bytes. But it looks like there is no toKString() for UByteArray in stdlib, correct? If so, what's the correct way to recast this so toKString is usable? Thanks in advance for any tips
b
get its pointer. call
reinterpret<ByteVar>()
to get it as a ByteVar. then you can use readBytes to get it into a ByteArray and decode that into a string
👍 1
s
Hmm, thanks, but I tried that. The IDE doesn't like it, andbuild claims Unresolved reference: reinterpret. Does that mean reinterpret also doesn't deal with UByteVar? Or am I more likely screwing up somehow 🙂 The function I'm calling is from Sqlite and looks like this:
Copy code
val ptr = sqlite3_column_text(statementContext, index)!!.reinterpret<ByteVar>()
reinterpret shows red in IDE. without the reinterpret, ptr shows as type CPointer<UByteVar> so seems like above should work.
b
what's the type of ptr?
oh you said that. hm
s
unsigned char * in raw C
b
try:
Copy code
memScoped {
   ptr.getPointer(this).reinterpret<ByteVar>()
}
s
Sill shows red.
b
it won't let you import?
s
gradle Build gets same error
b
i think they're extensions, so you'll have to import
s
That was it! I'm so used to IDE saying it can import that I didn't even look. Thanks!
🎉 1