Coverage Summary for Class: StripeObject_RefundSerializer (com.ghost.serialization.integration.model)
| Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| StripeObject_RefundSerializer |
100%
(1/1)
|
88.9%
(8/9)
|
45%
(9/20)
|
77.4%
(48/62)
|
70%
(194/277)
|
@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.nextLong
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 [StripeObject.Refund].
* Generated by GhostSerialization. Do not modify manually.
*/
public object StripeObject_RefundSerializer : GhostSerializer<StripeObject.Refund> {
override val typeName: String = "Refund"
private val OPTIONS: JsonReaderOptions =
JsonReaderOptions.of(0, 31, 128, false, "chargeId", "amount")
private val H_AMOUNT: ByteString = "\"amount\":".encodeUtf8()
private val H_CHARGEID: ByteString = "\"chargeId\":".encodeUtf8()
private const val MASK_CHARGEID: Long = 1L
private const val MASK_AMOUNT: 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_CHARGEID) == 0L) {
reader.throwError("Required field 'chargeId' missing in JSON")
} else if ((mask0 and MASK_AMOUNT) == 0L) {
reader.throwError("Required field 'amount' missing in JSON")
}
}
}
/**
* Robust deserialization for [StripeObject.Refund].
*/
override fun deserialize(reader: GhostJsonReader): StripeObject.Refund {
var chargeIdValue: String? = null
var amountValue: Long = 0L
var mask0 = 0L
reader.beginObject()
while (true) {
val index = reader.selectNameAndConsume(OPTIONS)
when (index) {
0 -> {
chargeIdValue = reader.nextString()
mask0 = mask0 or MASK_CHARGEID
}
1 -> {
amountValue = reader.nextLong()
mask0 = mask0 or MASK_AMOUNT
}
-1 -> break
-2 -> {
reader.skipValue()
}
}
}
reader.endObject()
validateRequiredFields(mask0, reader)
return StripeObject.Refund(
chargeId = chargeIdValue!!,
amount = amountValue,
)
}
private fun validateRequiredFields(mask0: Long, reader: GhostJsonFlatReader) {
if ((mask0 and MASK_REQUIRED_0) != MASK_REQUIRED_0) {
if ((mask0 and MASK_CHARGEID) == 0L) {
reader.throwError("Required field 'chargeId' missing in JSON")
} else if ((mask0 and MASK_AMOUNT) == 0L) {
reader.throwError("Required field 'amount' missing in JSON")
}
}
}
/**
* Robust deserialization for [StripeObject.Refund].
*/
override fun deserialize(reader: GhostJsonFlatReader): StripeObject.Refund {
var chargeIdValue: String? = null
var amountValue: Long = 0L
var mask0 = 0L
reader.beginObject()
while (true) {
val index = reader.selectNameAndConsume(OPTIONS)
when (index) {
0 -> {
chargeIdValue = reader.nextString()
mask0 = mask0 or MASK_CHARGEID
}
1 -> {
amountValue = reader.nextLong()
mask0 = mask0 or MASK_AMOUNT
}
-1 -> break
-2 -> {
reader.skipValue()
}
}
}
reader.endObject()
validateRequiredFields(mask0, reader)
return StripeObject.Refund(
chargeId = chargeIdValue!!,
amount = amountValue,
)
}
override fun serialize(writer: GhostJsonWriter, `value`: StripeObject.Refund) {
writer.beginObject()
writer.name("object").value("Refund")
writer.writeField(H_CHARGEID, value.chargeId)
writer.writeField(H_AMOUNT, value.amount)
writer.endObject()
}
override fun serialize(writer: GhostJsonFlatWriter, `value`: StripeObject.Refund) {
writer.beginObject()
writer.name("object").value("Refund")
writer.writeField(H_CHARGEID, value.chargeId)
writer.writeField(H_AMOUNT, value.amount)
writer.endObject()
}
override fun warmUp() {
try {
val reader1 = GhostJsonReader("{\"chargeId\":\"\",\"amount\":0}".encodeToByteArray())
deserialize(reader1)
} catch (_: Exception) {
}
try {
val reader2 = GhostJsonFlatReader("{\"chargeId\":\"\",\"amount\":0}".encodeToByteArray())
deserialize(reader2)
} catch (_: Exception) {
}
}
}