ProtoBuf utilities

This commit is contained in:
Him188 2020-01-29 16:26:25 +08:00
parent 2f2a8666b9
commit 1c285b1cb8

View File

@ -1,7 +1,32 @@
package net.mamoe.mirai.qqandroid.io
import kotlinx.io.core.Input
import kotlinx.io.core.readBytes
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.SerializationStrategy
/**
* 仅有标示作用
*/
interface ProtoBuf {
interface ProtoBuf
/**
* dump
*/
fun <T : ProtoBuf> T.toByteArray(serializer: SerializationStrategy<T>): ByteArray {
return kotlinx.serialization.protobuf.ProtoBuf.dump(serializer, this)
}
/**
* load
*/
fun <T : ProtoBuf> ByteArray.loadAs(serializer: DeserializationStrategy<T>): T {
return kotlinx.serialization.protobuf.ProtoBuf.load(serializer, this)
}
/**
* load
*/
fun <T : ProtoBuf> Input.readRemainingAsProtoBuf(serializer: DeserializationStrategy<T>): T {
return kotlinx.serialization.protobuf.ProtoBuf.load(serializer, this.readBytes())
}