Coverage Summary for Class: SmartDevice_ThermostatSerializer (com.ghost.serialization.integration.model)
| Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| SmartDevice_ThermostatSerializer |
100%
(1/1)
|
77.8%
(7/9)
|
60%
(6/10)
|
73.3%
(33/45)
|
69.6%
(133/191)
|
@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.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 [SmartDevice.Thermostat].
* Generated by GhostSerialization. Do not modify manually.
*/
public object SmartDevice_ThermostatSerializer : GhostSerializer<SmartDevice.Thermostat> {
override val typeName: String = "Thermostat"
private val OPTIONS: JsonReaderOptions = JsonReaderOptions.of(0, 31, 128, false, "temperature")
private val H_TEMPERATURE: ByteString = "\"temperature\":".encodeUtf8()
private const val MASK_TEMPERATURE: Long = 1L
private const val MASK_REQUIRED_0: Long = 1L
private fun validateRequiredFields(mask0: Long, reader: GhostJsonReader) {
if ((mask0 and MASK_TEMPERATURE) == 0L) {
reader.throwError("Required field 'temperature' missing in JSON")
}
}
/**
* Robust deserialization for [SmartDevice.Thermostat].
*/
override fun deserialize(reader: GhostJsonReader): SmartDevice.Thermostat {
var temperatureValue: Double = 0.0
var mask0 = 0L
reader.beginObject()
while (true) {
val index = reader.selectNameAndConsume(OPTIONS)
when (index) {
0 -> {
temperatureValue = reader.nextDouble()
mask0 = mask0 or MASK_TEMPERATURE
}
-1 -> break
-2 -> {
reader.skipValue()
}
}
}
reader.endObject()
validateRequiredFields(mask0, reader)
return SmartDevice.Thermostat(
temperature = temperatureValue,
)
}
private fun validateRequiredFields(mask0: Long, reader: GhostJsonFlatReader) {
if ((mask0 and MASK_TEMPERATURE) == 0L) {
reader.throwError("Required field 'temperature' missing in JSON")
}
}
/**
* Robust deserialization for [SmartDevice.Thermostat].
*/
override fun deserialize(reader: GhostJsonFlatReader): SmartDevice.Thermostat {
var temperatureValue: Double = 0.0
var mask0 = 0L
reader.beginObject()
while (true) {
val index = reader.selectNameAndConsume(OPTIONS)
when (index) {
0 -> {
temperatureValue = reader.nextDouble()
mask0 = mask0 or MASK_TEMPERATURE
}
-1 -> break
-2 -> {
reader.skipValue()
}
}
}
reader.endObject()
validateRequiredFields(mask0, reader)
return SmartDevice.Thermostat(
temperature = temperatureValue,
)
}
override fun serialize(writer: GhostJsonWriter, `value`: SmartDevice.Thermostat) {
writer.beginObject()
writer.name("type").value("Thermostat")
writer.writeField(H_TEMPERATURE, value.temperature)
writer.endObject()
}
override fun serialize(writer: GhostJsonFlatWriter, `value`: SmartDevice.Thermostat) {
writer.beginObject()
writer.name("type").value("Thermostat")
writer.writeField(H_TEMPERATURE, value.temperature)
writer.endObject()
}
override fun warmUp() {
try {
val reader1 = GhostJsonReader("{\"temperature\":0.0}".encodeToByteArray())
deserialize(reader1)
} catch (_: Exception) {
}
try {
val reader2 = GhostJsonFlatReader("{\"temperature\":0.0}".encodeToByteArray())
deserialize(reader2)
} catch (_: Exception) {
}
}
}