Coverage Summary for Class: ApiProductConfigSerializer (com.ghost.serialization.integration.model)

Class Class, % Method, % Branch, % Line, % Instruction, %
ApiProductConfigSerializer 100% (1/1) 88.9% (8/9) 52.8% (19/36) 70% (77/110) 69.2% (312/451)


 @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.nextBoolean
 import com.ghost.serialization.parser.nextInt
 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 [ApiProductConfig].
  * Generated by GhostSerialization. Do not modify manually.
  */
 public object ApiProductConfigSerializer : GhostSerializer<ApiProductConfig> {
   override val typeName: String = "ApiProductConfig"
 
   private val OPTIONS: JsonReaderOptions =
       JsonReaderOptions.of(0, 31, 128, false, "id", "name", "maxRetries", "isEnabled")
 
   private val H_ID: ByteString = "\"id\":".encodeUtf8()
 
   private val H_ISENABLED: ByteString = "\"isEnabled\":".encodeUtf8()
 
   private val H_MAXRETRIES: ByteString = "\"maxRetries\":".encodeUtf8()
 
   private val H_NAME: ByteString = "\"name\":".encodeUtf8()
 
   private const val MASK_ID: Long = 1L
 
   private const val MASK_NAME: Long = 2L
 
   private const val MASK_MAXRETRIES: Long = 4L
 
   private const val MASK_ISENABLED: Long = 8L
 
   private const val MASK_REQUIRED_0: Long = 3L
 
   private const val MASK_OPTS_ISENABLED_MAXRETRIES: Long = 12L
 
   private const val MASK_OPTS_MAXRETRIES: Long = 4L
 
   private const val MASK_OPTS_ISENABLED: Long = 8L
 
   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_NAME) == 0L) {
         reader.throwError("Required field 'name' missing in JSON")
       }
     }
   }
 
   /**
    * Robust deserialization for [ApiProductConfig].
    */
   override fun deserialize(reader: GhostJsonReader): ApiProductConfig {
     var idValue: Int = 0
     var nameValue: String? = null
     var maxRetriesValue: Int = 0
     var isEnabledValue: Boolean = false
     var mask0 = 0L
     reader.beginObject()
     while (true) {
       val index = reader.selectNameAndConsume(OPTIONS)
       when (index) {
         0 -> {
           idValue = reader.nextInt()
           mask0 = mask0 or MASK_ID
         }
         1 -> {
           nameValue = reader.nextString()
           mask0 = mask0 or MASK_NAME
         }
         2 -> {
           maxRetriesValue = reader.nextInt()
           mask0 = mask0 or MASK_MAXRETRIES
         }
         3 -> {
           isEnabledValue = reader.nextBoolean()
           mask0 = mask0 or MASK_ISENABLED
         }
         -1 -> break
         -2 -> {
           reader.skipValue()
         }
       }
     }
     reader.endObject()
     validateRequiredFields(mask0, reader)
     if ((mask0 and MASK_OPTS_ISENABLED_MAXRETRIES) == MASK_OPTS_ISENABLED_MAXRETRIES) {
       return ApiProductConfig(
         id = idValue,
         name = nameValue!!,
         maxRetries = maxRetriesValue,
         isEnabled = isEnabledValue,
       )
     }
     if ((mask0 and MASK_OPTS_MAXRETRIES) == MASK_OPTS_MAXRETRIES) {
       return ApiProductConfig(
         id = idValue,
         name = nameValue!!,
         maxRetries = maxRetriesValue,
       )
     }
     if ((mask0 and MASK_OPTS_ISENABLED) == MASK_OPTS_ISENABLED) {
       return ApiProductConfig(
         id = idValue,
         name = nameValue!!,
         isEnabled = isEnabledValue,
       )
     }
     return ApiProductConfig(
       id = idValue,
       name = nameValue!!,
     )
   }
 
   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_NAME) == 0L) {
         reader.throwError("Required field 'name' missing in JSON")
       }
     }
   }
 
   /**
    * Robust deserialization for [ApiProductConfig].
    */
   override fun deserialize(reader: GhostJsonFlatReader): ApiProductConfig {
     var idValue: Int = 0
     var nameValue: String? = null
     var maxRetriesValue: Int = 0
     var isEnabledValue: Boolean = false
     var mask0 = 0L
     reader.beginObject()
     while (true) {
       val index = reader.selectNameAndConsume(OPTIONS)
       when (index) {
         0 -> {
           idValue = reader.nextInt()
           mask0 = mask0 or MASK_ID
         }
         1 -> {
           nameValue = reader.nextString()
           mask0 = mask0 or MASK_NAME
         }
         2 -> {
           maxRetriesValue = reader.nextInt()
           mask0 = mask0 or MASK_MAXRETRIES
         }
         3 -> {
           isEnabledValue = reader.nextBoolean()
           mask0 = mask0 or MASK_ISENABLED
         }
         -1 -> break
         -2 -> {
           reader.skipValue()
         }
       }
     }
     reader.endObject()
     validateRequiredFields(mask0, reader)
     if ((mask0 and MASK_OPTS_ISENABLED_MAXRETRIES) == MASK_OPTS_ISENABLED_MAXRETRIES) {
       return ApiProductConfig(
         id = idValue,
         name = nameValue!!,
         maxRetries = maxRetriesValue,
         isEnabled = isEnabledValue,
       )
     }
     if ((mask0 and MASK_OPTS_MAXRETRIES) == MASK_OPTS_MAXRETRIES) {
       return ApiProductConfig(
         id = idValue,
         name = nameValue!!,
         maxRetries = maxRetriesValue,
       )
     }
     if ((mask0 and MASK_OPTS_ISENABLED) == MASK_OPTS_ISENABLED) {
       return ApiProductConfig(
         id = idValue,
         name = nameValue!!,
         isEnabled = isEnabledValue,
       )
     }
     return ApiProductConfig(
       id = idValue,
       name = nameValue!!,
     )
   }
 
   override fun serialize(writer: GhostJsonWriter, `value`: ApiProductConfig) {
     writer.beginObject()
     writer.writeField(H_ID, value.id)
     writer.writeField(H_NAME, value.name)
     writer.writeField(H_MAXRETRIES, value.maxRetries)
     writer.writeField(H_ISENABLED, value.isEnabled)
     writer.endObject()
   }
 
   override fun serialize(writer: GhostJsonFlatWriter, `value`: ApiProductConfig) {
     writer.beginObject()
     writer.writeField(H_ID, value.id)
     writer.writeField(H_NAME, value.name)
     writer.writeField(H_MAXRETRIES, value.maxRetries)
     writer.writeField(H_ISENABLED, value.isEnabled)
     writer.endObject()
   }
 
   override fun warmUp() {
     try {
       val reader1 = GhostJsonReader("{\"id\":0,\"name\":\"\"}".encodeToByteArray())
       deserialize(reader1)
     } catch (_: Exception) {
     }
     try {
       val reader2 = GhostJsonFlatReader("{\"id\":0,\"name\":\"\"}".encodeToByteArray())
       deserialize(reader2)
     } catch (_: Exception) {
     }
   }
 }