mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 15:40:28 +08:00
Add serializers for PermissionId
This commit is contained in:
parent
cce8c2db16
commit
a881235caa
@ -9,13 +9,17 @@
|
||||
|
||||
package net.mamoe.mirai.console.permission
|
||||
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.Serializer
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
import net.mamoe.mirai.console.internal.data.map
|
||||
|
||||
|
||||
/**
|
||||
* [PermissionId] 与 [Permission] 唯一对应.
|
||||
*/
|
||||
@Serializable
|
||||
@Serializable(with = PermissionId.AsStringSerializer::class)
|
||||
@ExperimentalPermission
|
||||
public data class PermissionId(
|
||||
public val namespace: String,
|
||||
@ -30,6 +34,14 @@ public data class PermissionId(
|
||||
}
|
||||
}
|
||||
|
||||
@Serializer(forClass = PermissionId::class)
|
||||
public object AsClassSerializer
|
||||
|
||||
public object AsStringSerializer : KSerializer<PermissionId> by String.serializer().map(
|
||||
serializer = { it.namespace + ":" + it.id },
|
||||
deserializer = { it.split(':').let { (namespace, id) -> PermissionId(namespace, id) } }
|
||||
)
|
||||
|
||||
public override fun toString(): String {
|
||||
return "$namespace:$id"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user