swiftlang/swift-java

Better support for byte array conversions

Opened this issue · 1 comments

Java bytes are converted in Swift as Int8 because Java considers bytes to be signed. This results in APIs that accept byte[] to be converted as [Int8] in Swift. This makes it really inconvenient to interact with native Data values in Swift land, since we need to convert Data to [Int8] in order to pass it appropriately to Java APIs.

Data can be easily converted to [Int8] with data.map { Int8(bitPattern: $0 }, but this results in unnecessary copying, which can make performant sensitive code feel slow.

Ideally, swift-java would provide support, and faster implementations, of these conversions. Not sure what would be all the use cases swift-java should support, but I think at the least java.ioByteArrayInputStream and java.io.ByteArrayOutputStream should be part of JavaKitIO's native offering, and provide simple APIs for converting between these and Data types (the parents java.io.InputStream and java.io.OutputStream are already there).

Yeah, this is planned and we are actively working on better Data support for jextract.

You're asking for javakit it seems.

But yes, both directions and approaches need to get better bytes support. This is already planned but we can keep this issue open as well