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

Class Class, % Method, % Branch, % Line, % Instruction, %
NestedGenericModelSerializer 100% (1/1) 88.9% (8/9) 54.5% (12/22) 70.4% (50/71) 70.5% (284/403)


 @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.nextInt
 import com.ghost.serialization.parser.nextKey
 import com.ghost.serialization.parser.readList
 import com.ghost.serialization.parser.readMap
 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 kotlin.collections.Map
 import okio.ByteString
 import okio.ByteString.Companion.encodeUtf8
 
 /**
  * High-performance serializer for [NestedGenericModel].
  * Generated by GhostSerialization. Do not modify manually.
  */
 public object NestedGenericModelSerializer : GhostSerializer<NestedGenericModel> {
   override val typeName: String = "NestedGenericModel"
 
   private val OPTIONS: JsonReaderOptions = JsonReaderOptions.of(0, 31, 128, false, "data")
 
   private val H_DATA: ByteString = "\"data\":".encodeUtf8()
 
   private const val MASK_DATA: Long = 1L
 
   private const val MASK_REQUIRED_0: Long = 1L
 
   private fun validateRequiredFields(mask0: Long, reader: GhostJsonReader) {
     if ((mask0 and MASK_DATA) == 0L) {
       reader.throwError("Required field 'data' missing in JSON")
     }
   }
 
   /**
    * Robust deserialization for [NestedGenericModel].
    */
   override fun deserialize(reader: GhostJsonReader): NestedGenericModel {
     var dataValue: Map<String, List<Map<String, Int>>>? = null
     var mask0 = 0L
     reader.beginObject()
     while (true) {
       val index = reader.selectNameAndConsume(OPTIONS)
       when (index) {
         0 -> {
           dataValue = reader.readMap({ reader.nextKey()!! }) { reader.readList { reader.readMap({ reader.nextKey()!! }) { reader.nextInt() } } }
           mask0 = mask0 or MASK_DATA
         }
         -1 -> break
         -2 -> {
           reader.skipValue()
         }
       }
     }
     reader.endObject()
     validateRequiredFields(mask0, reader)
     return NestedGenericModel(
       `data` = dataValue!!,
     )
   }
 
   private fun validateRequiredFields(mask0: Long, reader: GhostJsonFlatReader) {
     if ((mask0 and MASK_DATA) == 0L) {
       reader.throwError("Required field 'data' missing in JSON")
     }
   }
 
   /**
    * Robust deserialization for [NestedGenericModel].
    */
   override fun deserialize(reader: GhostJsonFlatReader): NestedGenericModel {
     var dataValue: Map<String, List<Map<String, Int>>>? = null
     var mask0 = 0L
     reader.beginObject()
     while (true) {
       val index = reader.selectNameAndConsume(OPTIONS)
       when (index) {
         0 -> {
           dataValue = reader.readMap({ reader.nextKey()!! }) { reader.readList { reader.readMap({ reader.nextKey()!! }) { reader.nextInt() } } }
           mask0 = mask0 or MASK_DATA
         }
         -1 -> break
         -2 -> {
           reader.skipValue()
         }
       }
     }
     reader.endObject()
     validateRequiredFields(mask0, reader)
     return NestedGenericModel(
       `data` = dataValue!!,
     )
   }
 
   override fun serialize(writer: GhostJsonWriter, `value`: NestedGenericModel) {
     writer.beginObject()
     writer.writeNameRaw(H_DATA)
     writer.beginObject()
     for ((mapKey0, mapVal0) in value.`data`) {
       writer.name(mapKey0)
       writer.beginArray()
       val size1 = mapVal0.size
       for (i1 in 0 until size1) {
         val item1 = mapVal0[i1]
         writer.beginObject()
         for ((mapKey2, mapVal2) in item1) {
           writer.name(mapKey2)
           writer.value(mapVal2)
         }
         writer.endObject()
       }
       writer.endArray()
     }
     writer.endObject()
     writer.endObject()
   }
 
   override fun serialize(writer: GhostJsonFlatWriter, `value`: NestedGenericModel) {
     writer.beginObject()
     writer.writeNameRaw(H_DATA)
     writer.beginObject()
     for ((mapKey0, mapVal0) in value.`data`) {
       writer.name(mapKey0)
       writer.beginArray()
       val size1 = mapVal0.size
       for (i1 in 0 until size1) {
         val item1 = mapVal0[i1]
         writer.beginObject()
         for ((mapKey2, mapVal2) in item1) {
           writer.name(mapKey2)
           writer.value(mapVal2)
         }
         writer.endObject()
       }
       writer.endArray()
     }
     writer.endObject()
     writer.endObject()
   }
 
   override fun warmUp() {
     try {
       val reader1 = GhostJsonReader("{\"data\":{}}".encodeToByteArray())
       deserialize(reader1)
     } catch (_: Exception) {
     }
     try {
       val reader2 = GhostJsonFlatReader("{\"data\":{}}".encodeToByteArray())
       deserialize(reader2)
     } catch (_: Exception) {
     }
   }
 }