Coverage Summary for Class: WireExtras12Serializer (com.ghost.serialization.integration.model)
| Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| WireExtras12Serializer |
100%
(1/1)
|
77.8%
(7/9)
|
60%
(12/20)
|
76.7%
(46/60)
|
74%
(199/269)
|
@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 [WireExtras12].
* Generated by GhostSerialization. Do not modify manually.
*/
public object WireExtras12Serializer : GhostSerializer<WireExtras12> {
override val typeName: String = "WireExtras12"
private val OPTIONS: JsonReaderOptions =
JsonReaderOptions.of(0, 31, 128, false, "extra1", "extra2")
private val H_EXTRA1: ByteString = "\"extra1\":".encodeUtf8()
private val H_EXTRA2: ByteString = "\"extra2\":".encodeUtf8()
private const val MASK_EXTRA1: Long = 1L
private const val MASK_EXTRA2: Long = 2L
private const val MASK_REQUIRED_0: Long = 3L
private fun validateRequiredFields(mask0: Long, reader: GhostJsonReader) {
if ((mask0 and MASK_REQUIRED_0) != MASK_REQUIRED_0) {
if ((mask0 and MASK_EXTRA1) == 0L) {
reader.throwError("Required field 'extra1' missing in JSON")
} else if ((mask0 and MASK_EXTRA2) == 0L) {
reader.throwError("Required field 'extra2' missing in JSON")
}
}
}
/**
* Robust deserialization for [WireExtras12].
*/
override fun deserialize(reader: GhostJsonReader): WireExtras12 {
var extra1Value: String? = null
var extra2Value: String? = null
var mask0 = 0L
reader.beginObject()
while (true) {
val index = reader.selectNameAndConsume(OPTIONS)
when (index) {
0 -> {
extra1Value = reader.nextString()
mask0 = mask0 or MASK_EXTRA1
}
1 -> {
extra2Value = reader.nextString()
mask0 = mask0 or MASK_EXTRA2
}
-1 -> break
-2 -> {
reader.skipValue()
}
}
}
reader.endObject()
validateRequiredFields(mask0, reader)
return WireExtras12(
extra1 = extra1Value!!,
extra2 = extra2Value!!,
)
}
private fun validateRequiredFields(mask0: Long, reader: GhostJsonFlatReader) {
if ((mask0 and MASK_REQUIRED_0) != MASK_REQUIRED_0) {
if ((mask0 and MASK_EXTRA1) == 0L) {
reader.throwError("Required field 'extra1' missing in JSON")
} else if ((mask0 and MASK_EXTRA2) == 0L) {
reader.throwError("Required field 'extra2' missing in JSON")
}
}
}
/**
* Robust deserialization for [WireExtras12].
*/
override fun deserialize(reader: GhostJsonFlatReader): WireExtras12 {
var extra1Value: String? = null
var extra2Value: String? = null
var mask0 = 0L
reader.beginObject()
while (true) {
val index = reader.selectNameAndConsume(OPTIONS)
when (index) {
0 -> {
extra1Value = reader.nextString()
mask0 = mask0 or MASK_EXTRA1
}
1 -> {
extra2Value = reader.nextString()
mask0 = mask0 or MASK_EXTRA2
}
-1 -> break
-2 -> {
reader.skipValue()
}
}
}
reader.endObject()
validateRequiredFields(mask0, reader)
return WireExtras12(
extra1 = extra1Value!!,
extra2 = extra2Value!!,
)
}
override fun serialize(writer: GhostJsonWriter, `value`: WireExtras12) {
writer.beginObject()
writer.writeField(H_EXTRA1, value.extra1)
writer.writeField(H_EXTRA2, value.extra2)
writer.endObject()
}
override fun serialize(writer: GhostJsonFlatWriter, `value`: WireExtras12) {
writer.beginObject()
writer.writeField(H_EXTRA1, value.extra1)
writer.writeField(H_EXTRA2, value.extra2)
writer.endObject()
}
override fun warmUp() {
try {
val reader1 = GhostJsonReader("{\"extra1\":\"\",\"extra2\":\"\"}".encodeToByteArray())
deserialize(reader1)
} catch (_: Exception) {
}
try {
val reader2 = GhostJsonFlatReader("{\"extra1\":\"\",\"extra2\":\"\"}".encodeToByteArray())
deserialize(reader2)
} catch (_: Exception) {
}
}
}