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
The main purpose of IO is read and write arrays of bytes. There is a ByteArray - common Kotlin array of bytes abstraction, but it usually is not the efficient way to represent array of bytes on the platform(ByteBuffer on JVM, NSData on iOS, CPointer on Native, ArrayBuffer on Js and so on).
In multiplatform code, it will be ok to use just Buffer, but in platform specific code, near interop with already written Java or Native code, we need to have access to underlying primitive, like ByteBuffer on JVM and CPointer or ByteArray (which can be converted to CPointer) on Native.
My use case is using JDK and OpenSSL for cryptography API, where JDK API need ByteArray or ByteBuffer and OpenSSL native API has CPointer. Of course, we may read ByteArray from Buffer and use it, and also we can create Buffer from ByteArray - but this will be not efficient as copies will be created.
I would think, that such a functionality should be hidden under some UnsafeBufferApi (similar to DelicateCoroutinesApi) opt-in annotation, as such code will be to easy to misuse.
Possible designs:
Make specific Buffer implementation public with public property/function to access underlying primitive
Make expect/actual to access ONLY platform specific representations
Create some other way to safely access underlying primitive, but not tight to specific implementation, so different implementations be it wrapping ByteBuffer or ByteArray or other primitive can be accessed both as ByteArray and ByteBuffer
The text was updated successfully, but these errors were encountered:
As stated in design/BUFFER.md
In multiplatform code, it will be ok to use just
Buffer
, but in platform specific code, near interop with already written Java or Native code, we need to have access to underlying primitive, likeByteBuffer
on JVM andCPointer
orByteArray
(which can be converted toCPointer
) on Native.My use case is using JDK and OpenSSL for cryptography API, where JDK API need ByteArray or ByteBuffer and OpenSSL native API has CPointer. Of course, we may read
ByteArray
fromBuffer
and use it, and also we can createBuffer
fromByteArray
- but this will be not efficient as copies will be created.I would think, that such a functionality should be hidden under some
UnsafeBufferApi
(similar toDelicateCoroutinesApi
) opt-in annotation, as such code will be to easy to misuse.Possible designs:
Buffer
implementation public with public property/function to access underlying primitiveByteBuffer
orByteArray
or other primitive can be accessed both asByteArray
andByteBuffer
The text was updated successfully, but these errors were encountered: