Coverage Summary for Class: ProtoOneofEventSerializer (com.ghost.serialization.integration.model)
| Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| ProtoOneofEventSerializer |
100%
(1/1)
|
80%
(8/10)
|
40.5%
(17/42)
|
71.1%
(64/90)
|
67.1%
(300/447)
|
@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.parser.GhostJsonFlatReader
import com.ghost.serialization.parser.GhostJsonReader
import com.ghost.serialization.parser.GhostWrappedKeysCapture
import com.ghost.serialization.parser.JsonReaderOptions
import com.ghost.serialization.parser.beginObject
import com.ghost.serialization.parser.captureWrappedKey
import com.ghost.serialization.parser.endObject
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
import kotlin.ByteArray
import kotlin.IntArray
import okio.ByteString
import okio.ByteString.Companion.encodeUtf8
/**
* High-performance serializer for [ProtoOneofEvent].
* Generated by GhostSerialization. Do not modify manually.
*/
public object ProtoOneofEventSerializer : GhostSerializer<ProtoOneofEvent> {
override val typeName: String = "ProtoOneofEvent"
override val isProto: Boolean = true
private val OPTIONS: JsonReaderOptions =
JsonReaderOptions.of(0, 31, 128, false, "id", "text", "code")
private val H_CODE: ByteString = "\"code\":".encodeUtf8()
private val H_ID: ByteString = "\"id\":".encodeUtf8()
private val H_TEXT: ByteString = "\"text\":".encodeUtf8()
private const val MASK_ID: Long = 1L
private const val MASK_PAYLOAD: Long = 2L
private const val MASK_REQUIRED_0: Long = 3L
private val WRAPPED_KEY_LITERALS_PAYLOAD: Array<ByteArray> = arrayOf(
"\"text\":".encodeToByteArray(),
"\"code\":".encodeToByteArray()
)
private val WRAPPED_OMIT_ABSENT_PAYLOAD: IntArray = intArrayOf()
private fun validateRequiredFields(mask0: Long, reader: GhostJsonReader) {
if ((mask0 and MASK_REQUIRED_0) != MASK_REQUIRED_0) {
if ((mask0 and MASK_ID) == 0L) {
reader.throwError("Required field 'id' missing in JSON")
} else if ((mask0 and MASK_PAYLOAD) == 0L) {
reader.throwError("Required field 'payload' missing in JSON")
}
}
}
/**
* Robust deserialization for [ProtoOneofEvent].
*/
override fun deserialize(reader: GhostJsonReader): ProtoOneofEvent {
var idValue: String? = null
var payloadValue: OneofPayload? = null
val wrappedCapture_payload = GhostWrappedKeysCapture(2)
var mask0 = 0L
reader.beginObject()
while (true) {
val index = reader.selectNameAndConsume(OPTIONS)
when (index) {
0 -> {
idValue = reader.nextString()
mask0 = mask0 or MASK_ID
}
1 -> {
reader.captureWrappedKey(wrappedCapture_payload, 0)
}
2 -> {
reader.captureWrappedKey(wrappedCapture_payload, 1)
}
-1 -> break
-2 -> {
reader.skipValue()
}
}
}
reader.endObject()
val wrappedJson_payload = wrappedCapture_payload.materializeWrappedObject(WRAPPED_KEY_LITERALS_PAYLOAD, false, WRAPPED_OMIT_ABSENT_PAYLOAD)
if (wrappedJson_payload != null) {
val wrappedReader = GhostJsonReader(wrappedJson_payload)
payloadValue = OneofPayloadSerializer.deserialize(wrappedReader)
mask0 = mask0 or MASK_PAYLOAD
} else {
}
validateRequiredFields(mask0, reader)
return ProtoOneofEvent(
id = idValue!!,
payload = payloadValue!!,
)
}
private fun validateRequiredFields(mask0: Long, reader: GhostJsonFlatReader) {
if ((mask0 and MASK_REQUIRED_0) != MASK_REQUIRED_0) {
if ((mask0 and MASK_ID) == 0L) {
reader.throwError("Required field 'id' missing in JSON")
} else if ((mask0 and MASK_PAYLOAD) == 0L) {
reader.throwError("Required field 'payload' missing in JSON")
}
}
}
/**
* Robust deserialization for [ProtoOneofEvent].
*/
override fun deserialize(reader: GhostJsonFlatReader): ProtoOneofEvent {
var idValue: String? = null
var payloadValue: OneofPayload? = null
val wrappedCapture_payload = GhostWrappedKeysCapture(2)
var mask0 = 0L
reader.beginObject()
while (true) {
val index = reader.selectNameAndConsume(OPTIONS)
when (index) {
0 -> {
idValue = reader.nextString()
mask0 = mask0 or MASK_ID
}
1 -> {
reader.captureWrappedKey(wrappedCapture_payload, 0)
}
2 -> {
reader.captureWrappedKey(wrappedCapture_payload, 1)
}
-1 -> break
-2 -> {
reader.skipValue()
}
}
}
reader.endObject()
val wrappedJson_payload = wrappedCapture_payload.materializeWrappedObject(WRAPPED_KEY_LITERALS_PAYLOAD, false, WRAPPED_OMIT_ABSENT_PAYLOAD)
if (wrappedJson_payload != null) {
val wrappedReader = GhostJsonFlatReader(wrappedJson_payload)
payloadValue = OneofPayloadSerializer.deserialize(wrappedReader)
mask0 = mask0 or MASK_PAYLOAD
} else {
}
validateRequiredFields(mask0, reader)
return ProtoOneofEvent(
id = idValue!!,
payload = payloadValue!!,
)
}
override fun serialize(writer: GhostJsonWriter, `value`: ProtoOneofEvent) {
writer.beginObject()
if (value.id.isNotEmpty()) {
writer.writeField(H_ID, value.id)
}
if (value.payload is OneofPayload.Text) {
writer.writeNameRaw(H_TEXT)
writer.value((value.payload as OneofPayload.Text).text)
}
if (value.payload is OneofPayload.Code) {
writer.writeNameRaw(H_CODE)
writer.value((value.payload as OneofPayload.Code).code)
}
writer.endObject()
}
override fun serialize(writer: GhostJsonFlatWriter, `value`: ProtoOneofEvent) {
writer.beginObject()
if (value.id.isNotEmpty()) {
writer.writeField(H_ID, value.id)
}
if (value.payload is OneofPayload.Text) {
writer.writeNameRaw(H_TEXT)
writer.value((value.payload as OneofPayload.Text).text)
}
if (value.payload is OneofPayload.Code) {
writer.writeNameRaw(H_CODE)
writer.value((value.payload as OneofPayload.Code).code)
}
writer.endObject()
}
override fun warmUp() {
try {
val reader1 = GhostJsonReader("{\"id\":\"\",\"payload\":{}}".encodeToByteArray())
deserialize(reader1)
} catch (_: Exception) {
}
try {
val reader2 = GhostJsonFlatReader("{\"id\":\"\",\"payload\":{}}".encodeToByteArray())
deserialize(reader2)
} catch (_: Exception) {
}
}
}