From 904d1ffbeaa97d6944eb883278babedba4ea0ec3 Mon Sep 17 00:00:00 2001 From: MCKero Date: Sun, 27 Sep 2026 10:44:48 +0100 Subject: [PATCH] fix(kmp): replace remaining jvm-only encoding calls in common sources The previous round fixed the convention plugin and the native expect declarations, which let both platforms compile far enough to reveal the next layer: a handful of jvm-only call forms that survived the original kotlin/native sweep because they look like plain kotlin. String.toByteArray() and Charsets.UTF_8 live in java.nio.charset and do not exist on kotlin/native; the stdlib equivalents encodeToByteArray() compile everywhere and are byte-identical for utf-8, so the APRS packet length budget and the ADIF field length calculation keep their exact arithmetic. The DatabaseRepoTest helpers kept an InputStream return type after their bodies were moved to ByteArray sources, and the java.io import was gone with the sweep, so the android unit test task could not resolve them; the fake source maps were already typed () -> ByteArray, so the return type simply follows the data it now feeds. --- .../look4sat/core/data/repository/DatabaseRepoTest.kt | 4 ++-- .../com/rtbishop/look4sat/core/domain/aprs/AprsBeacon.kt | 2 +- .../com/rtbishop/look4sat/core/domain/wavelog/WaveLogApi.kt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/data/src/test/java/com/rtbishop/look4sat/core/data/repository/DatabaseRepoTest.kt b/core/data/src/test/java/com/rtbishop/look4sat/core/data/repository/DatabaseRepoTest.kt index 7c37b989..97ba0094 100644 --- a/core/data/src/test/java/com/rtbishop/look4sat/core/data/repository/DatabaseRepoTest.kt +++ b/core/data/src/test/java/com/rtbishop/look4sat/core/data/repository/DatabaseRepoTest.kt @@ -194,12 +194,12 @@ class DatabaseRepoTest { assertTrue("no entries may be inserted", localSource.insertedEntries.isEmpty()) } - private fun validCsvBytes(): InputStream = """ + private fun validCsvBytes(): ByteArray = """ OBJECT_NAME,OBJECT_ID,EPOCH,MEAN_MOTION,ECCENTRICITY,INCLINATION,RA_OF_ASC_NODE,ARG_OF_PERICENTER,MEAN_ANOMALY,EPHEMERIS_TYPE,CLASSIFICATION_TYPE,NORAD_CAT_ID,ELEMENT_SET_NO,REV_AT_EPOCH,BSTAR,MEAN_MOTION_DOT,MEAN_MOTION_DDOT ISS (ZARYA),1998-067A,2021-11-16T12:28:09.322176,15.48582035,.0004694,51.6447,309.4881,203.6966,299.8876,0,U,25544,999,31220,.31985E-4,.1288E-4,0 """.trimIndent().encodeToByteArray() - private fun validTleBytes(): InputStream = """ + private fun validTleBytes(): ByteArray = """ ISS (ZARYA) 1 25544U 98067A 21320.51955234 .00001288 00000+0 31985-4 0 9990 2 25544 51.6447 309.4881 0004694 203.6966 299.8876 15.48582035312205 diff --git a/core/domain/src/commonMain/kotlin/com/rtbishop/look4sat/core/domain/aprs/AprsBeacon.kt b/core/domain/src/commonMain/kotlin/com/rtbishop/look4sat/core/domain/aprs/AprsBeacon.kt index 33ab181e..600552ff 100644 --- a/core/domain/src/commonMain/kotlin/com/rtbishop/look4sat/core/domain/aprs/AprsBeacon.kt +++ b/core/domain/src/commonMain/kotlin/com/rtbishop/look4sat/core/domain/aprs/AprsBeacon.kt @@ -91,7 +91,7 @@ object AprsBeacon { ) val header = "$source>$DESTINATION,$PATH:=" val body = position.toUncompressedString() - val room = MAX_LINE_BYTES - CRLF_BYTES - header.toByteArray().size - body.toByteArray().size + val room = MAX_LINE_BYTES - CRLF_BYTES - header.encodeToByteArray().size - body.encodeToByteArray().size return Result.Line(header + body + sanitiseComment(comment, room)) } diff --git a/core/domain/src/commonMain/kotlin/com/rtbishop/look4sat/core/domain/wavelog/WaveLogApi.kt b/core/domain/src/commonMain/kotlin/com/rtbishop/look4sat/core/domain/wavelog/WaveLogApi.kt index 77f1c43a..6f629e31 100644 --- a/core/domain/src/commonMain/kotlin/com/rtbishop/look4sat/core/domain/wavelog/WaveLogApi.kt +++ b/core/domain/src/commonMain/kotlin/com/rtbishop/look4sat/core/domain/wavelog/WaveLogApi.kt @@ -312,7 +312,7 @@ object WaveLogApi { /** v1 ADIF string (freq in MHz, length = UTF-8 byte count, sat_name normalized) */ internal fun toAdif(qso: WavelogQso, gridsquare: String, satName: String): String { fun field(name: String, value: String): String { - val bytes = value.toByteArray(Charsets.UTF_8).size + val bytes = value.encodeToByteArray().size return "<$name:$bytes>$value" } val satMode = satModeFrom(qso.freqTxHz, qso.freqRxHz)