Add vector codecs

This commit is contained in:
DBotThePony 2024-02-05 12:22:56 +07:00
parent abf91f445e
commit 5c26b1087a
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 15 additions and 1 deletions

View File

@ -4,7 +4,7 @@ kotlin.code.style=official
specifyKotlinAsDependency=false
projectGroup=ru.dbotthepony.kommons
projectVersion=1.7.8
projectVersion=1.7.9
guavaDepVersion=33.0.0
gsonDepVersion=2.8.9

View File

@ -9,6 +9,8 @@ import ru.dbotthepony.kommons.vector.Vector3i
import ru.dbotthepony.kommons.vector.Vector4d
import ru.dbotthepony.kommons.vector.Vector4f
import ru.dbotthepony.kommons.vector.Vector4i
import java.io.DataInputStream
import java.io.DataOutputStream
import java.io.InputStream
private inline fun <T, I> InputStream.read2(factory: (I, I) -> T, reader: (InputStream) -> I): T {
@ -34,3 +36,15 @@ fun InputStream.readVector3f() = read3(::Vector3f) { it.readFloat() }
fun InputStream.readVector4i() = read4(::Vector4i) { it.readInt() }
fun InputStream.readVector4d() = read4(::Vector4d) { it.readDouble() }
fun InputStream.readVector4f() = read4(::Vector4f) { it.readFloat() }
val Vector2iCodec = StreamCodec(DataInputStream::readVector2i, DataOutputStream::writeStruct2i)
val Vector2dCodec = StreamCodec(DataInputStream::readVector2d, DataOutputStream::writeStruct2d)
val Vector2fCodec = StreamCodec(DataInputStream::readVector2f, DataOutputStream::writeStruct2f)
val Vector3iCodec = StreamCodec(DataInputStream::readVector3i, DataOutputStream::writeStruct3i)
val Vector3dCodec = StreamCodec(DataInputStream::readVector3d, DataOutputStream::writeStruct3d)
val Vector3fCodec = StreamCodec(DataInputStream::readVector3f, DataOutputStream::writeStruct3f)
val Vector4iCodec = StreamCodec(DataInputStream::readVector4i, DataOutputStream::writeStruct4i)
val Vector4dCodec = StreamCodec(DataInputStream::readVector4d, DataOutputStream::writeStruct4d)
val Vector4fCodec = StreamCodec(DataInputStream::readVector4f, DataOutputStream::writeStruct4f)