bump kommons

This commit is contained in:
DBotThePony 2024-02-03 20:49:59 +07:00
parent c5d1e0f4c7
commit c4241a027a
Signed by: DBot
GPG Key ID: DCC23B5715498507
7 changed files with 8 additions and 63 deletions

View File

@ -2,7 +2,7 @@ kotlin.code.style=official
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m
kotlinVersion=1.9.0
kommonsVersion=1.7.1
kommonsVersion=1.7.3
ffiVersion=2.2.13
lwjglVersion=3.3.0

View File

@ -1,9 +1,9 @@
package ru.dbotthepony.kstarbound.client.network.packets
import ru.dbotthepony.kommons.io.readUUID
import ru.dbotthepony.kommons.io.writeUUID
import ru.dbotthepony.kstarbound.client.network.ClientConnection
import ru.dbotthepony.kstarbound.client.world.ClientWorld
import ru.dbotthepony.kstarbound.io.readUUID
import ru.dbotthepony.kstarbound.io.writeUUID
import ru.dbotthepony.kstarbound.network.IClientPacket
import ru.dbotthepony.kstarbound.world.World
import ru.dbotthepony.kstarbound.world.WorldGeometry

View File

@ -1,6 +1,7 @@
package ru.dbotthepony.kstarbound.io
import it.unimi.dsi.fastutil.ints.IntArraySet
import ru.dbotthepony.kommons.io.readString
import ru.dbotthepony.kommons.io.readVarInt
import ru.dbotthepony.kommons.io.readVarIntInfo
import java.io.*

View File

@ -23,36 +23,6 @@ import java.util.function.IntConsumer
import java.util.function.IntSupplier
import kotlin.collections.ArrayList
fun RandomAccessFile.readString(length: Int): String {
require(length >= 0) { "Invalid length $length" }
val bytes = ByteArray(length)
try {
readFully(bytes)
} catch(err: Throwable) {
throw IOException("Tried to read string with length of $length", err)
}
return bytes.toString(Charsets.UTF_8)
}
fun InputStream.readString(length: Int, allowSmaller: Boolean = false): String {
require(length >= 0) { "Invalid length $length" }
val bytes = ByteArray(length)
try {
val read = readNBytes(bytes, 0, length)
if (!allowSmaller)
require(read == bytes.size) { "Read $read bytes, expected ${bytes.size}" }
} catch(err: Throwable) {
throw IOException("Tried to read string with length of $length", err)
}
return bytes.toString(Charsets.UTF_8)
}
fun InputStream.readByteChar(): Char {
return read().toChar()
}
@ -67,32 +37,6 @@ fun InputStream.readHeader(header: String) {
}
}
fun OutputStream.writeUTF(value: String) {
write(value.toByteArray().also { check(!it.any { it.toInt() == 0 }) { "Provided UTF string contains NUL" } })
write(0)
}
fun InputStream.readUTF(): String {
val bytes = ByteArrayList()
var read = read()
while (read != 0) {
bytes.add(read.toByte())
read = read()
}
return String(bytes.toByteArray())
}
fun InputStream.readUUID(): UUID {
return UUID(readLong(), readLong())
}
fun OutputStream.writeUUID(value: UUID) {
writeLong(value.mostSignificantBits)
writeLong(value.leastSignificantBits)
}
fun OutputStream.writeVec2i(value: IStruct2i) {
writeSignedVarInt(value.component1())
writeSignedVarInt(value.component2())

View File

@ -11,8 +11,8 @@ import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonToken
import ru.dbotthepony.kommons.io.readBinaryString
import ru.dbotthepony.kommons.io.readSignedVarLong
import ru.dbotthepony.kommons.io.readString
import ru.dbotthepony.kommons.io.readVarInt
import ru.dbotthepony.kstarbound.io.readString
import java.io.DataInputStream
import java.io.EOFException
import java.io.InputStream

View File

@ -6,6 +6,8 @@ import io.netty.buffer.ByteBufOutputStream
import io.netty.channel.Channel
import io.netty.channel.ChannelHandlerContext
import io.netty.channel.ChannelInboundHandlerAdapter
import ru.dbotthepony.kommons.io.readUUID
import ru.dbotthepony.kommons.io.writeUUID
import ru.dbotthepony.kstarbound.Starbound
import ru.dbotthepony.kstarbound.client.network.ClientConnection
import ru.dbotthepony.kstarbound.network.Connection
@ -16,8 +18,6 @@ import ru.dbotthepony.kstarbound.network.IServerPacket
import ru.dbotthepony.kstarbound.network.readUTF
import ru.dbotthepony.kstarbound.network.writeUTF
import ru.dbotthepony.kstarbound.server.network.ServerConnection
import ru.dbotthepony.kstarbound.io.readUUID
import ru.dbotthepony.kstarbound.io.writeUUID
import java.io.DataInputStream
import java.io.DataOutputStream
import java.util.UUID

View File

@ -1,9 +1,9 @@
package ru.dbotthepony.kstarbound.tools
import com.google.gson.GsonBuilder
import ru.dbotthepony.kommons.io.readString
import ru.dbotthepony.kommons.io.readVarInt
import ru.dbotthepony.kstarbound.io.readHeader
import ru.dbotthepony.kstarbound.io.readString
import ru.dbotthepony.kstarbound.json.readJsonElement
import java.io.BufferedInputStream
import java.io.DataInputStream