From f010b1150ccb4a45ef1a0d13e015eb6669b3fada Mon Sep 17 00:00:00 2001 From: Him188 Date: Thu, 25 Feb 2021 09:41:05 +0800 Subject: [PATCH] Fix platform declarations in mirai-core-utils --- .../src/androidMain/kotlin/Actuals.kt | 20 +++++++++++++++++++ .../src/commonMain/kotlin/Bytes.kt | 3 +-- .../commonMain/kotlin/MiraiPlatformUtils.kt | 2 +- .../src/jvmMain/kotlin/Actuals.kt | 20 +++++++++++++++++++ 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 mirai-core-utils/src/androidMain/kotlin/Actuals.kt create mode 100644 mirai-core-utils/src/jvmMain/kotlin/Actuals.kt diff --git a/mirai-core-utils/src/androidMain/kotlin/Actuals.kt b/mirai-core-utils/src/androidMain/kotlin/Actuals.kt new file mode 100644 index 000000000..3a02e12ff --- /dev/null +++ b/mirai-core-utils/src/androidMain/kotlin/Actuals.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2019-2021 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ + +@file:JvmMultifileClass +@file:Suppress("NOTHING_TO_INLINE") + +package net.mamoe.mirai.utils + +import android.util.Base64 + + +public actual fun ByteArray.encodeToBase64(): String { + return Base64.encodeToString(this, Base64.DEFAULT) +} \ No newline at end of file diff --git a/mirai-core-utils/src/commonMain/kotlin/Bytes.kt b/mirai-core-utils/src/commonMain/kotlin/Bytes.kt index a8f42cc29..57bf2e0dd 100644 --- a/mirai-core-utils/src/commonMain/kotlin/Bytes.kt +++ b/mirai-core-utils/src/commonMain/kotlin/Bytes.kt @@ -152,8 +152,7 @@ public fun UByteArray.toUHexString(separator: String = " ", offset: Int = 0, len public inline fun ByteArray.encodeToString(offset: Int = 0, charset: Charset = Charsets.UTF_8): String = kotlinx.io.core.String(this, charset = charset, offset = offset, length = this.size - offset) -public inline fun ByteArray.encodeToBase64(): String = - Base64.getEncoder().encodeToString(this) +public expect fun ByteArray.encodeToBase64(): String public inline fun ByteArray.toReadPacket(offset: Int = 0, length: Int = this.size - offset): ByteReadPacket = ByteReadPacket(this, offset = offset, length = length) diff --git a/mirai-core-utils/src/commonMain/kotlin/MiraiPlatformUtils.kt b/mirai-core-utils/src/commonMain/kotlin/MiraiPlatformUtils.kt index aac85c498..c45b7a34c 100644 --- a/mirai-core-utils/src/commonMain/kotlin/MiraiPlatformUtils.kt +++ b/mirai-core-utils/src/commonMain/kotlin/MiraiPlatformUtils.kt @@ -131,7 +131,7 @@ public fun Input.copyTo(out: OutputStream, bufferSize: Int = DEFAULT_BUFFER_SIZE return bytesCopied } -public inline fun I.withOut(output: O, block: I.(output: O) -> R): R { +public inline fun I.withOut(output: O, block: I.(output: O) -> R): R { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } diff --git a/mirai-core-utils/src/jvmMain/kotlin/Actuals.kt b/mirai-core-utils/src/jvmMain/kotlin/Actuals.kt new file mode 100644 index 000000000..6c36115cf --- /dev/null +++ b/mirai-core-utils/src/jvmMain/kotlin/Actuals.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2019-2021 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ + +@file:JvmMultifileClass +@file:Suppress("NOTHING_TO_INLINE") + +package net.mamoe.mirai.utils + +import java.util.* + + +public actual fun ByteArray.encodeToBase64(): String { + return Base64.getEncoder().encodeToString(this) +} \ No newline at end of file