Benjamin Deroche
06/10/2022, 12:23 PMCPointer<ByteVar>.toKString(): String only work with zero terminated C stringsribesg
06/10/2022, 12:57 PMribesg
06/10/2022, 12:58 PMBenjamin Deroche
06/10/2022, 1:55 PMcontent.get(i).toInt().toChar() to get the next char and append it to my StringBuilderribesg
06/10/2022, 1:59 PMByteArray of the right size, fill it in one operation and then just String(myByteArray)ribesg
06/10/2022, 2:01 PMreadBytes(count: Int) on a CPointer? Or maybe it’s on a COpaquePointerribesg
06/10/2022, 2:02 PMCOpaquePointer is CPointer<out CPointed> and ByteVar extends CPointed so you can just do String((ptr as COpaquePointer).readBytes(count)) or something like thatBenjamin Deroche
06/10/2022, 2:07 PMreadBytes work and give me a ByteArray, but I can't do String(myByteArray) , I get an error Using 'String(CharArray): String' is an error. Use CharArray.concatToString() instead , does I need to convert the ByteArray into a CharArray first?ribesg
06/10/2022, 2:09 PMString(ByteArray) only works on the JVM. Try myByteArray.stringFromUtf8()Benjamin Deroche
06/10/2022, 2:12 PMstringFromUtf8 , but either decodeToString or toKString seems to worksBenjamin Deroche
06/10/2022, 2:13 PMval str: CValue<CRustStrView> = Get_version()
str.useContents {
val length: Int = len.toInt()
val test: ByteArray? = data?.readBytes(length)
println("Received string : '${test?.toKString()}'")
}Benjamin Deroche
06/10/2022, 2:14 PMribesg
06/10/2022, 2:15 PMtoKString() on Kotlin’s ByteArray too. Niceribesg
06/10/2022, 2:16 PMnapperley
06/11/2022, 12:22 AM