mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-08 17:20:11 +08:00
ProtoBuf utilities
This commit is contained in:
parent
2f2a8666b9
commit
1c285b1cb8
@ -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())
|
||||
}
|
Loading…
Reference in New Issue
Block a user