Coverage Summary for Class: UserRoleSerializer (com.ghost.serialization.integration.model)
| Class |
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| UserRoleSerializer |
85.7%
(6/7)
|
20%
(2/10)
|
50%
(12/24)
|
58.1%
(90/155)
|
| UserRoleSerializer$WhenMappings |
|
| Total |
85.7%
(6/7)
|
20%
(2/10)
|
50%
(12/24)
|
58.1%
(90/155)
|
@file:OptIn(InternalGhostApi::class)
package com.ghost.serialization.integration.model
import com.ghost.serialization.InternalGhostApi
import com.ghost.serialization.contract.GhostSerializer
import com.ghost.serialization.exception.GhostJsonException
import com.ghost.serialization.parser.GhostJsonFlatReader
import com.ghost.serialization.parser.GhostJsonReader
import com.ghost.serialization.parser.JsonReaderOptions
import com.ghost.serialization.parser.selectString
import com.ghost.serialization.writer.GhostJsonFlatWriter
import com.ghost.serialization.writer.GhostJsonWriter
/**
* High-performance serializer for [UserRole].
* Generated by GhostSerialization. Do not modify manually.
*/
public object UserRoleSerializer : GhostSerializer<UserRole> {
override val typeName: String = "UserRole"
private val ENUM_OPTIONS: JsonReaderOptions =
JsonReaderOptions.of(0, 31, 128, false, "EDITOR", "VIEWER")
/**
* Robust deserialization for [UserRole].
*/
override fun deserialize(reader: GhostJsonReader): UserRole {
val index = reader.selectString(ENUM_OPTIONS)
return when (index) {
0 -> UserRole.EDITOR
1 -> UserRole.VIEWER
-1 -> reader.throwError("Invalid enum value")
else -> throw GhostJsonException("Unexpected index: $index")
}
}
/**
* Robust deserialization for [UserRole].
*/
override fun deserialize(reader: GhostJsonFlatReader): UserRole {
val index = reader.selectString(ENUM_OPTIONS)
return when (index) {
0 -> UserRole.EDITOR
1 -> UserRole.VIEWER
-1 -> reader.throwError("Invalid enum value")
else -> throw GhostJsonException("Unexpected index: $index")
}
}
override fun serialize(writer: GhostJsonWriter, `value`: UserRole) {
when (value) {
UserRole.EDITOR -> writer.value("EDITOR")
UserRole.VIEWER -> writer.value("VIEWER")
}
}
override fun serialize(writer: GhostJsonFlatWriter, `value`: UserRole) {
when (value) {
UserRole.EDITOR -> writer.value("EDITOR")
UserRole.VIEWER -> writer.value("VIEWER")
}
}
override fun warmUp() {
try {
val reader1 = GhostJsonReader("{}".encodeToByteArray())
deserialize(reader1)
} catch (_: Exception) {
}
try {
val reader2 = GhostJsonFlatReader("{}".encodeToByteArray())
deserialize(reader2)
} catch (_: Exception) {
}
}
}