-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...-serializers/src/main/kotlin/com/mineinabyss/idofront/serialization/Vector3fSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |