kernl.data.source.serialize.SerializableSerializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Kernl.Runtime Show documentation
Show all versions of Kernl.Runtime Show documentation
Kernl: A Kotlin Symbol Processing (KSP) library for automatic repository generation.
package io.github.mattshoe.shoebox.kernl.data.source.serialize
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.ObjectInputStream
import java.io.ObjectOutputStream
import java.io.Serializable
class SerializableSerializer : Serializer {
override fun serialize(data: T): ByteArray {
val byteArrayOutputStream = ByteArrayOutputStream()
ObjectOutputStream(byteArrayOutputStream).use { it.writeObject(data) }
return byteArrayOutputStream.toByteArray()
}
@Suppress("UNCHECKED_CAST")
override fun deserialize(data: ByteArray): T {
val byteArrayInputStream = ByteArrayInputStream(data)
return ObjectInputStream(byteArrayInputStream).use { it.readObject() as T }
}
}