swiftlang / swiftlang/swift-java

Better support for byte array conversions

Open
#288 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.