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

Class Class, % Method, % Branch, % Line, % Instruction, %
ExtendedScalarsModelSerializer 100% (1/1) 88.9% (8/9) 38.1% (16/42) 69.7% (83/119) 61.6% (338/549)


 @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.endArray
 import com.ghost.serialization.parser.endObject
 import com.ghost.serialization.parser.nextChar
 import com.ghost.serialization.parser.nextFloat
 import com.ghost.serialization.parser.nextInt
 import com.ghost.serialization.parser.nextString
 import com.ghost.serialization.parser.readSet
 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.Set
 import okio.ByteString
 import okio.ByteString.Companion.encodeUtf8
 
 /**
  * High-performance serializer for [ExtendedScalarsModel].
  * Generated by GhostSerialization. Do not modify manually.
  */
 public object ExtendedScalarsModelSerializer : GhostSerializer<ExtendedScalarsModel> {
   override val typeName: String = "ExtendedScalarsModel"
 
   private val OPTIONS: JsonReaderOptions =
       JsonReaderOptions.of(0, 31, 128, false, "tags", "code", "port", "letter", "ratio")
 
   private val H_CODE: ByteString = "\"code\":".encodeUtf8()
 
   private val H_LETTER: ByteString = "\"letter\":".encodeUtf8()
 
   private val H_PORT: ByteString = "\"port\":".encodeUtf8()
 
   private val H_RATIO: ByteString = "\"ratio\":".encodeUtf8()
 
   private val H_TAGS: ByteString = "\"tags\":".encodeUtf8()
 
   private const val MASK_TAGS: Long = 1L
 
   private const val MASK_CODE: Long = 2L
 
   private const val MASK_PORT: Long = 4L
 
   private const val MASK_LETTER: Long = 8L
 
   private const val MASK_RATIO: Long = 16L
 
   private const val MASK_REQUIRED_0: Long = 31L
 
   private fun validateRequiredFields(mask0: Long, reader: GhostJsonReader) {
     if ((mask0 and MASK_REQUIRED_0) != MASK_REQUIRED_0) {
       if ((mask0 and MASK_TAGS) == 0L) {
         reader.throwError("Required field 'tags' missing in JSON")
       } else if ((mask0 and MASK_CODE) == 0L) {
         reader.throwError("Required field 'code' missing in JSON")
       } else if ((mask0 and MASK_PORT) == 0L) {
         reader.throwError("Required field 'port' missing in JSON")
       } else if ((mask0 and MASK_LETTER) == 0L) {
         reader.throwError("Required field 'letter' missing in JSON")
       } else if ((mask0 and MASK_RATIO) == 0L) {
         reader.throwError("Required field 'ratio' missing in JSON")
       }
     }
   }
 
   /**
    * Robust deserialization for [ExtendedScalarsModel].
    */
   override fun deserialize(reader: GhostJsonReader): ExtendedScalarsModel {
     var tagsValue: Set<String>? = null
     var codeValue: Byte = 0
     var portValue: Short = 0
     var letterValue: Char = '\u0000'
     var ratioValue: Float = 0.0f
     var mask0 = 0L
     reader.beginObject()
     while (true) {
       val index = reader.selectNameAndConsume(OPTIONS)
       when (index) {
         0 -> {
           tagsValue = reader.readSet { reader.nextString() }
           mask0 = mask0 or MASK_TAGS
         }
         1 -> {
           codeValue = reader.nextInt().toByte()
           mask0 = mask0 or MASK_CODE
         }
         2 -> {
           portValue = reader.nextInt().toShort()
           mask0 = mask0 or MASK_PORT
         }
         3 -> {
           letterValue = reader.nextChar()
           mask0 = mask0 or MASK_LETTER
         }
         4 -> {
           ratioValue = reader.nextFloat()
           mask0 = mask0 or MASK_RATIO
         }
         -1 -> break
         -2 -> {
           reader.skipValue()
         }
       }
     }
     reader.endObject()
     validateRequiredFields(mask0, reader)
     return ExtendedScalarsModel(
       tags = tagsValue!!,
       code = codeValue,
       port = portValue,
       letter = letterValue,
       ratio = ratioValue,
     )
   }
 
   private fun validateRequiredFields(mask0: Long, reader: GhostJsonFlatReader) {
     if ((mask0 and MASK_REQUIRED_0) != MASK_REQUIRED_0) {
       if ((mask0 and MASK_TAGS) == 0L) {
         reader.throwError("Required field 'tags' missing in JSON")
       } else if ((mask0 and MASK_CODE) == 0L) {
         reader.throwError("Required field 'code' missing in JSON")
       } else if ((mask0 and MASK_PORT) == 0L) {
         reader.throwError("Required field 'port' missing in JSON")
       } else if ((mask0 and MASK_LETTER) == 0L) {
         reader.throwError("Required field 'letter' missing in JSON")
       } else if ((mask0 and MASK_RATIO) == 0L) {
         reader.throwError("Required field 'ratio' missing in JSON")
       }
     }
   }
 
   /**
    * Robust deserialization for [ExtendedScalarsModel].
    */
   override fun deserialize(reader: GhostJsonFlatReader): ExtendedScalarsModel {
     var tagsValue: Set<String>? = null
     var codeValue: Byte = 0
     var portValue: Short = 0
     var letterValue: Char = '\u0000'
     var ratioValue: Float = 0.0f
     var mask0 = 0L
     reader.beginObject()
     while (true) {
       val index = reader.selectNameAndConsume(OPTIONS)
       when (index) {
         0 -> {
           tagsValue = reader.readSet { reader.nextString() }
           mask0 = mask0 or MASK_TAGS
         }
         1 -> {
           codeValue = reader.nextInt().toByte()
           mask0 = mask0 or MASK_CODE
         }
         2 -> {
           portValue = reader.nextInt().toShort()
           mask0 = mask0 or MASK_PORT
         }
         3 -> {
           letterValue = reader.nextChar()
           mask0 = mask0 or MASK_LETTER
         }
         4 -> {
           ratioValue = reader.nextFloat()
           mask0 = mask0 or MASK_RATIO
         }
         -1 -> break
         -2 -> {
           reader.skipValue()
         }
       }
     }
     reader.endObject()
     validateRequiredFields(mask0, reader)
     return ExtendedScalarsModel(
       tags = tagsValue!!,
       code = codeValue,
       port = portValue,
       letter = letterValue,
       ratio = ratioValue,
     )
   }
 
   override fun serialize(writer: GhostJsonWriter, `value`: ExtendedScalarsModel) {
     writer.beginObject()
     writer.writeNameRaw(H_TAGS)
     writer.beginArray()
     for (item0 in value.tags) {
       writer.value(item0)
     }
     writer.endArray()
     writer.writeNameRaw(H_CODE)
     writer.value(value.code.toInt())
     writer.writeNameRaw(H_PORT)
     writer.value(value.port.toInt())
     writer.writeNameRaw(H_LETTER)
     writer.value(value.letter)
     writer.writeField(H_RATIO, value.ratio)
     writer.endObject()
   }
 
   override fun serialize(writer: GhostJsonFlatWriter, `value`: ExtendedScalarsModel) {
     writer.beginObject()
     writer.writeNameRaw(H_TAGS)
     writer.beginArray()
     for (item0 in value.tags) {
       writer.value(item0)
     }
     writer.endArray()
     writer.writeNameRaw(H_CODE)
     writer.value(value.code.toInt())
     writer.writeNameRaw(H_PORT)
     writer.value(value.port.toInt())
     writer.writeNameRaw(H_LETTER)
     writer.value(value.letter)
     writer.writeField(H_RATIO, value.ratio)
     writer.endObject()
   }
 
   override fun warmUp() {
     try {
       val reader1 = GhostJsonReader("{\"tags\":[],\"code\":0,\"port\":0,\"letter\":\"\\u0000\",\"ratio\":0.0}".encodeToByteArray())
       deserialize(reader1)
     } catch (_: Exception) {
     }
     try {
       val reader2 = GhostJsonFlatReader("{\"tags\":[],\"code\":0,\"port\":0,\"letter\":\"\\u0000\",\"ratio\":0.0}".encodeToByteArray())
       deserialize(reader2)
     } catch (_: Exception) {
     }
   }
 }