diff --git a/mirai-core/src/main/java/net/mamoe/mirai/network/packet/server/ServerPacket.kt b/mirai-core/src/main/java/net/mamoe/mirai/network/packet/server/ServerPacket.kt index 44fa1c395..3a1e03de7 100644 --- a/mirai-core/src/main/java/net/mamoe/mirai/network/packet/server/ServerPacket.kt +++ b/mirai-core/src/main/java/net/mamoe/mirai/network/packet/server/ServerPacket.kt @@ -96,8 +96,28 @@ fun ByteArray.dataInputStream(): DataInputStream = DataInputStream(this.inputStr /** * Reset and skip(position) */ -fun <N : Number> DataInputStream.goto(position: N): DataInputStream { +infix fun <N : Number> DataInputStream.goto(position: N): DataInputStream { this.reset() this.skip(position.toLong()); return this +} + +fun <N : Number> DataInputStream.readNBytes(position: N, length: Int): ByteArray { + this.goto(position) + return this.readNBytes(length) +} + +fun <N : Number> DataInputStream.readInt(position: N): Int { + this.goto(position) + return this.readInt(); +} + +fun <N : Number> DataInputStream.readByte(position: N): Byte { + this.goto(position) + return this.readByte(); +} + +fun <N : Number> DataInputStream.readShort(position: N): Short { + this.goto(position) + return this.readShort(); } \ No newline at end of file