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

Class Class, % Method, % Branch, % Line, % Instruction, %
DeviceStateWrapperSerializer 100% (1/1) 77.8% (7/9) 25% (5/20) 60.9% (39/64) 57.5% (164/285)


 @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.endObject
 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 [DeviceStateWrapper].
  * Generated by GhostSerialization. Do not modify manually.
  */
 public object DeviceStateWrapperSerializer : GhostSerializer<DeviceStateWrapper> {
   override val typeName: String = "DeviceStateWrapper"
 
   private val OPTIONS: JsonReaderOptions = JsonReaderOptions.of(0, 31, 128, false, "state", "sync")
 
   private val H_STATE: ByteString = "\"state\":".encodeUtf8()
 
   private val H_SYNC: ByteString = "\"sync\":".encodeUtf8()
 
   private const val MASK_STATE: Long = 1L
 
   private const val MASK_SYNC: 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_STATE) == 0L) {
         reader.throwError("Required field 'state' missing in JSON")
       } else if ((mask0 and MASK_SYNC) == 0L) {
         reader.throwError("Required field 'sync' missing in JSON")
       }
     }
   }
 
   /**
    * Robust deserialization for [DeviceStateWrapper].
    */
   override fun deserialize(reader: GhostJsonReader): DeviceStateWrapper {
     var stateValue: DeviceState? = null
     var syncValue: SyncStatus? = null
     var mask0 = 0L
     reader.beginObject()
     while (true) {
       val index = reader.selectNameAndConsume(OPTIONS)
       when (index) {
         0 -> {
           stateValue = DeviceStateSerializer.deserialize(reader)
           mask0 = mask0 or MASK_STATE
         }
         1 -> {
           syncValue = SyncStatusSerializer.deserialize(reader)
           mask0 = mask0 or MASK_SYNC
         }
         -1 -> break
         -2 -> {
           reader.skipValue()
         }
       }
     }
     reader.endObject()
     validateRequiredFields(mask0, reader)
     return DeviceStateWrapper(
       state = stateValue!!,
       sync = syncValue!!,
     )
   }
 
   private fun validateRequiredFields(mask0: Long, reader: GhostJsonFlatReader) {
     if ((mask0 and MASK_REQUIRED_0) != MASK_REQUIRED_0) {
       if ((mask0 and MASK_STATE) == 0L) {
         reader.throwError("Required field 'state' missing in JSON")
       } else if ((mask0 and MASK_SYNC) == 0L) {
         reader.throwError("Required field 'sync' missing in JSON")
       }
     }
   }
 
   /**
    * Robust deserialization for [DeviceStateWrapper].
    */
   override fun deserialize(reader: GhostJsonFlatReader): DeviceStateWrapper {
     var stateValue: DeviceState? = null
     var syncValue: SyncStatus? = null
     var mask0 = 0L
     reader.beginObject()
     while (true) {
       val index = reader.selectNameAndConsume(OPTIONS)
       when (index) {
         0 -> {
           stateValue = DeviceStateSerializer.deserialize(reader)
           mask0 = mask0 or MASK_STATE
         }
         1 -> {
           syncValue = SyncStatusSerializer.deserialize(reader)
           mask0 = mask0 or MASK_SYNC
         }
         -1 -> break
         -2 -> {
           reader.skipValue()
         }
       }
     }
     reader.endObject()
     validateRequiredFields(mask0, reader)
     return DeviceStateWrapper(
       state = stateValue!!,
       sync = syncValue!!,
     )
   }
 
   override fun serialize(writer: GhostJsonWriter, `value`: DeviceStateWrapper) {
     writer.beginObject()
     writer.writeNameRaw(H_STATE)
     DeviceStateSerializer.serialize(writer, value.state)
     writer.writeNameRaw(H_SYNC)
     SyncStatusSerializer.serialize(writer, value.sync)
     writer.endObject()
   }
 
   override fun serialize(writer: GhostJsonFlatWriter, `value`: DeviceStateWrapper) {
     writer.beginObject()
     writer.writeNameRaw(H_STATE)
     DeviceStateSerializer.serialize(writer, value.state)
     writer.writeNameRaw(H_SYNC)
     SyncStatusSerializer.serialize(writer, value.sync)
     writer.endObject()
   }
 
   override fun warmUp() {
     try {
       val reader1 = GhostJsonReader("{\"state\":{},\"sync\":{}}".encodeToByteArray())
       deserialize(reader1)
     } catch (_: Exception) {
     }
     try {
       val reader2 = GhostJsonFlatReader("{\"state\":{},\"sync\":{}}".encodeToByteArray())
       deserialize(reader2)
     } catch (_: Exception) {
     }
   }
 }