All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.http4k.connect.amazon.sqs.action.KotshiReceiveMessageJsonAdapter.kt Maven / Gradle / Ivy

// Code generated by Kotshi. Do not edit.
package org.http4k.connect.amazon.sqs.action

import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonDataException
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types.newParameterizedType
import java.io.IOException
import java.lang.StringBuilder
import java.lang.reflect.Constructor
import java.time.ZonedDateTime
import kotlin.Int
import kotlin.String
import kotlin.Suppress
import kotlin.apply
import kotlin.collections.List
import kotlin.collections.setOf
import kotlin.jvm.Throws
import kotlin.jvm.Volatile
import kotlin.jvm.`internal`.DefaultConstructorMarker
import org.http4k.core.Uri
import se.ansman.kotshi.InternalKotshiApi
import se.ansman.kotshi.KotshiUtils.appendNullableError
import se.ansman.kotshi.NamedJsonAdapter

@InternalKotshiApi
@Suppress(
  "DEPRECATION",
  "unused",
  "ClassName",
  "REDUNDANT_PROJECTION",
  "RedundantExplicitType",
  "LocalVariableName",
  "RedundantVisibilityModifier",
  "PLATFORM_CLASS_MAPPED_TO_KOTLIN",
  "IMPLICIT_NOTHING_TYPE_ARGUMENT_IN_RETURN_POSITION",
  "EXPERIMENTAL_API_USAGE",
  "OPT_IN_USAGE",
)
internal class KotshiReceiveMessageJsonAdapter(
  moshi: Moshi,
) : NamedJsonAdapter("KotshiJsonAdapter(ReceiveMessage)") {
  private val queueUrlAdapter: JsonAdapter = moshi.adapter(
      Uri::class.javaObjectType,
      setOf(),
      "queueUrl"
  )

  private val expiresAdapter: JsonAdapter = moshi.adapter(
      ZonedDateTime::class.javaObjectType,
      setOf(),
      "expires"
  )

  private val messageAttributesAdapter: JsonAdapter?> = moshi.adapter(
      newParameterizedType(List::class.javaObjectType, String::class.javaObjectType),
      setOf(),
      "messageAttributes"
  )

  private val attributeNamesAdapter: JsonAdapter?> = moshi.adapter(
      newParameterizedType(List::class.javaObjectType, String::class.javaObjectType),
      setOf(),
      "attributeNames"
  )

  private val options: JsonReader.Options = JsonReader.Options.of(
      "QueueUrl",
      "MaxNumberOfMessages",
      "VisibilityTimeout",
      "expires",
      "WaitTimeSeconds",
      "MessageAttributeNames",
      "EeceiveRequestAttemptId",
      "AttributeNames"
  )

  @Volatile
  private var defaultConstructor: Constructor? = null

  @Throws(IOException::class)
  override fun toJson(writer: JsonWriter, `value`: ReceiveMessage?) {
    if (`value` == null) {
      writer.nullValue()
      return
    }
    writer
      .beginObject()
      .name("QueueUrl").apply {
        queueUrlAdapter.toJson(this, `value`.queueUrl)
      }
      .name("MaxNumberOfMessages").value(`value`.maxNumberOfMessages)
      .name("VisibilityTimeout").value(`value`.visibilityTimeout)
      .name("expires").apply {
        expiresAdapter.toJson(this, `value`.expires)
      }
      .name("WaitTimeSeconds").value(`value`.waitTimeSeconds)
      .name("MessageAttributeNames").apply {
        messageAttributesAdapter.toJson(this, `value`.messageAttributes)
      }
      .name("EeceiveRequestAttemptId").value(`value`.receiveRequestAttemptId)
      .name("AttributeNames").apply {
        attributeNamesAdapter.toJson(this, `value`.attributeNames)
      }
      .endObject()
  }

  @Throws(IOException::class)
  override fun fromJson(reader: JsonReader): ReceiveMessage? {
    if (reader.peek() == JsonReader.Token.NULL) return reader.nextNull()

    var mask = -1
    var queueUrl: Uri? = null
    var maxNumberOfMessages: Int? = null
    var visibilityTimeout: Int? = null
    var expires: ZonedDateTime? = null
    var waitTimeSeconds: Int? = null
    var messageAttributes: List? = null
    var receiveRequestAttemptId: String? = null
    var attributeNames: List? = null

    reader.beginObject()
    while (reader.hasNext()) {
      when (reader.selectName(options)) {
        0 -> {
          queueUrl = queueUrlAdapter.fromJson(reader)
        }
        1 -> {
          if (reader.peek() == JsonReader.Token.NULL) {
            reader.skipValue()
          } else {
            maxNumberOfMessages = reader.nextInt()
          }
          // $mask = $mask and (1 shl 1).inv()
          mask = mask and 0xfffffffd.toInt()
        }
        2 -> {
          if (reader.peek() == JsonReader.Token.NULL) {
            reader.skipValue()
          } else {
            visibilityTimeout = reader.nextInt()
          }
          // $mask = $mask and (1 shl 2).inv()
          mask = mask and 0xfffffffb.toInt()
        }
        3 -> {
          expires = expiresAdapter.fromJson(reader)
          // $mask = $mask and (1 shl 3).inv()
          mask = mask and 0xfffffff7.toInt()
        }
        4 -> {
          if (reader.peek() == JsonReader.Token.NULL) {
            reader.skipValue()
          } else {
            waitTimeSeconds = reader.nextInt()
          }
          // $mask = $mask and (1 shl 4).inv()
          mask = mask and 0xffffffef.toInt()
        }
        5 -> {
          messageAttributes = messageAttributesAdapter.fromJson(reader)
          // $mask = $mask and (1 shl 5).inv()
          mask = mask and 0xffffffdf.toInt()
        }
        6 -> {
          if (reader.peek() == JsonReader.Token.NULL) {
            reader.skipValue()
          } else {
            receiveRequestAttemptId = reader.nextString()
          }
          // $mask = $mask and (1 shl 6).inv()
          mask = mask and 0xffffffbf.toInt()
        }
        7 -> {
          attributeNames = attributeNamesAdapter.fromJson(reader)
          // $mask = $mask and (1 shl 7).inv()
          mask = mask and 0xffffff7f.toInt()
        }
        -1 -> {
          reader.skipName()
          reader.skipValue()
        }
      }
    }
    reader.endObject()

    var errorBuilder: StringBuilder? = null
    if (queueUrl == null) {
      errorBuilder = errorBuilder.appendNullableError("queueUrl", "QueueUrl")
    }
    if (errorBuilder != null) {
      errorBuilder.append(" (at path ").append(reader.path).append(')')
      throw JsonDataException(errorBuilder.toString())
    }

    return if (mask == 0xffffff01.toInt()) {
      ReceiveMessage(
          queueUrl = queueUrl!!,
          maxNumberOfMessages = maxNumberOfMessages,
          visibilityTimeout = visibilityTimeout,
          expires = expires,
          waitTimeSeconds = waitTimeSeconds,
          messageAttributes = messageAttributes,
          receiveRequestAttemptId = receiveRequestAttemptId,
          attributeNames = attributeNames
      )
    } else {
      // Reflectively invoke the synthetic defaults constructor
      @Suppress("UNCHECKED_CAST")
      val localConstructor: Constructor =
          this.defaultConstructor ?: ReceiveMessage::class.java.getDeclaredConstructor(
            Uri::class.java,
            Int::class.javaObjectType,
            Int::class.javaObjectType,
            ZonedDateTime::class.java,
            Int::class.javaObjectType,
            List::class.java,
            String::class.java,
            List::class.java,
            Int::class.javaPrimitiveType,
            DefaultConstructorMarker::class.java
          ).also { this.defaultConstructor = it }
      localConstructor.newInstance(
          queueUrl,
          maxNumberOfMessages,
          visibilityTimeout,
          expires,
          waitTimeSeconds,
          messageAttributes,
          receiveRequestAttemptId,
          attributeNames,
          mask,
          /* DefaultConstructorMarker */ null
      )
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy