Commit 1cd1a19d authored by Him188's avatar Him188

Fast-fail check

parent 625d48f3
...@@ -5,6 +5,7 @@ package net.mamoe.mirai.utils.io ...@@ -5,6 +5,7 @@ package net.mamoe.mirai.utils.io
import kotlinx.io.core.ByteReadPacket import kotlinx.io.core.ByteReadPacket
import kotlinx.io.core.String import kotlinx.io.core.String
import kotlinx.io.core.use import kotlinx.io.core.use
import net.mamoe.mirai.utils.checkOffsetAndLength
import kotlin.contracts.ExperimentalContracts import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind import kotlin.contracts.InvocationKind
import kotlin.contracts.contract import kotlin.contracts.contract
...@@ -16,6 +17,7 @@ import kotlin.jvm.JvmSynthetic ...@@ -16,6 +17,7 @@ import kotlin.jvm.JvmSynthetic
@Suppress("DuplicatedCode") // false positive. foreach is not common to UByteArray and ByteArray @Suppress("DuplicatedCode") // false positive. foreach is not common to UByteArray and ByteArray
@UseExperimental(ExperimentalUnsignedTypes::class) @UseExperimental(ExperimentalUnsignedTypes::class)
fun List<Byte>.toUHexString(separator: String = " ", offset: Int = 0, length: Int = this.size - offset): String { fun List<Byte>.toUHexString(separator: String = " ", offset: Int = 0, length: Int = this.size - offset): String {
this.checkOffsetAndLength(offset, length)
if (length == 0) { if (length == 0) {
return "" return ""
} }
...@@ -36,6 +38,7 @@ fun List<Byte>.toUHexString(separator: String = " ", offset: Int = 0, length: In ...@@ -36,6 +38,7 @@ fun List<Byte>.toUHexString(separator: String = " ", offset: Int = 0, length: In
@Suppress("DuplicatedCode") // false positive. foreach is not common to UByteArray and ByteArray @Suppress("DuplicatedCode") // false positive. foreach is not common to UByteArray and ByteArray
@UseExperimental(ExperimentalUnsignedTypes::class) @UseExperimental(ExperimentalUnsignedTypes::class)
fun ByteArray.toUHexString(separator: String = " ", offset: Int = 0, length: Int = this.size - offset): String { fun ByteArray.toUHexString(separator: String = " ", offset: Int = 0, length: Int = this.size - offset): String {
this.checkOffsetAndLength(offset, length)
if (length == 0) { if (length == 0) {
return "" return ""
} }
...@@ -72,7 +75,8 @@ fun UByteArray.toUHexString(separator: String = " ", offset: Int = 0, length: In ...@@ -72,7 +75,8 @@ fun UByteArray.toUHexString(separator: String = " ", offset: Int = 0, length: In
} }
} }
fun ByteArray.encodeToString(): String = String(this) @Suppress("NOTHING_TO_INLINE")
inline fun ByteArray.encodeToString(): String = String(this)
fun ByteArray.toReadPacket(offset: Int = 0, length: Int = this.size) = ByteReadPacket(this, offset = offset, length = length) fun ByteArray.toReadPacket(offset: Int = 0, length: Int = this.size) = ByteReadPacket(this, offset = offset, length = length)
......
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