Coverage Summary for Class: NestedContainerSerializer (com.ghost.serialization.integration.model)
| Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| NestedContainerSerializer |
100%
(1/1)
|
88.9%
(8/9)
|
53.6%
(15/28)
|
73%
(54/74)
|
70.2%
(238/339)
|
@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.beginArray
import com.ghost.serialization.parser.beginObject
import com.ghost.serialization.parser.consumeNull
import com.ghost.serialization.parser.endArray
import com.ghost.serialization.parser.endObject
import com.ghost.serialization.parser.isNextNullValue
import com.ghost.serialization.parser.nextString
import com.ghost.serialization.parser.readList
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.List
import okio.ByteString
import okio.ByteString.Companion.encodeUtf8
/**
* High-performance serializer for [NestedContainer].
* Generated by GhostSerialization. Do not modify manually.
*/
public object NestedContainerSerializer : GhostSerializer<NestedContainer> {
override val typeName: String = "NestedContainer"
private val OPTIONS: JsonReaderOptions =
JsonReaderOptions.of(0, 31, 128, false, "label", "children")
private val H_CHILDREN: ByteString = "\"children\":".encodeUtf8()
private val H_LABEL: ByteString = "\"label\":".encodeUtf8()
private const val MASK_LABEL: Long = 1L
private const val MASK_CHILDREN: Long = 2L
private const val MASK_REQUIRED_0: Long = 1L
private const val MASK_OPTS_CHILDREN: Long = 2L
private fun validateRequiredFields(mask0: Long, reader: GhostJsonReader) {
if ((mask0 and MASK_LABEL) == 0L) {
reader.throwError("Required field 'label' missing in JSON")
}
}
/**
* Robust deserialization for [NestedContainer].
*/
override fun deserialize(reader: GhostJsonReader): NestedContainer {
var labelValue: String? = null
var childrenValue: List<NestedContainer>? = null
var mask0 = 0L
reader.beginObject()
while (true) {
val index = reader.selectNameAndConsume(OPTIONS)
when (index) {
0 -> {
labelValue = reader.nextString()
mask0 = mask0 or MASK_LABEL
}
1 -> {
childrenValue = if (reader.isNextNullValue()) { reader.consumeNull(); null } else reader.readList { NestedContainerSerializer.deserialize(reader) }
mask0 = mask0 or MASK_CHILDREN
}
-1 -> break
-2 -> {
reader.skipValue()
}
}
}
reader.endObject()
validateRequiredFields(mask0, reader)
if ((mask0 and MASK_OPTS_CHILDREN) == MASK_OPTS_CHILDREN) {
return NestedContainer(
label = labelValue!!,
children = childrenValue,
)
}
return NestedContainer(
label = labelValue!!,
)
}
private fun validateRequiredFields(mask0: Long, reader: GhostJsonFlatReader) {
if ((mask0 and MASK_LABEL) == 0L) {
reader.throwError("Required field 'label' missing in JSON")
}
}
/**
* Robust deserialization for [NestedContainer].
*/
override fun deserialize(reader: GhostJsonFlatReader): NestedContainer {
var labelValue: String? = null
var childrenValue: List<NestedContainer>? = null
var mask0 = 0L
reader.beginObject()
while (true) {
val index = reader.selectNameAndConsume(OPTIONS)
when (index) {
0 -> {
labelValue = reader.nextString()
mask0 = mask0 or MASK_LABEL
}
1 -> {
childrenValue = if (reader.isNextNullValue()) { reader.consumeNull(); null } else reader.readList { NestedContainerSerializer.deserialize(reader) }
mask0 = mask0 or MASK_CHILDREN
}
-1 -> break
-2 -> {
reader.skipValue()
}
}
}
reader.endObject()
validateRequiredFields(mask0, reader)
if ((mask0 and MASK_OPTS_CHILDREN) == MASK_OPTS_CHILDREN) {
return NestedContainer(
label = labelValue!!,
children = childrenValue,
)
}
return NestedContainer(
label = labelValue!!,
)
}
override fun serialize(writer: GhostJsonWriter, `value`: NestedContainer) {
writer.beginObject()
writer.writeField(H_LABEL, value.label)
if (value.children != null) {
writer.writeNameRaw(H_CHILDREN)
writer.beginArray()
val size0 = value.children.size
for (i0 in 0 until size0) {
val item0 = value.children[i0]
NestedContainerSerializer.serialize(writer, item0)
}
writer.endArray()
}
writer.endObject()
}
override fun serialize(writer: GhostJsonFlatWriter, `value`: NestedContainer) {
writer.beginObject()
writer.writeField(H_LABEL, value.label)
if (value.children != null) {
writer.writeNameRaw(H_CHILDREN)
writer.beginArray()
val size0 = value.children.size
for (i0 in 0 until size0) {
val item0 = value.children[i0]
NestedContainerSerializer.serialize(writer, item0)
}
writer.endArray()
}
writer.endObject()
}
override fun warmUp() {
try {
val reader1 = GhostJsonReader("{\"label\":\"\"}".encodeToByteArray())
deserialize(reader1)
} catch (_: Exception) {
}
try {
val reader2 = GhostJsonFlatReader("{\"label\":\"\"}".encodeToByteArray())
deserialize(reader2)
} catch (_: Exception) {
}
}
}