Coverage Summary for Class: EmojiKeyModelSerializer (com.ghost.serialization.integration.model)
| Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| EmojiKeyModelSerializer |
100%
(1/1)
|
88.9%
(8/9)
|
46.7%
(14/30)
|
70.8%
(63/89)
|
65.9%
(280/425)
|
@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.nextInt
import com.ghost.serialization.parser.nextKey
import com.ghost.serialization.parser.nextString
import com.ghost.serialization.parser.readMap
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.collections.Map
import okio.ByteString
import okio.ByteString.Companion.encodeUtf8
/**
* High-performance serializer for [EmojiKeyModel].
* Generated by GhostSerialization. Do not modify manually.
*/
public object EmojiKeyModelSerializer : GhostSerializer<EmojiKeyModel> {
override val typeName: String = "EmojiKeyModel"
private val OPTIONS: JsonReaderOptions =
JsonReaderOptions.of(0, 31, 128, false, "familyName", "rocketCount", "emojiMap")
private val H_EMOJIMAP: ByteString = "\"emojiMap\":".encodeUtf8()
private val H_FAMILYNAME: ByteString = "\"familyName\":".encodeUtf8()
private val H_ROCKETCOUNT: ByteString = "\"rocketCount\":".encodeUtf8()
private const val MASK_FAMILYNAME: Long = 1L
private const val MASK_ROCKETCOUNT: Long = 2L
private const val MASK_EMOJIMAP: Long = 4L
private const val MASK_REQUIRED_0: Long = 3L
private const val MASK_OPTS_EMOJIMAP: Long = 4L
private fun validateRequiredFields(mask0: Long, reader: GhostJsonReader) {
if ((mask0 and MASK_REQUIRED_0) != MASK_REQUIRED_0) {
if ((mask0 and MASK_FAMILYNAME) == 0L) {
reader.throwError("Required field 'familyName' missing in JSON")
} else if ((mask0 and MASK_ROCKETCOUNT) == 0L) {
reader.throwError("Required field 'rocketCount' missing in JSON")
}
}
}
/**
* Robust deserialization for [EmojiKeyModel].
*/
override fun deserialize(reader: GhostJsonReader): EmojiKeyModel {
var familyNameValue: String? = null
var rocketCountValue: Int = 0
var emojiMapValue: Map<String, String>? = null
var mask0 = 0L
reader.beginObject()
while (true) {
val index = reader.selectNameAndConsume(OPTIONS)
when (index) {
0 -> {
familyNameValue = reader.nextString()
mask0 = mask0 or MASK_FAMILYNAME
}
1 -> {
rocketCountValue = reader.nextInt()
mask0 = mask0 or MASK_ROCKETCOUNT
}
2 -> {
emojiMapValue = reader.readMap({ reader.nextKey()!! }) { reader.nextString() }
mask0 = mask0 or MASK_EMOJIMAP
}
-1 -> break
-2 -> {
reader.skipValue()
}
}
}
reader.endObject()
validateRequiredFields(mask0, reader)
if ((mask0 and MASK_OPTS_EMOJIMAP) == MASK_OPTS_EMOJIMAP) {
return EmojiKeyModel(
familyName = familyNameValue!!,
rocketCount = rocketCountValue,
emojiMap = emojiMapValue!!,
)
}
return EmojiKeyModel(
familyName = familyNameValue!!,
rocketCount = rocketCountValue,
)
}
private fun validateRequiredFields(mask0: Long, reader: GhostJsonFlatReader) {
if ((mask0 and MASK_REQUIRED_0) != MASK_REQUIRED_0) {
if ((mask0 and MASK_FAMILYNAME) == 0L) {
reader.throwError("Required field 'familyName' missing in JSON")
} else if ((mask0 and MASK_ROCKETCOUNT) == 0L) {
reader.throwError("Required field 'rocketCount' missing in JSON")
}
}
}
/**
* Robust deserialization for [EmojiKeyModel].
*/
override fun deserialize(reader: GhostJsonFlatReader): EmojiKeyModel {
var familyNameValue: String? = null
var rocketCountValue: Int = 0
var emojiMapValue: Map<String, String>? = null
var mask0 = 0L
reader.beginObject()
while (true) {
val index = reader.selectNameAndConsume(OPTIONS)
when (index) {
0 -> {
familyNameValue = reader.nextString()
mask0 = mask0 or MASK_FAMILYNAME
}
1 -> {
rocketCountValue = reader.nextInt()
mask0 = mask0 or MASK_ROCKETCOUNT
}
2 -> {
emojiMapValue = reader.readMap({ reader.nextKey()!! }) { reader.nextString() }
mask0 = mask0 or MASK_EMOJIMAP
}
-1 -> break
-2 -> {
reader.skipValue()
}
}
}
reader.endObject()
validateRequiredFields(mask0, reader)
if ((mask0 and MASK_OPTS_EMOJIMAP) == MASK_OPTS_EMOJIMAP) {
return EmojiKeyModel(
familyName = familyNameValue!!,
rocketCount = rocketCountValue,
emojiMap = emojiMapValue!!,
)
}
return EmojiKeyModel(
familyName = familyNameValue!!,
rocketCount = rocketCountValue,
)
}
override fun serialize(writer: GhostJsonWriter, `value`: EmojiKeyModel) {
writer.beginObject()
writer.writeField(H_FAMILYNAME, value.familyName)
writer.writeField(H_ROCKETCOUNT, value.rocketCount)
writer.writeNameRaw(H_EMOJIMAP)
writer.beginObject()
for ((mapKey0, mapVal0) in value.emojiMap) {
writer.name(mapKey0)
writer.value(mapVal0)
}
writer.endObject()
writer.endObject()
}
override fun serialize(writer: GhostJsonFlatWriter, `value`: EmojiKeyModel) {
writer.beginObject()
writer.writeField(H_FAMILYNAME, value.familyName)
writer.writeField(H_ROCKETCOUNT, value.rocketCount)
writer.writeNameRaw(H_EMOJIMAP)
writer.beginObject()
for ((mapKey0, mapVal0) in value.emojiMap) {
writer.name(mapKey0)
writer.value(mapVal0)
}
writer.endObject()
writer.endObject()
}
override fun warmUp() {
try {
val reader1 = GhostJsonReader("{\"familyName\":\"\",\"rocketCount\":0}".encodeToByteArray())
deserialize(reader1)
} catch (_: Exception) {
}
try {
val reader2 = GhostJsonFlatReader("{\"familyName\":\"\",\"rocketCount\":0}".encodeToByteArray())
deserialize(reader2)
} catch (_: Exception) {
}
}
}