Coverage Summary for Class: OneofPayloadSerializer (com.ghost.serialization.integration.model)
| Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| OneofPayloadSerializer |
100%
(1/1)
|
71.4%
(5/7)
|
50%
(17/34)
|
72.6%
(45/62)
|
63%
(221/351)
|
@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.beginObject
import com.ghost.serialization.parser.endObject
import com.ghost.serialization.parser.nextInt
import com.ghost.serialization.parser.nextString
import com.ghost.serialization.parser.selectNameAndConsume
import com.ghost.serialization.parser.skipValue
import com.ghost.serialization.writer.GhostJsonFlatWriter
import com.ghost.serialization.writer.GhostJsonWriter
/**
* High-performance serializer for [OneofPayload].
* Generated by GhostSerialization. Do not modify manually.
*/
public object OneofPayloadSerializer : GhostSerializer<OneofPayload> {
override val typeName: String = "OneofPayload"
private val OPTIONS: JsonReaderOptions = JsonReaderOptions.of(0, 31, 128, false, "code", "text")
/**
* Robust deserialization for [OneofPayload].
*/
override fun deserialize(reader: GhostJsonReader): OneofPayload {
reader.beginObject()
var v0: Int? = null
var v1: String? = null
var eligibilityMask = 3L
var seenMask = 0L
while (true) {
val index = reader.selectNameAndConsume(OPTIONS)
when (index) {
0 -> {
v0 = reader.nextInt()
eligibilityMask = eligibilityMask and 1L
seenMask = seenMask or (1L shl 0)
}
1 -> {
v1 = reader.nextString()
eligibilityMask = eligibilityMask and 2L
seenMask = seenMask or (1L shl 1)
}
-1 -> break
else -> reader.skipValue()
}
}
reader.endObject()
val reqMask0 = 1L
val reqMask1 = 2L
val result = when {
(eligibilityMask and 1L) != 0L && (seenMask and reqMask0) == reqMask0 -> {
OneofPayload.Code(code = v0 ?: throw GhostJsonException("Required field 'code' missing for Code"))
}
(eligibilityMask and 2L) != 0L && (seenMask and reqMask1) == reqMask1 -> {
OneofPayload.Text(text = v1 ?: throw GhostJsonException("Required field 'text' missing for Text"))
}
else -> throw GhostJsonException("Could not infer subclass (eligibilityMask: ${'$'}eligibilityMask, seenMask: ${'$'}seenMask)")
}
return result
}
/**
* Robust deserialization for [OneofPayload].
*/
override fun deserialize(reader: GhostJsonFlatReader): OneofPayload {
reader.beginObject()
var v0: Int? = null
var v1: String? = null
var eligibilityMask = 3L
var seenMask = 0L
while (true) {
val index = reader.selectNameAndConsume(OPTIONS)
when (index) {
0 -> {
v0 = reader.nextInt()
eligibilityMask = eligibilityMask and 1L
seenMask = seenMask or (1L shl 0)
}
1 -> {
v1 = reader.nextString()
eligibilityMask = eligibilityMask and 2L
seenMask = seenMask or (1L shl 1)
}
-1 -> break
else -> reader.skipValue()
}
}
reader.endObject()
val reqMask0 = 1L
val reqMask1 = 2L
val result = when {
(eligibilityMask and 1L) != 0L && (seenMask and reqMask0) == reqMask0 -> {
OneofPayload.Code(code = v0 ?: throw GhostJsonException("Required field 'code' missing for Code"))
}
(eligibilityMask and 2L) != 0L && (seenMask and reqMask1) == reqMask1 -> {
OneofPayload.Text(text = v1 ?: throw GhostJsonException("Required field 'text' missing for Text"))
}
else -> throw GhostJsonException("Could not infer subclass (eligibilityMask: ${'$'}eligibilityMask, seenMask: ${'$'}seenMask)")
}
return result
}
override fun serialize(writer: GhostJsonWriter, `value`: OneofPayload) {
when (value) {
is OneofPayload.Code -> OneofPayload_CodeSerializer.serialize(writer, value)
is OneofPayload.Text -> OneofPayload_TextSerializer.serialize(writer, value)
}
}
override fun serialize(writer: GhostJsonFlatWriter, `value`: OneofPayload) {
when (value) {
is OneofPayload.Code -> OneofPayload_CodeSerializer.serialize(writer, value)
is OneofPayload.Text -> OneofPayload_TextSerializer.serialize(writer, value)
}
}
override fun warmUp() {
try {
val reader1 = GhostJsonReader("{}".encodeToByteArray())
deserialize(reader1)
} catch (_: Exception) {
}
try {
val reader2 = GhostJsonFlatReader("{}".encodeToByteArray())
deserialize(reader2)
} catch (_: Exception) {
}
}
}