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

Class Class, % Method, % Branch, % Line, % Instruction, %
RawJsonListModelSerializer 100% (1/1) 88.9% (8/9) 57.1% (8/14) 76.4% (42/55) 74.9% (191/255)


 @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.captureRawJson
 import com.ghost.serialization.parser.endArray
 import com.ghost.serialization.parser.endObject
 import com.ghost.serialization.parser.readList
 import com.ghost.serialization.parser.selectNameAndConsume
 import com.ghost.serialization.parser.skipValue
 import com.ghost.serialization.types.RawJson
 import com.ghost.serialization.writer.GhostJsonFlatWriter
 import com.ghost.serialization.writer.GhostJsonWriter
 import kotlin.collections.List
 import okio.ByteString
 import okio.ByteString.Companion.encodeUtf8
 
 /**
  * High-performance serializer for [RawJsonListModel].
  * Generated by GhostSerialization. Do not modify manually.
  */
 public object RawJsonListModelSerializer : GhostSerializer<RawJsonListModel> {
   override val typeName: String = "RawJsonListModel"
 
   private val OPTIONS: JsonReaderOptions = JsonReaderOptions.of(0, 31, 128, false, "items")
 
   private val H_ITEMS: ByteString = "\"items\":".encodeUtf8()
 
   private const val MASK_ITEMS: Long = 1L
 
   private const val MASK_REQUIRED_0: Long = 1L
 
   private fun validateRequiredFields(mask0: Long, reader: GhostJsonReader) {
     if ((mask0 and MASK_ITEMS) == 0L) {
       reader.throwError("Required field 'items' missing in JSON")
     }
   }
 
   /**
    * Robust deserialization for [RawJsonListModel].
    */
   override fun deserialize(reader: GhostJsonReader): RawJsonListModel {
     var itemsValue: List<RawJson>? = null
     var mask0 = 0L
     reader.beginObject()
     while (true) {
       val index = reader.selectNameAndConsume(OPTIONS)
       when (index) {
         0 -> {
           itemsValue = reader.readList { reader.captureRawJson() }
           mask0 = mask0 or MASK_ITEMS
         }
         -1 -> break
         -2 -> {
           reader.skipValue()
         }
       }
     }
     reader.endObject()
     validateRequiredFields(mask0, reader)
     return RawJsonListModel(
       items = itemsValue!!,
     )
   }
 
   private fun validateRequiredFields(mask0: Long, reader: GhostJsonFlatReader) {
     if ((mask0 and MASK_ITEMS) == 0L) {
       reader.throwError("Required field 'items' missing in JSON")
     }
   }
 
   /**
    * Robust deserialization for [RawJsonListModel].
    */
   override fun deserialize(reader: GhostJsonFlatReader): RawJsonListModel {
     var itemsValue: List<RawJson>? = null
     var mask0 = 0L
     reader.beginObject()
     while (true) {
       val index = reader.selectNameAndConsume(OPTIONS)
       when (index) {
         0 -> {
           itemsValue = reader.readList { reader.captureRawJson() }
           mask0 = mask0 or MASK_ITEMS
         }
         -1 -> break
         -2 -> {
           reader.skipValue()
         }
       }
     }
     reader.endObject()
     validateRequiredFields(mask0, reader)
     return RawJsonListModel(
       items = itemsValue!!,
     )
   }
 
   override fun serialize(writer: GhostJsonWriter, `value`: RawJsonListModel) {
     writer.beginObject()
     writer.writeNameRaw(H_ITEMS)
     writer.beginArray()
     val size0 = value.items.size
     for (i0 in 0 until size0) {
       val item0 = value.items[i0]
       writer.rawValue(item0.storage, item0.storageOffset, item0.storageLength)
     }
     writer.endArray()
     writer.endObject()
   }
 
   override fun serialize(writer: GhostJsonFlatWriter, `value`: RawJsonListModel) {
     writer.beginObject()
     writer.writeNameRaw(H_ITEMS)
     writer.beginArray()
     val size0 = value.items.size
     for (i0 in 0 until size0) {
       val item0 = value.items[i0]
       writer.rawValue(item0.storage, item0.storageOffset, item0.storageLength)
     }
     writer.endArray()
     writer.endObject()
   }
 
   override fun warmUp() {
     try {
       val reader1 = GhostJsonReader("{\"items\":[]}".encodeToByteArray())
       deserialize(reader1)
     } catch (_: Exception) {
     }
     try {
       val reader2 = GhostJsonFlatReader("{\"items\":[]}".encodeToByteArray())
       deserialize(reader2)
     } catch (_: Exception) {
     }
   }
 }