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

Class Class, % Method, % Branch, % Line, % Instruction, %
BenchUserSerializer 100% (1/1) 77.8% (7/9) 35.1% (26/74) 36.2% (83/229) 40.7% (361/887)


 @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.consumeNull
 import com.ghost.serialization.parser.endObject
 import com.ghost.serialization.parser.isNextNullValue
 import com.ghost.serialization.parser.nextBoolean
 import com.ghost.serialization.parser.nextDouble
 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 [BenchUser].
  * Generated by GhostSerialization. Do not modify manually.
  */
 public object BenchUserSerializer : GhostSerializer<BenchUser> {
   override val typeName: String = "BenchUser"
 
   private val OPTIONS: JsonReaderOptions =
       JsonReaderOptions.of(0, 31, 128, false, "id", "name", "email", "score", "isActive", "role", "bio")
 
   private val H_BIO: ByteString = "\"bio\":".encodeUtf8()
 
   private val H_EMAIL: ByteString = "\"email\":".encodeUtf8()
 
   private val H_ID: ByteString = "\"id\":".encodeUtf8()
 
   private val H_ISACTIVE: ByteString = "\"isActive\":".encodeUtf8()
 
   private val H_NAME: ByteString = "\"name\":".encodeUtf8()
 
   private val H_ROLE: ByteString = "\"role\":".encodeUtf8()
 
   private val H_SCORE: ByteString = "\"score\":".encodeUtf8()
 
   private const val MASK_ID: Long = 1L
 
   private const val MASK_NAME: Long = 2L
 
   private const val MASK_EMAIL: Long = 4L
 
   private const val MASK_SCORE: Long = 8L
 
   private const val MASK_ISACTIVE: Long = 16L
 
   private const val MASK_ROLE: Long = 32L
 
   private const val MASK_BIO: Long = 64L
 
   private const val MASK_REQUIRED_0: Long = 15L
 
   private const val MASK_OPTS_BIO_ISACTIVE_ROLE: Long = 112L
 
   private const val MASK_OPTS_ISACTIVE_ROLE: Long = 48L
 
   private const val MASK_OPTS_BIO_ISACTIVE: Long = 80L
 
   private const val MASK_OPTS_BIO_ROLE: Long = 96L
 
   private const val MASK_OPTS_ISACTIVE: Long = 16L
 
   private const val MASK_OPTS_ROLE: Long = 32L
 
   private const val MASK_OPTS_BIO: Long = 64L
 
   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")
       } else if ((mask0 and MASK_EMAIL) == 0L) {
         reader.throwError("Required field 'email' missing in JSON")
       } else if ((mask0 and MASK_SCORE) == 0L) {
         reader.throwError("Required field 'score' missing in JSON")
       }
     }
   }
 
   /**
    * Robust deserialization for [BenchUser].
    */
   override fun deserialize(reader: GhostJsonReader): BenchUser {
     var idValue: Int = 0
     var nameValue: String? = null
     var emailValue: String? = null
     var scoreValue: Double = 0.0
     var isActiveValue: Boolean = false
     var roleValue: UserRole? = null
     var bioValue: String? = null
     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 -> {
           emailValue = reader.nextString()
           mask0 = mask0 or MASK_EMAIL
         }
         3 -> {
           scoreValue = reader.nextDouble()
           mask0 = mask0 or MASK_SCORE
         }
         4 -> {
           isActiveValue = reader.nextBoolean()
           mask0 = mask0 or MASK_ISACTIVE
         }
         5 -> {
           roleValue = UserRoleSerializer.deserialize(reader)
           mask0 = mask0 or MASK_ROLE
         }
         6 -> {
           bioValue = if (reader.isNextNullValue()) { reader.consumeNull(); null } else reader.nextString()
           mask0 = mask0 or MASK_BIO
         }
         -1 -> break
         -2 -> {
           reader.skipValue()
         }
       }
     }
     reader.endObject()
     validateRequiredFields(mask0, reader)
     if ((mask0 and MASK_OPTS_BIO_ISACTIVE_ROLE) == MASK_OPTS_BIO_ISACTIVE_ROLE) {
       return BenchUser(
         id = idValue,
         name = nameValue!!,
         email = emailValue!!,
         score = scoreValue,
         isActive = isActiveValue,
         role = roleValue!!,
         bio = bioValue,
       )
     }
     if ((mask0 and MASK_OPTS_ISACTIVE_ROLE) == MASK_OPTS_ISACTIVE_ROLE) {
       return BenchUser(
         id = idValue,
         name = nameValue!!,
         email = emailValue!!,
         score = scoreValue,
         isActive = isActiveValue,
         role = roleValue!!,
       )
     }
     if ((mask0 and MASK_OPTS_BIO_ISACTIVE) == MASK_OPTS_BIO_ISACTIVE) {
       return BenchUser(
         id = idValue,
         name = nameValue!!,
         email = emailValue!!,
         score = scoreValue,
         isActive = isActiveValue,
         bio = bioValue,
       )
     }
     if ((mask0 and MASK_OPTS_BIO_ROLE) == MASK_OPTS_BIO_ROLE) {
       return BenchUser(
         id = idValue,
         name = nameValue!!,
         email = emailValue!!,
         score = scoreValue,
         role = roleValue!!,
         bio = bioValue,
       )
     }
     if ((mask0 and MASK_OPTS_ISACTIVE) == MASK_OPTS_ISACTIVE) {
       return BenchUser(
         id = idValue,
         name = nameValue!!,
         email = emailValue!!,
         score = scoreValue,
         isActive = isActiveValue,
       )
     }
     if ((mask0 and MASK_OPTS_ROLE) == MASK_OPTS_ROLE) {
       return BenchUser(
         id = idValue,
         name = nameValue!!,
         email = emailValue!!,
         score = scoreValue,
         role = roleValue!!,
       )
     }
     if ((mask0 and MASK_OPTS_BIO) == MASK_OPTS_BIO) {
       return BenchUser(
         id = idValue,
         name = nameValue!!,
         email = emailValue!!,
         score = scoreValue,
         bio = bioValue,
       )
     }
     return BenchUser(
       id = idValue,
       name = nameValue!!,
       email = emailValue!!,
       score = scoreValue,
     )
   }
 
   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")
       } else if ((mask0 and MASK_EMAIL) == 0L) {
         reader.throwError("Required field 'email' missing in JSON")
       } else if ((mask0 and MASK_SCORE) == 0L) {
         reader.throwError("Required field 'score' missing in JSON")
       }
     }
   }
 
   /**
    * Robust deserialization for [BenchUser].
    */
   override fun deserialize(reader: GhostJsonFlatReader): BenchUser {
     var idValue: Int = 0
     var nameValue: String? = null
     var emailValue: String? = null
     var scoreValue: Double = 0.0
     var isActiveValue: Boolean = false
     var roleValue: UserRole? = null
     var bioValue: String? = null
     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 -> {
           emailValue = reader.nextString()
           mask0 = mask0 or MASK_EMAIL
         }
         3 -> {
           scoreValue = reader.nextDouble()
           mask0 = mask0 or MASK_SCORE
         }
         4 -> {
           isActiveValue = reader.nextBoolean()
           mask0 = mask0 or MASK_ISACTIVE
         }
         5 -> {
           roleValue = UserRoleSerializer.deserialize(reader)
           mask0 = mask0 or MASK_ROLE
         }
         6 -> {
           bioValue = if (reader.isNextNullValue()) { reader.consumeNull(); null } else reader.nextString()
           mask0 = mask0 or MASK_BIO
         }
         -1 -> break
         -2 -> {
           reader.skipValue()
         }
       }
     }
     reader.endObject()
     validateRequiredFields(mask0, reader)
     if ((mask0 and MASK_OPTS_BIO_ISACTIVE_ROLE) == MASK_OPTS_BIO_ISACTIVE_ROLE) {
       return BenchUser(
         id = idValue,
         name = nameValue!!,
         email = emailValue!!,
         score = scoreValue,
         isActive = isActiveValue,
         role = roleValue!!,
         bio = bioValue,
       )
     }
     if ((mask0 and MASK_OPTS_ISACTIVE_ROLE) == MASK_OPTS_ISACTIVE_ROLE) {
       return BenchUser(
         id = idValue,
         name = nameValue!!,
         email = emailValue!!,
         score = scoreValue,
         isActive = isActiveValue,
         role = roleValue!!,
       )
     }
     if ((mask0 and MASK_OPTS_BIO_ISACTIVE) == MASK_OPTS_BIO_ISACTIVE) {
       return BenchUser(
         id = idValue,
         name = nameValue!!,
         email = emailValue!!,
         score = scoreValue,
         isActive = isActiveValue,
         bio = bioValue,
       )
     }
     if ((mask0 and MASK_OPTS_BIO_ROLE) == MASK_OPTS_BIO_ROLE) {
       return BenchUser(
         id = idValue,
         name = nameValue!!,
         email = emailValue!!,
         score = scoreValue,
         role = roleValue!!,
         bio = bioValue,
       )
     }
     if ((mask0 and MASK_OPTS_ISACTIVE) == MASK_OPTS_ISACTIVE) {
       return BenchUser(
         id = idValue,
         name = nameValue!!,
         email = emailValue!!,
         score = scoreValue,
         isActive = isActiveValue,
       )
     }
     if ((mask0 and MASK_OPTS_ROLE) == MASK_OPTS_ROLE) {
       return BenchUser(
         id = idValue,
         name = nameValue!!,
         email = emailValue!!,
         score = scoreValue,
         role = roleValue!!,
       )
     }
     if ((mask0 and MASK_OPTS_BIO) == MASK_OPTS_BIO) {
       return BenchUser(
         id = idValue,
         name = nameValue!!,
         email = emailValue!!,
         score = scoreValue,
         bio = bioValue,
       )
     }
     return BenchUser(
       id = idValue,
       name = nameValue!!,
       email = emailValue!!,
       score = scoreValue,
     )
   }
 
   override fun serialize(writer: GhostJsonWriter, `value`: BenchUser) {
     writer.beginObject()
     writer.writeField(H_ID, value.id)
     writer.writeField(H_NAME, value.name)
     writer.writeField(H_EMAIL, value.email)
     writer.writeField(H_SCORE, value.score)
     writer.writeField(H_ISACTIVE, value.isActive)
     writer.writeNameRaw(H_ROLE)
     UserRoleSerializer.serialize(writer, value.role)
     if (value.bio != null) {
       writer.writeField(H_BIO, value.bio)
     }
     writer.endObject()
   }
 
   override fun serialize(writer: GhostJsonFlatWriter, `value`: BenchUser) {
     writer.beginObject()
     writer.writeField(H_ID, value.id)
     writer.writeField(H_NAME, value.name)
     writer.writeField(H_EMAIL, value.email)
     writer.writeField(H_SCORE, value.score)
     writer.writeField(H_ISACTIVE, value.isActive)
     writer.writeNameRaw(H_ROLE)
     UserRoleSerializer.serialize(writer, value.role)
     if (value.bio != null) {
       writer.writeField(H_BIO, value.bio)
     }
     writer.endObject()
   }
 
   override fun warmUp() {
     try {
       val reader1 = GhostJsonReader("{\"id\":0,\"name\":\"\",\"email\":\"\",\"score\":0.0}".encodeToByteArray())
       deserialize(reader1)
     } catch (_: Exception) {
     }
     try {
       val reader2 = GhostJsonFlatReader("{\"id\":0,\"name\":\"\",\"email\":\"\",\"score\":0.0}".encodeToByteArray())
       deserialize(reader2)
     } catch (_: Exception) {
     }
   }
 }