Coverage Summary for Class: AddressSerializer (com.ghost.serialization.integration.model)
| Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| AddressSerializer |
100%
(1/1)
|
88.9%
(8/9)
|
43.8%
(14/32)
|
71.9%
(69/96)
|
66.8%
(288/431)
|
@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 [Address].
* Generated by GhostSerialization. Do not modify manually.
*/
public object AddressSerializer : GhostSerializer<Address> {
override val typeName: String = "Address"
private val OPTIONS: JsonReaderOptions =
JsonReaderOptions.of(0, 31, 128, false, "street", "city", "zipCode", "country")
private val H_CITY: ByteString = "\"city\":".encodeUtf8()
private val H_COUNTRY: ByteString = "\"country\":".encodeUtf8()
private val H_STREET: ByteString = "\"street\":".encodeUtf8()
private val H_ZIPCODE: ByteString = "\"zipCode\":".encodeUtf8()
private const val MASK_STREET: Long = 1L
private const val MASK_CITY: Long = 2L
private const val MASK_ZIPCODE: Long = 4L
private const val MASK_COUNTRY: Long = 8L
private const val MASK_REQUIRED_0: Long = 7L
private const val MASK_OPTS_COUNTRY: Long = 8L
private fun validateRequiredFields(mask0: Long, reader: GhostJsonReader) {
if ((mask0 and MASK_REQUIRED_0) != MASK_REQUIRED_0) {
if ((mask0 and MASK_STREET) == 0L) {
reader.throwError("Required field 'street' missing in JSON")
} else if ((mask0 and MASK_CITY) == 0L) {
reader.throwError("Required field 'city' missing in JSON")
} else if ((mask0 and MASK_ZIPCODE) == 0L) {
reader.throwError("Required field 'zipCode' missing in JSON")
}
}
}
/**
* Robust deserialization for [Address].
*/
override fun deserialize(reader: GhostJsonReader): Address {
var streetValue: String? = null
var cityValue: String? = null
var zipCodeValue: String? = null
var countryValue: String? = null
var mask0 = 0L
reader.beginObject()
while (true) {
val index = reader.selectNameAndConsume(OPTIONS)
when (index) {
0 -> {
streetValue = reader.nextString()
mask0 = mask0 or MASK_STREET
}
1 -> {
cityValue = reader.nextString()
mask0 = mask0 or MASK_CITY
}
2 -> {
zipCodeValue = reader.nextString()
mask0 = mask0 or MASK_ZIPCODE
}
3 -> {
countryValue = reader.nextString()
mask0 = mask0 or MASK_COUNTRY
}
-1 -> break
-2 -> {
reader.skipValue()
}
}
}
reader.endObject()
validateRequiredFields(mask0, reader)
if ((mask0 and MASK_OPTS_COUNTRY) == MASK_OPTS_COUNTRY) {
return Address(
street = streetValue!!,
city = cityValue!!,
zipCode = zipCodeValue!!,
country = countryValue!!,
)
}
return Address(
street = streetValue!!,
city = cityValue!!,
zipCode = zipCodeValue!!,
)
}
private fun validateRequiredFields(mask0: Long, reader: GhostJsonFlatReader) {
if ((mask0 and MASK_REQUIRED_0) != MASK_REQUIRED_0) {
if ((mask0 and MASK_STREET) == 0L) {
reader.throwError("Required field 'street' missing in JSON")
} else if ((mask0 and MASK_CITY) == 0L) {
reader.throwError("Required field 'city' missing in JSON")
} else if ((mask0 and MASK_ZIPCODE) == 0L) {
reader.throwError("Required field 'zipCode' missing in JSON")
}
}
}
/**
* Robust deserialization for [Address].
*/
override fun deserialize(reader: GhostJsonFlatReader): Address {
var streetValue: String? = null
var cityValue: String? = null
var zipCodeValue: String? = null
var countryValue: String? = null
var mask0 = 0L
reader.beginObject()
while (true) {
val index = reader.selectNameAndConsume(OPTIONS)
when (index) {
0 -> {
streetValue = reader.nextString()
mask0 = mask0 or MASK_STREET
}
1 -> {
cityValue = reader.nextString()
mask0 = mask0 or MASK_CITY
}
2 -> {
zipCodeValue = reader.nextString()
mask0 = mask0 or MASK_ZIPCODE
}
3 -> {
countryValue = reader.nextString()
mask0 = mask0 or MASK_COUNTRY
}
-1 -> break
-2 -> {
reader.skipValue()
}
}
}
reader.endObject()
validateRequiredFields(mask0, reader)
if ((mask0 and MASK_OPTS_COUNTRY) == MASK_OPTS_COUNTRY) {
return Address(
street = streetValue!!,
city = cityValue!!,
zipCode = zipCodeValue!!,
country = countryValue!!,
)
}
return Address(
street = streetValue!!,
city = cityValue!!,
zipCode = zipCodeValue!!,
)
}
override fun serialize(writer: GhostJsonWriter, `value`: Address) {
writer.beginObject()
writer.writeField(H_STREET, value.street)
writer.writeField(H_CITY, value.city)
writer.writeField(H_ZIPCODE, value.zipCode)
writer.writeField(H_COUNTRY, value.country)
writer.endObject()
}
override fun serialize(writer: GhostJsonFlatWriter, `value`: Address) {
writer.beginObject()
writer.writeField(H_STREET, value.street)
writer.writeField(H_CITY, value.city)
writer.writeField(H_ZIPCODE, value.zipCode)
writer.writeField(H_COUNTRY, value.country)
writer.endObject()
}
override fun warmUp() {
try {
val reader1 = GhostJsonReader("{\"street\":\"\",\"city\":\"\",\"zipCode\":\"\"}".encodeToByteArray())
deserialize(reader1)
} catch (_: Exception) {
}
try {
val reader2 = GhostJsonFlatReader("{\"street\":\"\",\"city\":\"\",\"zipCode\":\"\"}".encodeToByteArray())
deserialize(reader2)
} catch (_: Exception) {
}
}
}