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

Class Class, % Method, % Branch, % Line, % Instruction, %
GhostAdvancedProfileSerializer 100% (1/1) 77.8% (7/9) 29.2% (7/24) 59.5% (44/74) 56% (192/343)


 @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.nextString
 import com.ghost.serialization.parser.readList
 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 okio.ByteString
 import okio.ByteString.Companion.encodeUtf8
 
 /**
  * High-performance serializer for [GhostAdvancedProfile].
  * Generated by GhostSerialization. Do not modify manually.
  */
 public object GhostAdvancedProfileSerializer : GhostSerializer<GhostAdvancedProfile> {
   override val typeName: String = "GhostAdvancedProfile"
 
   private val OPTIONS: JsonReaderOptions =
       JsonReaderOptions.of(0, 31, 128, false, "token", "shapes")
 
   private val H_SHAPES: ByteString = "\"shapes\":".encodeUtf8()
 
   private val H_TOKEN: ByteString = "\"token\":".encodeUtf8()
 
   private const val MASK_TOKEN: Long = 1L
 
   private const val MASK_SHAPES: 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_TOKEN) == 0L) {
         reader.throwError("Required field 'token' missing in JSON")
       } else if ((mask0 and MASK_SHAPES) == 0L) {
         reader.throwError("Required field 'shapes' missing in JSON")
       }
     }
   }
 
   /**
    * Robust deserialization for [GhostAdvancedProfile].
    */
   override fun deserialize(reader: GhostJsonReader): GhostAdvancedProfile {
     var tokenValue: String? = null
     var shapesValue: List<GhostShape>? = null
     var mask0 = 0L
     reader.beginObject()
     while (true) {
       val index = reader.selectNameAndConsume(OPTIONS)
       when (index) {
         0 -> {
           tokenValue = reader.nextString()
           mask0 = mask0 or MASK_TOKEN
         }
         1 -> {
           shapesValue = reader.readList { GhostShapeSerializer.deserialize(reader) }
           mask0 = mask0 or MASK_SHAPES
         }
         -1 -> break
         -2 -> {
           reader.skipValue()
         }
       }
     }
     reader.endObject()
     validateRequiredFields(mask0, reader)
     return GhostAdvancedProfile(
       token = com.ghost.serialization.integration.model.GhostUserToken(tokenValue!!),
       shapes = shapesValue!!,
     )
   }
 
   private fun validateRequiredFields(mask0: Long, reader: GhostJsonFlatReader) {
     if ((mask0 and MASK_REQUIRED_0) != MASK_REQUIRED_0) {
       if ((mask0 and MASK_TOKEN) == 0L) {
         reader.throwError("Required field 'token' missing in JSON")
       } else if ((mask0 and MASK_SHAPES) == 0L) {
         reader.throwError("Required field 'shapes' missing in JSON")
       }
     }
   }
 
   /**
    * Robust deserialization for [GhostAdvancedProfile].
    */
   override fun deserialize(reader: GhostJsonFlatReader): GhostAdvancedProfile {
     var tokenValue: String? = null
     var shapesValue: List<GhostShape>? = null
     var mask0 = 0L
     reader.beginObject()
     while (true) {
       val index = reader.selectNameAndConsume(OPTIONS)
       when (index) {
         0 -> {
           tokenValue = reader.nextString()
           mask0 = mask0 or MASK_TOKEN
         }
         1 -> {
           shapesValue = reader.readList { GhostShapeSerializer.deserialize(reader) }
           mask0 = mask0 or MASK_SHAPES
         }
         -1 -> break
         -2 -> {
           reader.skipValue()
         }
       }
     }
     reader.endObject()
     validateRequiredFields(mask0, reader)
     return GhostAdvancedProfile(
       token = com.ghost.serialization.integration.model.GhostUserToken(tokenValue!!),
       shapes = shapesValue!!,
     )
   }
 
   override fun serialize(writer: GhostJsonWriter, `value`: GhostAdvancedProfile) {
     writer.beginObject()
     writer.writeNameRaw(H_TOKEN)
     writer.value(value.token.`value`)
     writer.writeNameRaw(H_SHAPES)
     writer.beginArray()
     val size0 = value.shapes.size
     for (i0 in 0 until size0) {
       val item0 = value.shapes[i0]
       GhostShapeSerializer.serialize(writer, item0)
     }
     writer.endArray()
     writer.endObject()
   }
 
   override fun serialize(writer: GhostJsonFlatWriter, `value`: GhostAdvancedProfile) {
     writer.beginObject()
     writer.writeNameRaw(H_TOKEN)
     writer.value(value.token.`value`)
     writer.writeNameRaw(H_SHAPES)
     writer.beginArray()
     val size0 = value.shapes.size
     for (i0 in 0 until size0) {
       val item0 = value.shapes[i0]
       GhostShapeSerializer.serialize(writer, item0)
     }
     writer.endArray()
     writer.endObject()
   }
 
   override fun warmUp() {
     try {
       val reader1 = GhostJsonReader("{\"token\":{},\"shapes\":[]}".encodeToByteArray())
       deserialize(reader1)
     } catch (_: Exception) {
     }
     try {
       val reader2 = GhostJsonFlatReader("{\"token\":{},\"shapes\":[]}".encodeToByteArray())
       deserialize(reader2)
     } catch (_: Exception) {
     }
   }
 }