swiftlang / swiftlang/swift-java
Better support for byte array conversions
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 1.2k
- Forks
- 123
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 16
Description
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).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the existing JavaKitIO support for java.io.InputStream and java.io.OutputStream, then examine how Java byte[] values are represented in Swift. Define the needed Data conversion use cases for java.io.ByteArrayInputStream and java.io.ByteArrayOutputStream, and consider how to avoid unnecessary copying. Done means the native offering supports the agreed conversions with coverage for the relevant APIs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, swift
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100