Skip to content

Latest commit

 

History

History

catcode2-serialization-kotlinx

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
catcode logo

- 😺 CatCode Ⅱ - Serialization Kotlinx 😺 -

github    |    gitee
> 感谢 Simple Robot 开发团队成员制作的猫猫logo <
> 如果有点击一下⭐的话,猫猫会很开心哦~ <
maven-central npm-latest npm-snapshot

CatCode2 针对 kotlinx-serialization 所实现的序列化模块。 CatCode2 Serialization Kotlinx 允许通过实体类作为一个猫猫码的基本载体使用。

@Serializable
@SerialName("at") // or use @CatCodeTypeName("at")
data class At(val code: Long, val name: String)

@Test
fun sample() {
    val at = At(123456L, "forte")
    val catcode = CatCode.encodeToString(At.serializer(), at)
    val newAt = CatCode.decodeFromString(At.serializer(), catcode)
    
    assertTrue { at == newAt } // pass.
    println(catcode)           // [CAT:at,code=123456,name=forte]
    
    val cqcode = CatCode.encodeToString(At.serializer(), at, "CQ")
    println(cqcode)            // [CQ:at,code=123456,name=forte]
}