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

Class Class, % Method, % Branch, % Line, % Instruction, %
TweetMetadataSerializer 100% (1/1) 83.3% (10/12) 60% (18/30) 81.1% (73/90) 77.7% (304/391)


 @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.GhostJsonStringReader
 import com.ghost.serialization.parser.JsonReaderOptions
 import com.ghost.serialization.parser.beginObject
 import com.ghost.serialization.parser.endObject
 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.GhostJsonStringWriter
 import com.ghost.serialization.writer.GhostJsonWriter
 import okio.ByteString
 import okio.ByteString.Companion.encodeUtf8
 
 /**
  * High-performance serializer for [TweetMetadata].
  * Generated by GhostSerialization. Do not modify manually.
  */
 public object TweetMetadataSerializer : GhostSerializer<TweetMetadata> {
   override val typeName: String = "TweetMetadata"
 
   private val OPTIONS: JsonReaderOptions =
       JsonReaderOptions.of(0, 31, 128, true, "result_type", "iso_language_code")
 
   private val H_ISO_LANGUAGE_CODE: ByteString = "\"iso_language_code\":".encodeUtf8()
 
   private val HS_ISO_LANGUAGE_CODE: String = "\"iso_language_code\":"
 
   private val H_RESULT_TYPE: ByteString = "\"result_type\":".encodeUtf8()
 
   private val HS_RESULT_TYPE: String = "\"result_type\":"
 
   private const val MASK_RESULTTYPE: Long = 1L
 
   private const val MASK_ISOLANGUAGECODE: 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_RESULTTYPE) == 0L) {
         reader.throwError("Required field 'result_type' missing in JSON")
       } else if ((mask0 and MASK_ISOLANGUAGECODE) == 0L) {
         reader.throwError("Required field 'iso_language_code' missing in JSON")
       }
     }
   }
 
   /**
    * Robust deserialization for [TweetMetadata].
    */
   override fun deserialize(reader: GhostJsonReader): TweetMetadata {
     var resultTypeValue: String? = null
     var isoLanguageCodeValue: String? = null
     var mask0 = 0L
     reader.beginObject()
     while (true) {
       val index = reader.selectNameAndConsume(OPTIONS)
       when (index) {
         0 -> {
           resultTypeValue = reader.nextString()
           mask0 = mask0 or MASK_RESULTTYPE
         }
         1 -> {
           isoLanguageCodeValue = reader.nextString()
           mask0 = mask0 or MASK_ISOLANGUAGECODE
         }
         -1 -> break
         -2 -> {
           reader.skipValue()
         }
       }
     }
     reader.endObject()
     validateRequiredFields(mask0, reader)
     return TweetMetadata(
       resultType = resultTypeValue!!,
       isoLanguageCode = isoLanguageCodeValue!!,
     )
   }
 
   private fun validateRequiredFields(mask0: Long, reader: GhostJsonFlatReader) {
     if ((mask0 and MASK_REQUIRED_0) != MASK_REQUIRED_0) {
       if ((mask0 and MASK_RESULTTYPE) == 0L) {
         reader.throwError("Required field 'result_type' missing in JSON")
       } else if ((mask0 and MASK_ISOLANGUAGECODE) == 0L) {
         reader.throwError("Required field 'iso_language_code' missing in JSON")
       }
     }
   }
 
   /**
    * Robust deserialization for [TweetMetadata].
    */
   override fun deserialize(reader: GhostJsonFlatReader): TweetMetadata {
     var resultTypeValue: String? = null
     var isoLanguageCodeValue: String? = null
     var mask0 = 0L
     reader.beginObject()
     while (true) {
       val index = reader.selectNameAndConsume(OPTIONS)
       when (index) {
         0 -> {
           resultTypeValue = reader.nextString()
           mask0 = mask0 or MASK_RESULTTYPE
         }
         1 -> {
           isoLanguageCodeValue = reader.nextString()
           mask0 = mask0 or MASK_ISOLANGUAGECODE
         }
         -1 -> break
         -2 -> {
           reader.skipValue()
         }
       }
     }
     reader.endObject()
     validateRequiredFields(mask0, reader)
     return TweetMetadata(
       resultType = resultTypeValue!!,
       isoLanguageCode = isoLanguageCodeValue!!,
     )
   }
 
   private fun validateRequiredFields(mask0: Long, reader: GhostJsonStringReader) {
     if ((mask0 and MASK_REQUIRED_0) != MASK_REQUIRED_0) {
       if ((mask0 and MASK_RESULTTYPE) == 0L) {
         reader.throwError("Required field 'result_type' missing in JSON")
       } else if ((mask0 and MASK_ISOLANGUAGECODE) == 0L) {
         reader.throwError("Required field 'iso_language_code' missing in JSON")
       }
     }
   }
 
   /**
    * Robust deserialization for [TweetMetadata].
    */
   override fun deserialize(reader: GhostJsonStringReader): TweetMetadata {
     var resultTypeValue: String? = null
     var isoLanguageCodeValue: String? = null
     var mask0 = 0L
     reader.beginObject()
     while (true) {
       val index = reader.selectNameAndConsume(OPTIONS)
       when (index) {
         0 -> {
           resultTypeValue = reader.nextString()
           mask0 = mask0 or MASK_RESULTTYPE
         }
         1 -> {
           isoLanguageCodeValue = reader.nextString()
           mask0 = mask0 or MASK_ISOLANGUAGECODE
         }
         -1 -> break
         -2 -> {
           reader.skipValue()
         }
       }
     }
     reader.endObject()
     validateRequiredFields(mask0, reader)
     return TweetMetadata(
       resultType = resultTypeValue!!,
       isoLanguageCode = isoLanguageCodeValue!!,
     )
   }
 
   override fun serialize(writer: GhostJsonWriter, `value`: TweetMetadata) {
     writer.beginObject()
     writer.writeField(H_RESULT_TYPE, value.resultType)
     writer.writeField(H_ISO_LANGUAGE_CODE, value.isoLanguageCode)
     writer.endObject()
   }
 
   override fun serialize(writer: GhostJsonFlatWriter, `value`: TweetMetadata) {
     writer.beginObject()
     writer.writeField(H_RESULT_TYPE, value.resultType)
     writer.writeField(H_ISO_LANGUAGE_CODE, value.isoLanguageCode)
     writer.endObject()
   }
 
   override fun serialize(writer: GhostJsonStringWriter, `value`: TweetMetadata) {
     writer.beginObject()
     writer.writeField(HS_RESULT_TYPE, value.resultType)
     writer.writeField(HS_ISO_LANGUAGE_CODE, value.isoLanguageCode)
     writer.endObject()
   }
 
   override fun warmUp() {
     try {
       val reader1 = GhostJsonReader("{\"result_type\":\"\",\"iso_language_code\":\"\"}".encodeToByteArray())
       deserialize(reader1)
     } catch (_: Exception) {
     }
     try {
       val reader2 = GhostJsonFlatReader("{\"result_type\":\"\",\"iso_language_code\":\"\"}".encodeToByteArray())
       deserialize(reader2)
     } catch (_: Exception) {
     }
     try {
       val reader3 = GhostJsonStringReader("{\"result_type\":\"\",\"iso_language_code\":\"\"}")
       deserialize(reader3)
     } catch (_: Exception) {
     }
   }
 }