Added toByteArray()
This commit is contained in:
parent
117bb2e5e0
commit
85572d7fb2
|
@ -1,6 +1,4 @@
|
||||||
import kotlinx.cinterop.addressOf
|
import kotlinx.cinterop.*
|
||||||
import kotlinx.cinterop.convert
|
|
||||||
import kotlinx.cinterop.usePinned
|
|
||||||
import platform.Foundation.*
|
import platform.Foundation.*
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,3 +12,9 @@ fun ByteArray.toNSData(): NSData = NSMutableData().apply {
|
||||||
appendBytes(it.addressOf(0), size.convert())
|
appendBytes(it.addressOf(0), size.convert())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun NSData.toByteArray(): ByteArray {
|
||||||
|
val data: CPointer<ByteVar> = bytes!!.reinterpret()
|
||||||
|
|
||||||
|
return ByteArray(length.toInt()) { index -> data[index] }
|
||||||
|
}
|
Loading…
Reference in New Issue