Coverage Summary for Class: EvolutionModelSerializer (com.ghost.serialization.integration.model)
| Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| EvolutionModelSerializer |
100%
(1/1)
|
77.8%
(7/9)
|
56.2%
(9/16)
|
65%
(39/60)
|
65.6%
(170/259)
|
@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.JsonReaderOptions
import com.ghost.serialization.parser.beginObject
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 okio.ByteString
import okio.ByteString.Companion.encodeUtf8
/**
* High-performance serializer for [EvolutionModel].
* Generated by GhostSerialization. Do not modify manually.
*/
public object EvolutionModelSerializer : GhostSerializer<EvolutionModel> {
override val typeName: String = "EvolutionModel"
private val OPTIONS: JsonReaderOptions =
JsonReaderOptions.of(0, 31, 128, false, "required", "optional")
private val H_OPTIONAL: ByteString = "\"optional\":".encodeUtf8()
private val H_REQUIRED: ByteString = "\"required\":".encodeUtf8()
private const val MASK_REQUIRED: Long = 1L
private const val MASK_OPTIONAL: Long = 2L
private const val MASK_REQUIRED_0: Long = 1L
private const val MASK_OPTS_OPTIONAL: Long = 2L
private fun validateRequiredFields(mask0: Long, reader: GhostJsonReader) {
if ((mask0 and MASK_REQUIRED) == 0L) {
reader.throwError("Required field 'required' missing in JSON")
}
}
/**
* Robust deserialization for [EvolutionModel].
*/
override fun deserialize(reader: GhostJsonReader): EvolutionModel {
var requiredValue: String? = null
var optionalValue: String? = null
var mask0 = 0L
reader.beginObject()
while (true) {
val index = reader.selectNameAndConsume(OPTIONS)
when (index) {
0 -> {
requiredValue = reader.nextString()
mask0 = mask0 or MASK_REQUIRED
}
1 -> {
optionalValue = reader.nextString()
mask0 = mask0 or MASK_OPTIONAL
}
-1 -> break
-2 -> {
reader.skipValue()
}
}
}
reader.endObject()
validateRequiredFields(mask0, reader)
if ((mask0 and MASK_OPTS_OPTIONAL) == MASK_OPTS_OPTIONAL) {
return EvolutionModel(
required = requiredValue!!,
optional = optionalValue!!,
)
}
return EvolutionModel(
required = requiredValue!!,
)
}
private fun validateRequiredFields(mask0: Long, reader: GhostJsonFlatReader) {
if ((mask0 and MASK_REQUIRED) == 0L) {
reader.throwError("Required field 'required' missing in JSON")
}
}
/**
* Robust deserialization for [EvolutionModel].
*/
override fun deserialize(reader: GhostJsonFlatReader): EvolutionModel {
var requiredValue: String? = null
var optionalValue: String? = null
var mask0 = 0L
reader.beginObject()
while (true) {
val index = reader.selectNameAndConsume(OPTIONS)
when (index) {
0 -> {
requiredValue = reader.nextString()
mask0 = mask0 or MASK_REQUIRED
}
1 -> {
optionalValue = reader.nextString()
mask0 = mask0 or MASK_OPTIONAL
}
-1 -> break
-2 -> {
reader.skipValue()
}
}
}
reader.endObject()
validateRequiredFields(mask0, reader)
if ((mask0 and MASK_OPTS_OPTIONAL) == MASK_OPTS_OPTIONAL) {
return EvolutionModel(
required = requiredValue!!,
optional = optionalValue!!,
)
}
return EvolutionModel(
required = requiredValue!!,
)
}
override fun serialize(writer: GhostJsonWriter, `value`: EvolutionModel) {
writer.beginObject()
writer.writeField(H_REQUIRED, value.required)
writer.writeField(H_OPTIONAL, value.optional)
writer.endObject()
}
override fun serialize(writer: GhostJsonFlatWriter, `value`: EvolutionModel) {
writer.beginObject()
writer.writeField(H_REQUIRED, value.required)
writer.writeField(H_OPTIONAL, value.optional)
writer.endObject()
}
override fun warmUp() {
try {
val reader1 = GhostJsonReader("{\"required\":\"\"}".encodeToByteArray())
deserialize(reader1)
} catch (_: Exception) {
}
try {
val reader2 = GhostJsonFlatReader("{\"required\":\"\"}".encodeToByteArray())
deserialize(reader2)
} catch (_: Exception) {
}
}
}