Files
libmc/src/nativeMain/kotlin/cn/rtast/mcping/platform/buffer.native.kt
T

37 lines
1.1 KiB
Kotlin
Raw Normal View History

2026-09-03 19:32:46 +08:00
/*
* Copyright © 2026 RTAkland
* Author: RTAkland
* Date: 2026/9/3
*/
package cn.rtast.mcping.platform
import kotlinx.io.Buffer
import kotlinx.io.readByteArray
2026-09-03 22:47:27 +08:00
internal actual class PlatformBuffer {
private val _delegateBuf: Buffer
actual constructor() {
_delegateBuf = Buffer()
}
actual constructor(bytes: ByteArray) {
_delegateBuf = Buffer().apply { write(bytes) }
}
2026-09-03 19:32:46 +08:00
actual fun writeByte(value: Byte) = _delegateBuf.writeByte(value)
2026-09-03 22:47:27 +08:00
actual fun writeShort(value: Short) = _delegateBuf.writeShort(value)
actual fun writeLong(value: Long) = _delegateBuf.writeLong(value)
2026-09-03 19:32:46 +08:00
actual fun writeBytes(bytes: ByteArray) = _delegateBuf.write(bytes)
2026-09-03 22:47:27 +08:00
2026-09-03 19:32:46 +08:00
actual fun readByte(): Byte = _delegateBuf.readByte()
2026-09-03 22:47:27 +08:00
actual fun readShort(): Short = _delegateBuf.readShort()
actual fun readLong(): Long = _delegateBuf.readLong()
2026-09-03 19:32:46 +08:00
actual fun readBytes(length: Int): ByteArray = _delegateBuf.readByteArray(length)
2026-09-03 22:47:27 +08:00
2026-09-03 19:32:46 +08:00
actual fun toByteArray(): ByteArray = _delegateBuf.peek().readByteArray()
actual val size: Int
get() = _delegateBuf.size.toInt()
}