Commit 1d0b42df authored by Him188's avatar Him188

Cleanup

parent 01e887ff
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* *
* https://github.com/mamoe/mirai/blob/master/LICENSE * https://github.com/mamoe/mirai/blob/master/LICENSE
*/ */
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") @file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
package net.mamoe.mirai.qqandroid.contact package net.mamoe.mirai.qqandroid.contact
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* *
* https://github.com/mamoe/mirai/blob/master/LICENSE * https://github.com/mamoe/mirai/blob/master/LICENSE
*/ */
@file:OptIn(LowLevelAPI::class) @file:OptIn(LowLevelAPI::class)
@file:Suppress("EXPERIMENTAL_API_USAGE", "DEPRECATION_ERROR") @file:Suppress("EXPERIMENTAL_API_USAGE", "DEPRECATION_ERROR")
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* *
* https://github.com/mamoe/mirai/blob/master/LICENSE * https://github.com/mamoe/mirai/blob/master/LICENSE
*/ */
@file:Suppress("EXPERIMENTAL_API_USAGE", "EXPERIMENTAL_OVERRIDE", "INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") @file:Suppress("EXPERIMENTAL_API_USAGE", "EXPERIMENTAL_OVERRIDE", "INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
package net.mamoe.mirai.qqandroid.message package net.mamoe.mirai.qqandroid.message
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* *
* https://github.com/mamoe/mirai/blob/master/LICENSE * https://github.com/mamoe/mirai/blob/master/LICENSE
*/ */
@file:Suppress("EXPERIMENTAL_API_USAGE", "EXPERIMENTAL_OVERRIDE", "INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") @file:Suppress("EXPERIMENTAL_API_USAGE", "EXPERIMENTAL_OVERRIDE", "INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
package net.mamoe.mirai.qqandroid.message package net.mamoe.mirai.qqandroid.message
......
...@@ -14,6 +14,7 @@ import net.mamoe.mirai.contact.Friend ...@@ -14,6 +14,7 @@ import net.mamoe.mirai.contact.Friend
import net.mamoe.mirai.contact.Group import net.mamoe.mirai.contact.Group
import net.mamoe.mirai.data.* import net.mamoe.mirai.data.*
import net.mamoe.mirai.utils.MiraiExperimentalAPI import net.mamoe.mirai.utils.MiraiExperimentalAPI
import net.mamoe.mirai.utils.SinceMirai
import net.mamoe.mirai.utils.WeakRef import net.mamoe.mirai.utils.WeakRef
/** /**
...@@ -125,7 +126,6 @@ public interface LowLevelBotAPIAccessor { ...@@ -125,7 +126,6 @@ public interface LowLevelBotAPIAccessor {
* 处理一个账号请求添加机器人为好友的事件 * 处理一个账号请求添加机器人为好友的事件
*/ */
@LowLevelAPI @LowLevelAPI
@MiraiExperimentalAPI
public suspend fun _lowLevelSolveNewFriendRequestEvent( public suspend fun _lowLevelSolveNewFriendRequestEvent(
eventId: Long, eventId: Long,
fromId: Long, fromId: Long,
...@@ -138,7 +138,6 @@ public interface LowLevelBotAPIAccessor { ...@@ -138,7 +138,6 @@ public interface LowLevelBotAPIAccessor {
* 处理被邀请加入一个群请求事件 * 处理被邀请加入一个群请求事件
*/ */
@LowLevelAPI @LowLevelAPI
@MiraiExperimentalAPI
public suspend fun _lowLevelSolveBotInvitedJoinGroupRequestEvent( public suspend fun _lowLevelSolveBotInvitedJoinGroupRequestEvent(
eventId: Long, eventId: Long,
invitorId: Long, invitorId: Long,
...@@ -150,7 +149,7 @@ public interface LowLevelBotAPIAccessor { ...@@ -150,7 +149,7 @@ public interface LowLevelBotAPIAccessor {
* 处理账号请求加入群事件 * 处理账号请求加入群事件
*/ */
@LowLevelAPI @LowLevelAPI
@MiraiExperimentalAPI @SinceMirai("1.2.0")
public suspend fun _lowLevelSolveMemberJoinRequestEvent( public suspend fun _lowLevelSolveMemberJoinRequestEvent(
eventId: Long, eventId: Long,
fromId: Long, fromId: Long,
...@@ -165,6 +164,20 @@ public interface LowLevelBotAPIAccessor { ...@@ -165,6 +164,20 @@ public interface LowLevelBotAPIAccessor {
* 查询语音的下载连接 * 查询语音的下载连接
*/ */
@LowLevelAPI @LowLevelAPI
@MiraiExperimentalAPI @SinceMirai("1.2.0")
public suspend fun _lowLevelQueryGroupVoiceDownloadUrl(md5: ByteArray, groupId: Long, dstUin: Long): String public suspend fun _lowLevelQueryGroupVoiceDownloadUrl(
md5: ByteArray,
groupId: Long,
dstUin: Long
): String
/**
* 查询语音的上传连接
*/
@LowLevelAPI
@SinceMirai("1.2.0")
public suspend fun _lowLevelUploadVoice(
md5: ByteArray,
groupId: Long,
)
} }
...@@ -14,9 +14,7 @@ package net.mamoe.mirai.message.data ...@@ -14,9 +14,7 @@ package net.mamoe.mirai.message.data
import kotlinx.io.core.* import kotlinx.io.core.*
import kotlinx.serialization.KSerializer import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.UnstableDefault
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration
import kotlinx.serialization.protobuf.ProtoBuf import kotlinx.serialization.protobuf.ProtoBuf
import kotlinx.serialization.protobuf.ProtoId import kotlinx.serialization.protobuf.ProtoId
import net.mamoe.mirai.utils.* import net.mamoe.mirai.utils.*
...@@ -90,8 +88,8 @@ public sealed class CustomMessage : SingleMessage { ...@@ -90,8 +88,8 @@ public sealed class CustomMessage : SingleMessage {
*/ */
public abstract fun serializer(): KSerializer<M> public abstract fun serializer(): KSerializer<M>
public override fun dump(message: M): ByteArray = ProtoBuf.dump(serializer(), message) public override fun dump(message: M): ByteArray = ProtoBuf.encodeToByteArray(serializer(), message)
public override fun load(input: ByteArray): M = ProtoBuf.load(serializer(), input) public override fun load(input: ByteArray): M = ProtoBuf.decodeFromByteArray(serializer(), input)
} }
/** /**
...@@ -106,11 +104,10 @@ public sealed class CustomMessage : SingleMessage { ...@@ -106,11 +104,10 @@ public sealed class CustomMessage : SingleMessage {
*/ */
public abstract fun serializer(): KSerializer<M> public abstract fun serializer(): KSerializer<M>
@OptIn(UnstableDefault::class) public open val json: Json = Json.Default
public open val json: Json = Json(JsonConfiguration.Default)
public override fun dump(message: M): ByteArray = json.stringify(serializer(), message).toByteArray() public override fun dump(message: M): ByteArray = json.encodeToString(serializer(), message).toByteArray()
public override fun load(input: ByteArray): M = json.parse(serializer(), String(input)) public override fun load(input: ByteArray): M = json.decodeFromString(serializer(), String(input))
} }
public companion object Key : Message.Key<CustomMessage> { public companion object Key : Message.Key<CustomMessage> {
...@@ -143,7 +140,7 @@ public sealed class CustomMessage : SingleMessage { ...@@ -143,7 +140,7 @@ public sealed class CustomMessage : SingleMessage {
if (fullData.remaining != length.toLong()) { if (fullData.remaining != length.toLong()) {
return null return null
} }
ProtoBuf.load(CustomMessageFullData.serializer(), fullData.readBytes(length)) ProtoBuf.decodeFromByteArray(CustomMessageFullData.serializer(), fullData.readBytes(length))
}.getOrElse { }.getOrElse {
throw CustomMessageFullDataDeserializeInternalException(it) throw CustomMessageFullDataDeserializeInternalException(it)
} }
...@@ -158,7 +155,7 @@ public sealed class CustomMessage : SingleMessage { ...@@ -158,7 +155,7 @@ public sealed class CustomMessage : SingleMessage {
} }
internal fun <M : CustomMessage> dump(factory: Factory<M>, message: M): ByteArray = buildPacket { internal fun <M : CustomMessage> dump(factory: Factory<M>, message: M): ByteArray = buildPacket {
ProtoBuf.dump( ProtoBuf.encodeToByteArray(
CustomMessageFullData.serializer(), CustomMessageFullData( CustomMessageFullData.serializer(), CustomMessageFullData(
miraiVersionFlag = 1, miraiVersionFlag = 1,
typeName = factory.typeName, typeName = factory.typeName,
......
...@@ -15,16 +15,18 @@ import kotlinx.coroutines.flow.flow ...@@ -15,16 +15,18 @@ import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.io.ByteReadChannel import kotlinx.coroutines.io.ByteReadChannel
import kotlinx.io.InputStream
import kotlinx.io.core.ByteReadPacket import kotlinx.io.core.ByteReadPacket
import kotlinx.io.core.Closeable import kotlinx.io.core.Closeable
import kotlinx.io.core.Input import kotlinx.io.core.Input
import kotlinx.serialization.InternalSerializationApi import kotlinx.serialization.InternalSerializationApi
import net.mamoe.mirai.utils.MiraiExperimentalAPI
import java.io.InputStream
import kotlin.jvm.JvmField import kotlin.jvm.JvmField
internal interface ChunkedFlowSession<T> : Closeable { @MiraiExperimentalAPI
val flow: Flow<T> public interface ChunkedFlowSession<T> : Closeable {
public val flow: Flow<T>
override fun close() override fun close()
} }
...@@ -39,7 +41,8 @@ internal inline fun <T, R> ChunkedFlowSession<T>.map(crossinline mapper: suspend ...@@ -39,7 +41,8 @@ internal inline fun <T, R> ChunkedFlowSession<T>.map(crossinline mapper: suspend
/** /**
* 由 [chunkedFlow] 分割得到的区块 * 由 [chunkedFlow] 分割得到的区块
*/ */
internal class ChunkedInput( @MiraiExperimentalAPI
public class ChunkedInput(
/** /**
* 区块的数据. * 区块的数据.
* 由 [ByteArrayPool] 缓存并管理, 只可在 [Flow.collect] 中访问. * 由 [ByteArrayPool] 缓存并管理, 只可在 [Flow.collect] 中访问.
...@@ -47,13 +50,13 @@ internal class ChunkedInput( ...@@ -47,13 +50,13 @@ internal class ChunkedInput(
* *
* **注意**: 不要将他带出 [Flow.collect] 作用域, 否则将造成内存泄露 * **注意**: 不要将他带出 [Flow.collect] 作用域, 否则将造成内存泄露
*/ */
@JvmField val buffer: ByteArray, @JvmField public val buffer: ByteArray,
@JvmField internal var size: Int @JvmField internal var size: Int
) { ) {
/** /**
* [buffer] 的有效大小 * [buffer] 的有效大小
*/ */
inline val bufferSize: Int get() = size public val bufferSize: Int get() = size
} }
/** /**
......
...@@ -4,15 +4,7 @@ package net.mamoe.mirai.utils.internal ...@@ -4,15 +4,7 @@ package net.mamoe.mirai.utils.internal
import kotlinx.io.pool.DefaultPool import kotlinx.io.pool.DefaultPool
import kotlinx.io.pool.ObjectPool import kotlinx.io.pool.ObjectPool
import java.io.InputStream
internal expect abstract class InputStream {
open fun available(): Int
open fun close()
abstract fun read(): Int
open fun read(b: ByteArray): Int
open fun read(b: ByteArray, offset: Int, len: Int): Int
open fun skip(n: Long): Long
}
internal expect fun InputStream.md5(): ByteArray internal expect fun InputStream.md5(): ByteArray
internal expect fun ByteArray.md5(offset: Int = 0, length: Int = this.size - offset): ByteArray internal expect fun ByteArray.md5(offset: Int = 0, length: Int = this.size - offset): ByteArray
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* *
* https://github.com/mamoe/mirai/blob/master/LICENSE * https://github.com/mamoe/mirai/blob/master/LICENSE
*/ */
@file:Suppress("unused", "DEPRECATION_ERROR", "EXPOSED_SUPER_CLASS") @file:Suppress("unused", "DEPRECATION_ERROR", "EXPOSED_SUPER_CLASS")
package net.mamoe.mirai.utils package net.mamoe.mirai.utils
...@@ -63,7 +64,7 @@ public actual open class BotConfiguration : BotConfigurationBase() { // open for ...@@ -63,7 +64,7 @@ public actual open class BotConfiguration : BotConfigurationBase() { // open for
@SinceMirai("1.2.0") @SinceMirai("1.2.0")
public actual fun loadDeviceInfoJson(json: String) { public actual fun loadDeviceInfoJson(json: String) {
deviceInfo = { context -> deviceInfo = { context ->
this.json.parse(DeviceInfoData.serializer(), json).also { it.context = context } this.json.decodeFromString(DeviceInfoData.serializer(), json).also { it.context = context }
} }
} }
......
...@@ -6,13 +6,9 @@ import kotlinx.io.core.* ...@@ -6,13 +6,9 @@ import kotlinx.io.core.*
import kotlinx.io.streams.asInput import kotlinx.io.streams.asInput
import kotlinx.io.streams.asOutput import kotlinx.io.streams.asOutput
import net.mamoe.mirai.Bot import net.mamoe.mirai.Bot
import net.mamoe.mirai.utils.internal.InputStream
import net.mamoe.mirai.utils.internal.asReusableInput import net.mamoe.mirai.utils.internal.asReusableInput
import java.awt.image.BufferedImage import java.awt.image.BufferedImage
import java.io.ByteArrayOutputStream import java.io.*
import java.io.File
import java.io.IOException
import java.io.OutputStream
import java.net.URL import java.net.URL
import java.security.MessageDigest import java.security.MessageDigest
import java.util.* import java.util.*
......
...@@ -30,9 +30,6 @@ import java.io.RandomAccessFile ...@@ -30,9 +30,6 @@ import java.io.RandomAccessFile
import javax.imageio.ImageIO import javax.imageio.ImageIO
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias Throws = kotlin.jvm.Throws
/** /**
* 自动选择 [SwingSolver] 或 [StandardCharImageLoginSolver] * 自动选择 [SwingSolver] 或 [StandardCharImageLoginSolver]
*/ */
......
...@@ -24,10 +24,10 @@ import kotlin.random.nextInt ...@@ -24,10 +24,10 @@ import kotlin.random.nextInt
public fun File.loadAsDeviceInfo(json: Json, context: Context = ContextImpl()): DeviceInfo { public fun File.loadAsDeviceInfo(json: Json, context: Context = ContextImpl()): DeviceInfo {
if (!this.exists() || this.length() == 0L) { if (!this.exists() || this.length() == 0L) {
return SystemDeviceInfo(context).also { return SystemDeviceInfo(context).also {
this.writeText(json.stringify(SystemDeviceInfo.serializer(), it)) this.writeText(json.encodeToString(SystemDeviceInfo.serializer(), it))
} }
} }
return json.parse(DeviceInfoData.serializer(), this.readText()).also { return json.decodeFromString(DeviceInfoData.serializer(), this.readText()).also {
it.context = context it.context = context
} }
} }
......
...@@ -6,6 +6,7 @@ import kotlinx.coroutines.withContext ...@@ -6,6 +6,7 @@ import kotlinx.coroutines.withContext
import kotlinx.io.core.Input import kotlinx.io.core.Input
import net.mamoe.mirai.utils.FileCacheStrategy import net.mamoe.mirai.utils.FileCacheStrategy
import java.awt.image.BufferedImage import java.awt.image.BufferedImage
import java.io.InputStream
import java.net.URL import java.net.URL
internal actual class DeferredReusableInput actual constructor( internal actual class DeferredReusableInput actual constructor(
...@@ -44,7 +45,7 @@ internal actual class DeferredReusableInput actual constructor( ...@@ -44,7 +45,7 @@ internal actual class DeferredReusableInput actual constructor(
return delegate?.writeTo(out) ?: error("DeferredReusableInput not yet initialized") return delegate?.writeTo(out) ?: error("DeferredReusableInput not yet initialized")
} }
override fun asInput(): Input { override fun asInput(): InputStream {
return delegate?.asInput() ?: error("DeferredReusableInput not yet initialized") return delegate?.asInput() ?: error("DeferredReusableInput not yet initialized")
} }
......
...@@ -8,6 +8,7 @@ import kotlinx.io.core.ByteReadPacket ...@@ -8,6 +8,7 @@ import kotlinx.io.core.ByteReadPacket
import kotlinx.io.core.Input import kotlinx.io.core.Input
import kotlinx.io.streams.asInput import kotlinx.io.streams.asInput
import net.mamoe.mirai.message.data.toLongUnsigned import net.mamoe.mirai.message.data.toLongUnsigned
import java.io.ByteArrayInputStream
import java.io.File import java.io.File
import java.io.InputStream import java.io.InputStream
...@@ -36,8 +37,8 @@ internal actual fun ByteArray.asReusableInput(): ReusableInput { ...@@ -36,8 +37,8 @@ internal actual fun ByteArray.asReusableInput(): ReusableInput {
return this@asReusableInput.size.toLongUnsigned() return this@asReusableInput.size.toLongUnsigned()
} }
override fun asInput(): Input { override fun asInput(): InputStream {
return ByteReadPacket(this@asReusableInput) return ByteArrayInputStream(this@asReusableInput)
} }
} }
} }
...@@ -62,8 +63,8 @@ internal fun File.asReusableInput(deleteOnClose: Boolean): ReusableInput { ...@@ -62,8 +63,8 @@ internal fun File.asReusableInput(deleteOnClose: Boolean): ReusableInput {
return inputStream().use { it.copyTo(out) } return inputStream().use { it.copyTo(out) }
} }
override fun asInput(): Input { override fun asInput(): InputStream {
return inputStream().asInput() return inputStream()
} }
} }
} }
...@@ -88,8 +89,8 @@ internal fun File.asReusableInput(deleteOnClose: Boolean, md5: ByteArray): Reusa ...@@ -88,8 +89,8 @@ internal fun File.asReusableInput(deleteOnClose: Boolean, md5: ByteArray): Reusa
return inputStream().use { it.copyTo(out) } return inputStream().use { it.copyTo(out) }
} }
override fun asInput(): Input { override fun asInput(): InputStream {
return inputStream().asInput() return inputStream()
} }
} }
} }
......
...@@ -17,7 +17,4 @@ internal actual fun InputStream.md5(): ByteArray { ...@@ -17,7 +17,4 @@ internal actual fun InputStream.md5(): ByteArray {
digest.update(buf, 0, len) digest.update(buf, 0, len)
} }
return digest.digest() return digest.digest()
} }
\ No newline at end of file
@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias InputStream = java.io.InputStream
\ No newline at end of file
package net.mamoe.mirai.utils.internal
private var isAddSuppressedSupported: Boolean = true
internal actual fun Throwable.addSuppressedMirai(e: Throwable) {
if (this == e) {
return
}
if (!isAddSuppressedSupported) {
return
}
try {
this.addSuppressed(e)
} catch (e: Exception) {
isAddSuppressedSupported = false
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment