Coverage Summary for Class: SmartHomeSerializer (com.ghost.serialization.integration.model)
| Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| SmartHomeSerializer |
100%
(1/1)
|
77.8%
(7/9)
|
40.9%
(54/132)
|
33.3%
(106/318)
|
36.3%
(556/1533)
|
@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.decodeResilient
import com.ghost.serialization.parser.endArray
import com.ghost.serialization.parser.endObject
import com.ghost.serialization.parser.isNextNullValue
import com.ghost.serialization.parser.nextBoolean
import com.ghost.serialization.parser.nextInt
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 [SmartHome].
* Generated by GhostSerialization. Do not modify manually.
*/
public object SmartHomeSerializer : GhostSerializer<SmartHome> {
override val typeName: String = "SmartHome"
private val OPTIONS: JsonReaderOptions =
JsonReaderOptions.of(0, 31, 128, false, "id", "active", "deviceCount", "devices", "status", "config")
private val H_ACTIVE: ByteString = "\"active\":".encodeUtf8()
private val H_CONFIG: ByteString = "\"config\":".encodeUtf8()
private val H_DEVICECOUNT: ByteString = "\"deviceCount\":".encodeUtf8()
private val H_DEVICES: ByteString = "\"devices\":".encodeUtf8()
private val H_ID: ByteString = "\"id\":".encodeUtf8()
private val H_STATUS: ByteString = "\"status\":".encodeUtf8()
private const val MASK_ID: Long = 1L
private const val MASK_ACTIVE: Long = 2L
private const val MASK_DEVICECOUNT: Long = 4L
private const val MASK_DEVICES: Long = 8L
private const val MASK_STATUS: Long = 16L
private const val MASK_CONFIG: Long = 32L
private const val MASK_REQUIRED_0: Long = 9L
private const val MASK_OPTS_ACTIVE_CONFIG_DEVICECOUNT_STATUS: Long = 54L
private const val MASK_OPTS_ACTIVE_DEVICECOUNT_STATUS: Long = 22L
private const val MASK_OPTS_ACTIVE_CONFIG_DEVICECOUNT: Long = 38L
private const val MASK_OPTS_ACTIVE_CONFIG_STATUS: Long = 50L
private const val MASK_OPTS_CONFIG_DEVICECOUNT_STATUS: Long = 52L
private const val MASK_OPTS_ACTIVE_DEVICECOUNT: Long = 6L
private const val MASK_OPTS_ACTIVE_STATUS: Long = 18L
private const val MASK_OPTS_DEVICECOUNT_STATUS: Long = 20L
private const val MASK_OPTS_ACTIVE_CONFIG: Long = 34L
private const val MASK_OPTS_CONFIG_DEVICECOUNT: Long = 36L
private const val MASK_OPTS_CONFIG_STATUS: Long = 48L
private const val MASK_OPTS_ACTIVE: Long = 2L
private const val MASK_OPTS_DEVICECOUNT: Long = 4L
private const val MASK_OPTS_STATUS: Long = 16L
private const val MASK_OPTS_CONFIG: Long = 32L
private fun validateRequiredFields(mask0: Long, reader: GhostJsonReader) {
if ((mask0 and MASK_REQUIRED_0) != MASK_REQUIRED_0) {
if ((mask0 and MASK_ID) == 0L) {
reader.throwError("Required field 'id' missing in JSON")
} else if ((mask0 and MASK_DEVICES) == 0L) {
reader.throwError("Required field 'devices' missing in JSON")
}
}
}
/**
* Robust deserialization for [SmartHome].
*/
override fun deserialize(reader: GhostJsonReader): SmartHome {
var idValue: String? = null
var activeValue: Boolean? = null
var deviceCountValue: Int = 0
var devicesValue: List<SmartDevice>? = null
var statusValue: HomeStatus? = null
var configValue: HomeConfig? = null
var mask0 = 0L
reader.beginObject()
while (true) {
val index = reader.selectNameAndConsume(OPTIONS)
when (index) {
0 -> {
idValue = reader.nextString()
mask0 = mask0 or MASK_ID
}
1 -> {
reader.decodeResilient { if (reader.isNextNullValue()) { reader.consumeNull(); null } else reader.nextBoolean() }?.let {
activeValue = it
mask0 = mask0 or MASK_ACTIVE
}
}
2 -> {
reader.decodeResilient { reader.nextInt() }?.let {
deviceCountValue = it
mask0 = mask0 or MASK_DEVICECOUNT
}
}
3 -> {
devicesValue = reader.readList { SmartDeviceSerializer.deserialize(reader) }
mask0 = mask0 or MASK_DEVICES
}
4 -> {
reader.decodeResilient { if (reader.isNextNullValue()) { reader.consumeNull(); null } else HomeStatusSerializer.deserialize(reader) }?.let {
statusValue = it
mask0 = mask0 or MASK_STATUS
}
}
5 -> {
reader.decodeResilient { if (reader.isNextNullValue()) { reader.consumeNull(); null } else HomeConfigSerializer.deserialize(reader) }?.let {
configValue = it
mask0 = mask0 or MASK_CONFIG
}
}
-1 -> break
-2 -> {
reader.skipValue()
}
}
}
reader.endObject()
validateRequiredFields(mask0, reader)
if ((mask0 and MASK_OPTS_ACTIVE_CONFIG_DEVICECOUNT_STATUS) == MASK_OPTS_ACTIVE_CONFIG_DEVICECOUNT_STATUS) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
active = activeValue,
deviceCount = deviceCountValue,
status = statusValue,
config = configValue,
)
}
if ((mask0 and MASK_OPTS_ACTIVE_DEVICECOUNT_STATUS) == MASK_OPTS_ACTIVE_DEVICECOUNT_STATUS) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
active = activeValue,
deviceCount = deviceCountValue,
status = statusValue,
)
}
if ((mask0 and MASK_OPTS_ACTIVE_CONFIG_DEVICECOUNT) == MASK_OPTS_ACTIVE_CONFIG_DEVICECOUNT) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
active = activeValue,
deviceCount = deviceCountValue,
config = configValue,
)
}
if ((mask0 and MASK_OPTS_ACTIVE_CONFIG_STATUS) == MASK_OPTS_ACTIVE_CONFIG_STATUS) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
active = activeValue,
status = statusValue,
config = configValue,
)
}
if ((mask0 and MASK_OPTS_CONFIG_DEVICECOUNT_STATUS) == MASK_OPTS_CONFIG_DEVICECOUNT_STATUS) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
deviceCount = deviceCountValue,
status = statusValue,
config = configValue,
)
}
if ((mask0 and MASK_OPTS_ACTIVE_DEVICECOUNT) == MASK_OPTS_ACTIVE_DEVICECOUNT) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
active = activeValue,
deviceCount = deviceCountValue,
)
}
if ((mask0 and MASK_OPTS_ACTIVE_STATUS) == MASK_OPTS_ACTIVE_STATUS) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
active = activeValue,
status = statusValue,
)
}
if ((mask0 and MASK_OPTS_DEVICECOUNT_STATUS) == MASK_OPTS_DEVICECOUNT_STATUS) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
deviceCount = deviceCountValue,
status = statusValue,
)
}
if ((mask0 and MASK_OPTS_ACTIVE_CONFIG) == MASK_OPTS_ACTIVE_CONFIG) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
active = activeValue,
config = configValue,
)
}
if ((mask0 and MASK_OPTS_CONFIG_DEVICECOUNT) == MASK_OPTS_CONFIG_DEVICECOUNT) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
deviceCount = deviceCountValue,
config = configValue,
)
}
if ((mask0 and MASK_OPTS_CONFIG_STATUS) == MASK_OPTS_CONFIG_STATUS) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
status = statusValue,
config = configValue,
)
}
if ((mask0 and MASK_OPTS_ACTIVE) == MASK_OPTS_ACTIVE) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
active = activeValue,
)
}
if ((mask0 and MASK_OPTS_DEVICECOUNT) == MASK_OPTS_DEVICECOUNT) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
deviceCount = deviceCountValue,
)
}
if ((mask0 and MASK_OPTS_STATUS) == MASK_OPTS_STATUS) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
status = statusValue,
)
}
if ((mask0 and MASK_OPTS_CONFIG) == MASK_OPTS_CONFIG) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
config = configValue,
)
}
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
)
}
private fun validateRequiredFields(mask0: Long, reader: GhostJsonFlatReader) {
if ((mask0 and MASK_REQUIRED_0) != MASK_REQUIRED_0) {
if ((mask0 and MASK_ID) == 0L) {
reader.throwError("Required field 'id' missing in JSON")
} else if ((mask0 and MASK_DEVICES) == 0L) {
reader.throwError("Required field 'devices' missing in JSON")
}
}
}
/**
* Robust deserialization for [SmartHome].
*/
override fun deserialize(reader: GhostJsonFlatReader): SmartHome {
var idValue: String? = null
var activeValue: Boolean? = null
var deviceCountValue: Int = 0
var devicesValue: List<SmartDevice>? = null
var statusValue: HomeStatus? = null
var configValue: HomeConfig? = null
var mask0 = 0L
reader.beginObject()
while (true) {
val index = reader.selectNameAndConsume(OPTIONS)
when (index) {
0 -> {
idValue = reader.nextString()
mask0 = mask0 or MASK_ID
}
1 -> {
reader.decodeResilient { if (reader.isNextNullValue()) { reader.consumeNull(); null } else reader.nextBoolean() }?.let {
activeValue = it
mask0 = mask0 or MASK_ACTIVE
}
}
2 -> {
reader.decodeResilient { reader.nextInt() }?.let {
deviceCountValue = it
mask0 = mask0 or MASK_DEVICECOUNT
}
}
3 -> {
devicesValue = reader.readList { SmartDeviceSerializer.deserialize(reader) }
mask0 = mask0 or MASK_DEVICES
}
4 -> {
reader.decodeResilient { if (reader.isNextNullValue()) { reader.consumeNull(); null } else HomeStatusSerializer.deserialize(reader) }?.let {
statusValue = it
mask0 = mask0 or MASK_STATUS
}
}
5 -> {
reader.decodeResilient { if (reader.isNextNullValue()) { reader.consumeNull(); null } else HomeConfigSerializer.deserialize(reader) }?.let {
configValue = it
mask0 = mask0 or MASK_CONFIG
}
}
-1 -> break
-2 -> {
reader.skipValue()
}
}
}
reader.endObject()
validateRequiredFields(mask0, reader)
if ((mask0 and MASK_OPTS_ACTIVE_CONFIG_DEVICECOUNT_STATUS) == MASK_OPTS_ACTIVE_CONFIG_DEVICECOUNT_STATUS) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
active = activeValue,
deviceCount = deviceCountValue,
status = statusValue,
config = configValue,
)
}
if ((mask0 and MASK_OPTS_ACTIVE_DEVICECOUNT_STATUS) == MASK_OPTS_ACTIVE_DEVICECOUNT_STATUS) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
active = activeValue,
deviceCount = deviceCountValue,
status = statusValue,
)
}
if ((mask0 and MASK_OPTS_ACTIVE_CONFIG_DEVICECOUNT) == MASK_OPTS_ACTIVE_CONFIG_DEVICECOUNT) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
active = activeValue,
deviceCount = deviceCountValue,
config = configValue,
)
}
if ((mask0 and MASK_OPTS_ACTIVE_CONFIG_STATUS) == MASK_OPTS_ACTIVE_CONFIG_STATUS) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
active = activeValue,
status = statusValue,
config = configValue,
)
}
if ((mask0 and MASK_OPTS_CONFIG_DEVICECOUNT_STATUS) == MASK_OPTS_CONFIG_DEVICECOUNT_STATUS) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
deviceCount = deviceCountValue,
status = statusValue,
config = configValue,
)
}
if ((mask0 and MASK_OPTS_ACTIVE_DEVICECOUNT) == MASK_OPTS_ACTIVE_DEVICECOUNT) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
active = activeValue,
deviceCount = deviceCountValue,
)
}
if ((mask0 and MASK_OPTS_ACTIVE_STATUS) == MASK_OPTS_ACTIVE_STATUS) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
active = activeValue,
status = statusValue,
)
}
if ((mask0 and MASK_OPTS_DEVICECOUNT_STATUS) == MASK_OPTS_DEVICECOUNT_STATUS) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
deviceCount = deviceCountValue,
status = statusValue,
)
}
if ((mask0 and MASK_OPTS_ACTIVE_CONFIG) == MASK_OPTS_ACTIVE_CONFIG) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
active = activeValue,
config = configValue,
)
}
if ((mask0 and MASK_OPTS_CONFIG_DEVICECOUNT) == MASK_OPTS_CONFIG_DEVICECOUNT) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
deviceCount = deviceCountValue,
config = configValue,
)
}
if ((mask0 and MASK_OPTS_CONFIG_STATUS) == MASK_OPTS_CONFIG_STATUS) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
status = statusValue,
config = configValue,
)
}
if ((mask0 and MASK_OPTS_ACTIVE) == MASK_OPTS_ACTIVE) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
active = activeValue,
)
}
if ((mask0 and MASK_OPTS_DEVICECOUNT) == MASK_OPTS_DEVICECOUNT) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
deviceCount = deviceCountValue,
)
}
if ((mask0 and MASK_OPTS_STATUS) == MASK_OPTS_STATUS) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
status = statusValue,
)
}
if ((mask0 and MASK_OPTS_CONFIG) == MASK_OPTS_CONFIG) {
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
config = configValue,
)
}
return SmartHome(
id = idValue!!,
devices = devicesValue!!,
)
}
override fun serialize(writer: GhostJsonWriter, `value`: SmartHome) {
writer.beginObject()
writer.writeField(H_ID, value.id)
if (value.active != null) {
writer.writeField(H_ACTIVE, value.active)
}
writer.writeField(H_DEVICECOUNT, value.deviceCount)
writer.writeNameRaw(H_DEVICES)
writer.beginArray()
val size0 = value.devices.size
for (i0 in 0 until size0) {
val item0 = value.devices[i0]
SmartDeviceSerializer.serialize(writer, item0)
}
writer.endArray()
if (value.status != null) {
writer.writeNameRaw(H_STATUS)
HomeStatusSerializer.serialize(writer, value.status)
}
if (value.config != null) {
writer.writeNameRaw(H_CONFIG)
HomeConfigSerializer.serialize(writer, value.config)
}
writer.endObject()
}
override fun serialize(writer: GhostJsonFlatWriter, `value`: SmartHome) {
writer.beginObject()
writer.writeField(H_ID, value.id)
if (value.active != null) {
writer.writeField(H_ACTIVE, value.active)
}
writer.writeField(H_DEVICECOUNT, value.deviceCount)
writer.writeNameRaw(H_DEVICES)
writer.beginArray()
val size0 = value.devices.size
for (i0 in 0 until size0) {
val item0 = value.devices[i0]
SmartDeviceSerializer.serialize(writer, item0)
}
writer.endArray()
if (value.status != null) {
writer.writeNameRaw(H_STATUS)
HomeStatusSerializer.serialize(writer, value.status)
}
if (value.config != null) {
writer.writeNameRaw(H_CONFIG)
HomeConfigSerializer.serialize(writer, value.config)
}
writer.endObject()
}
override fun warmUp() {
try {
val reader1 = GhostJsonReader("{\"id\":\"\",\"devices\":[]}".encodeToByteArray())
deserialize(reader1)
} catch (_: Exception) {
}
try {
val reader2 = GhostJsonFlatReader("{\"id\":\"\",\"devices\":[]}".encodeToByteArray())
deserialize(reader2)
} catch (_: Exception) {
}
}
}