18 lines
575 B
Kotlin
18 lines
575 B
Kotlin
package net.sergeych.bipack
|
|
|
|
import kotlinx.serialization.KSerializer
|
|
import kotlinx.serialization.serializer
|
|
import net.sergeych.bintools.MotherPacker
|
|
import net.sergeych.bintools.toDataSource
|
|
import kotlin.reflect.KType
|
|
|
|
class MotherBipack : MotherPacker {
|
|
override fun <T> pack(type: KType, payload: T): ByteArray {
|
|
return BipackEncoder.encode(serializer(type), payload)
|
|
}
|
|
|
|
override fun <T> unpack(type: KType, packed: ByteArray): T {
|
|
return BipackDecoder.decode<T>(packed.toDataSource(),
|
|
serializer(type) as KSerializer<T>)
|
|
}
|
|
} |