Skip to content

Commit

Permalink
add Vector3fSerializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Aug 3, 2023
1 parent eb83219 commit f832173
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.mineinabyss.idofront.serialization

import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import org.joml.Vector3f

object Vector3fSerializer : KSerializer<Vector3f> {
private val serializer = ListSerializer(Float.serializer())
override val descriptor: SerialDescriptor = serializer.descriptor

override fun serialize(encoder: Encoder, value: Vector3f) {
with(value) {
encoder.encodeSerializableValue(serializer, listOf(x, y, z))
}
}

override fun deserialize(decoder: Decoder): Vector3f {
val (x, y, z) = decoder.decodeSerializableValue(serializer)
return Vector3f(x, y, z)
}
}

0 comments on commit f832173

Please sign in to comment.