Coverage Summary for Class: DecimalStressSerializer (com.ghost.serialization.integration.model)
| Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| DecimalStressSerializer |
100%
(1/1)
|
88.9%
(8/9)
|
38.5%
(10/26)
|
74.7%
(56/75)
|
65.6%
(217/331)
|
@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.nextDouble
import com.ghost.serialization.parser.nextFloat
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 [DecimalStress].
* Generated by GhostSerialization. Do not modify manually.
*/
public object DecimalStressSerializer : GhostSerializer<DecimalStress> {
override val typeName: String = "DecimalStress"
private val OPTIONS: JsonReaderOptions =
JsonReaderOptions.of(0, 31, 128, false, "big", "small", "precise")
private val H_BIG: ByteString = "\"big\":".encodeUtf8()
private val H_PRECISE: ByteString = "\"precise\":".encodeUtf8()
private val H_SMALL: ByteString = "\"small\":".encodeUtf8()
private const val MASK_BIG: Long = 1L
private const val MASK_SMALL: Long = 2L
private const val MASK_PRECISE: Long = 4L
private const val MASK_REQUIRED_0: Long = 7L
private fun validateRequiredFields(mask0: Long, reader: GhostJsonReader) {
if ((mask0 and MASK_REQUIRED_0) != MASK_REQUIRED_0) {
if ((mask0 and MASK_BIG) == 0L) {
reader.throwError("Required field 'big' missing in JSON")
} else if ((mask0 and MASK_SMALL) == 0L) {
reader.throwError("Required field 'small' missing in JSON")
} else if ((mask0 and MASK_PRECISE) == 0L) {
reader.throwError("Required field 'precise' missing in JSON")
}
}
}
/**
* Robust deserialization for [DecimalStress].
*/
override fun deserialize(reader: GhostJsonReader): DecimalStress {
var bigValue: Double = 0.0
var smallValue: Float = 0.0f
var preciseValue: Double = 0.0
var mask0 = 0L
reader.beginObject()
while (true) {
val index = reader.selectNameAndConsume(OPTIONS)
when (index) {
0 -> {
bigValue = reader.nextDouble()
mask0 = mask0 or MASK_BIG
}
1 -> {
smallValue = reader.nextFloat()
mask0 = mask0 or MASK_SMALL
}
2 -> {
preciseValue = reader.nextDouble()
mask0 = mask0 or MASK_PRECISE
}
-1 -> break
-2 -> {
reader.skipValue()
}
}
}
reader.endObject()
validateRequiredFields(mask0, reader)
return DecimalStress(
big = bigValue,
small = smallValue,
precise = preciseValue,
)
}
private fun validateRequiredFields(mask0: Long, reader: GhostJsonFlatReader) {
if ((mask0 and MASK_REQUIRED_0) != MASK_REQUIRED_0) {
if ((mask0 and MASK_BIG) == 0L) {
reader.throwError("Required field 'big' missing in JSON")
} else if ((mask0 and MASK_SMALL) == 0L) {
reader.throwError("Required field 'small' missing in JSON")
} else if ((mask0 and MASK_PRECISE) == 0L) {
reader.throwError("Required field 'precise' missing in JSON")
}
}
}
/**
* Robust deserialization for [DecimalStress].
*/
override fun deserialize(reader: GhostJsonFlatReader): DecimalStress {
var bigValue: Double = 0.0
var smallValue: Float = 0.0f
var preciseValue: Double = 0.0
var mask0 = 0L
reader.beginObject()
while (true) {
val index = reader.selectNameAndConsume(OPTIONS)
when (index) {
0 -> {
bigValue = reader.nextDouble()
mask0 = mask0 or MASK_BIG
}
1 -> {
smallValue = reader.nextFloat()
mask0 = mask0 or MASK_SMALL
}
2 -> {
preciseValue = reader.nextDouble()
mask0 = mask0 or MASK_PRECISE
}
-1 -> break
-2 -> {
reader.skipValue()
}
}
}
reader.endObject()
validateRequiredFields(mask0, reader)
return DecimalStress(
big = bigValue,
small = smallValue,
precise = preciseValue,
)
}
override fun serialize(writer: GhostJsonWriter, `value`: DecimalStress) {
writer.beginObject()
writer.writeField(H_BIG, value.big)
writer.writeField(H_SMALL, value.small)
writer.writeField(H_PRECISE, value.precise)
writer.endObject()
}
override fun serialize(writer: GhostJsonFlatWriter, `value`: DecimalStress) {
writer.beginObject()
writer.writeField(H_BIG, value.big)
writer.writeField(H_SMALL, value.small)
writer.writeField(H_PRECISE, value.precise)
writer.endObject()
}
override fun warmUp() {
try {
val reader1 = GhostJsonReader("{\"big\":0.0,\"small\":0.0,\"precise\":0.0}".encodeToByteArray())
deserialize(reader1)
} catch (_: Exception) {
}
try {
val reader2 = GhostJsonFlatReader("{\"big\":0.0,\"small\":0.0,\"precise\":0.0}".encodeToByteArray())
deserialize(reader2)
} catch (_: Exception) {
}
}
}