mirror of
https://github.com/tursom/TursomServer.git
synced 2025-02-08 18:50:11 +08:00
add skip
This commit is contained in:
parent
05d90029ae
commit
7045d77c7d
@ -89,6 +89,10 @@ interface ByteBuffer : Closeable {
|
||||
writePosition = 0
|
||||
}
|
||||
|
||||
fun skip(n: Int) {
|
||||
readPosition += n
|
||||
}
|
||||
|
||||
fun get(): Byte = read { it.get() }
|
||||
fun getChar(byteOrder: ByteOrder = ByteOrder.nativeOrder()): Char = read { it.char }
|
||||
fun getShort(byteOrder: ByteOrder = ByteOrder.nativeOrder()): Short = read { it.short }
|
||||
|
@ -11,6 +11,8 @@ package cn.tursom.core.buffer
|
||||
|
||||
import cn.tursom.core.Unsafe.unsafe
|
||||
import cn.tursom.core.isStatic
|
||||
import cn.tursom.core.toInt
|
||||
import java.nio.ByteOrder
|
||||
|
||||
class UnsupportedException : Exception()
|
||||
|
||||
@ -206,3 +208,25 @@ fun <T> ByteBuffer.unSerialize(clazz: Class<T>): T {
|
||||
inline fun <reified T : Any> ByteBuffer.unSerialize(): T {
|
||||
return unSerialize(T::class.java)
|
||||
}
|
||||
|
||||
fun ByteBuffer.getIntWithSize(size: Int, byteOrder: ByteOrder = ByteOrder.nativeOrder()): Int {
|
||||
var time = 4
|
||||
return toInt(byteOrder) {
|
||||
if (--time < size) {
|
||||
get()
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun ByteBuffer.getLongWithSize(size: Int, byteOrder: ByteOrder = ByteOrder.nativeOrder()): Int {
|
||||
var time = 8
|
||||
return toInt(byteOrder) {
|
||||
if (--time < size) {
|
||||
get()
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user