From 449ffbb76185a6313e76b62e5303c6b3a7ae91ec Mon Sep 17 00:00:00 2001 From: Clarke Brunsdon Date: Wed, 14 Jan 2026 11:42:26 -0800 Subject: [PATCH 1/3] Replace java's IOException with okio's for Adapter This is typealiased by okio for JVM classes, so should be binary/api compatible on JVM (the only one that cared about it). This is also pretty standard for the rest of wire-runtime: ``` $ rg "import okio.IOEx" wire-runtime | wc 19 38 1790 ``` --- .../src/jvmMain/kotlin/com/squareup/wire/EnumAdapter.kt | 2 +- .../src/jvmMain/kotlin/com/squareup/wire/ProtoAdapter.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/EnumAdapter.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/EnumAdapter.kt index 9e8ee14dbc..16f2210008 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/EnumAdapter.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/EnumAdapter.kt @@ -16,8 +16,8 @@ package com.squareup.wire import com.squareup.wire.internal.identityOrNull -import java.io.IOException import kotlin.reflect.KClass +import okio.IOException /** * An abstract [ProtoAdapter] that converts values of an enum to and from integers. diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/ProtoAdapter.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/ProtoAdapter.kt index 712ace9c59..e45fb86cc3 100644 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/ProtoAdapter.kt +++ b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/ProtoAdapter.kt @@ -18,13 +18,13 @@ package com.squareup.wire import com.squareup.wire.internal.createRuntimeMessageAdapter -import java.io.IOException import java.io.InputStream import java.io.OutputStream import kotlin.reflect.KClass import okio.BufferedSink import okio.BufferedSource import okio.ByteString +import okio.IOException import okio.buffer import okio.sink import okio.source From c28157b2f67f2080405892f95feaba7db7707a7b Mon Sep 17 00:00:00 2001 From: Clarke Brunsdon Date: Wed, 14 Jan 2026 11:56:33 -0800 Subject: [PATCH 2/3] Kill the expect/actual message sink Okio's closeable had the same signature so we're good to use it in commonMain. Moved the specific docs to the interface level to avoid needing to override the method just to doc it here, and avoid having to change the .api file. --- .../kotlin/com/squareup/wire/MessageSink.kt | 13 ++++---- .../kotlin/com/squareup/wire/MessageSink.kt | 27 ----------------- .../kotlin/com/squareup/wire/MessageSink.kt | 30 ------------------- 3 files changed, 5 insertions(+), 65 deletions(-) delete mode 100644 wire-runtime/src/jvmMain/kotlin/com/squareup/wire/MessageSink.kt delete mode 100644 wire-runtime/src/nonJvmMain/kotlin/com/squareup/wire/MessageSink.kt diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/MessageSink.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/MessageSink.kt index dbf25b234e..ab24fd5090 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/MessageSink.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/MessageSink.kt @@ -16,6 +16,7 @@ package com.squareup.wire import kotlin.Throws +import okio.Closeable import okio.IOException /** @@ -39,8 +40,11 @@ import okio.IOException * You should ensure that such backpressure propagates to the originator of outbound messages. * * Instances of this interface are not safe for concurrent use. + * + * Closing a sink will terminate the stream and release its resources. If this has not been canceled + * this signals a normal completion of the stream. */ -expect interface MessageSink { +interface MessageSink : Closeable { /** * Encode [message] to bytes and enqueue the bytes for delivery, waiting if necessary until the * delivery channel has capacity for the encoded message. @@ -60,11 +64,4 @@ expect interface MessageSink { */ @Throws(IOException::class) fun cancel() - - /** - * Terminate the stream and release its resources. If this has not been canceled this signals a - * normal completion of the stream. - */ - @Throws(IOException::class) - fun close() } diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/MessageSink.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/MessageSink.kt deleted file mode 100644 index 7a69974b70..0000000000 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/MessageSink.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2019 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.squareup.wire - -import java.io.Closeable -import okio.IOException - -actual interface MessageSink : Closeable { - @Throws(IOException::class) - actual fun write(message: T) - - @Throws(IOException::class) - actual fun cancel() -} diff --git a/wire-runtime/src/nonJvmMain/kotlin/com/squareup/wire/MessageSink.kt b/wire-runtime/src/nonJvmMain/kotlin/com/squareup/wire/MessageSink.kt deleted file mode 100644 index 018ab1a327..0000000000 --- a/wire-runtime/src/nonJvmMain/kotlin/com/squareup/wire/MessageSink.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2019 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.squareup.wire - -import kotlin.Throws -import okio.IOException - -actual interface MessageSink { - @Throws(IOException::class) - actual fun write(message: T) - - @Throws(IOException::class) - actual fun cancel() - - @Throws(IOException::class) - actual fun close() -} From 43a312ced90c3203ac229c1eb06c95847cdd7f54 Mon Sep 17 00:00:00 2001 From: Clarke Brunsdon Date: Wed, 14 Jan 2026 11:59:16 -0800 Subject: [PATCH 3/3] Remove the expect/actual on MessageSource Like MessageSink before it, we can reuse okio's closeable as it has the same signature --- .../kotlin/com/squareup/wire/MessageSource.kt | 6 ++--- .../kotlin/com/squareup/wire/MessageSource.kt | 24 ----------------- .../kotlin/com/squareup/wire/MessageSource.kt | 27 ------------------- 3 files changed, 2 insertions(+), 55 deletions(-) delete mode 100644 wire-runtime/src/jvmMain/kotlin/com/squareup/wire/MessageSource.kt delete mode 100644 wire-runtime/src/nonJvmMain/kotlin/com/squareup/wire/MessageSource.kt diff --git a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/MessageSource.kt b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/MessageSource.kt index 5a7c890034..0c6b9b476a 100644 --- a/wire-runtime/src/commonMain/kotlin/com/squareup/wire/MessageSource.kt +++ b/wire-runtime/src/commonMain/kotlin/com/squareup/wire/MessageSource.kt @@ -16,6 +16,7 @@ package com.squareup.wire import kotlin.Throws +import okio.Closeable import okio.IOException /** @@ -35,7 +36,7 @@ import okio.IOException * * Instances of this interface are not safe for concurrent use. */ -expect interface MessageSource { +interface MessageSource : Closeable { /** * Read the next length-prefixed message on the stream and return it. Returns null if there are * no further messages on this stream. @@ -45,7 +46,4 @@ expect interface MessageSource { */ @Throws(IOException::class) fun read(): T? - - @Throws(IOException::class) - fun close() } diff --git a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/MessageSource.kt b/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/MessageSource.kt deleted file mode 100644 index 481ccf20a6..0000000000 --- a/wire-runtime/src/jvmMain/kotlin/com/squareup/wire/MessageSource.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2019 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.squareup.wire - -import java.io.Closeable -import okio.IOException - -actual interface MessageSource : Closeable { - @Throws(IOException::class) - actual fun read(): T? -} diff --git a/wire-runtime/src/nonJvmMain/kotlin/com/squareup/wire/MessageSource.kt b/wire-runtime/src/nonJvmMain/kotlin/com/squareup/wire/MessageSource.kt deleted file mode 100644 index 5fe38ce1ee..0000000000 --- a/wire-runtime/src/nonJvmMain/kotlin/com/squareup/wire/MessageSource.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2019 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.squareup.wire - -import kotlin.Throws -import okio.IOException - -actual interface MessageSource { - @Throws(IOException::class) - actual fun read(): T? - - @Throws(IOException::class) - actual fun close() -}