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

commonMain.aws.sdk.kotlin.services.iotfleetwise.serde.GetCampaignOperationDeserializer.kt Maven / Gradle / Ivy

The newest version!
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!

package aws.sdk.kotlin.services.iotfleetwise.serde

import aws.sdk.kotlin.services.iotfleetwise.model.CampaignStatus
import aws.sdk.kotlin.services.iotfleetwise.model.CollectionScheme
import aws.sdk.kotlin.services.iotfleetwise.model.Compression
import aws.sdk.kotlin.services.iotfleetwise.model.DataDestinationConfig
import aws.sdk.kotlin.services.iotfleetwise.model.DiagnosticsMode
import aws.sdk.kotlin.services.iotfleetwise.model.GetCampaignResponse
import aws.sdk.kotlin.services.iotfleetwise.model.IotFleetWiseException
import aws.sdk.kotlin.services.iotfleetwise.model.SignalInformation
import aws.sdk.kotlin.services.iotfleetwise.model.SpoolingMode
import aws.smithy.kotlin.runtime.awsprotocol.json.RestJsonErrorDeserializer
import aws.smithy.kotlin.runtime.awsprotocol.setAseErrorMetadata
import aws.smithy.kotlin.runtime.awsprotocol.withPayload
import aws.smithy.kotlin.runtime.http.HttpCall
import aws.smithy.kotlin.runtime.http.isSuccess
import aws.smithy.kotlin.runtime.http.operation.HttpDeserializer
import aws.smithy.kotlin.runtime.operation.ExecutionContext
import aws.smithy.kotlin.runtime.serde.SdkFieldDescriptor
import aws.smithy.kotlin.runtime.serde.SdkObjectDescriptor
import aws.smithy.kotlin.runtime.serde.SerialKind
import aws.smithy.kotlin.runtime.serde.asSdkSerializable
import aws.smithy.kotlin.runtime.serde.deserializeList
import aws.smithy.kotlin.runtime.serde.deserializeMap
import aws.smithy.kotlin.runtime.serde.deserializeStruct
import aws.smithy.kotlin.runtime.serde.field
import aws.smithy.kotlin.runtime.serde.json.JsonDeserializer
import aws.smithy.kotlin.runtime.serde.json.JsonSerialName
import aws.smithy.kotlin.runtime.serde.serializeList
import aws.smithy.kotlin.runtime.serde.serializeMap
import aws.smithy.kotlin.runtime.serde.serializeStruct
import aws.smithy.kotlin.runtime.time.Instant
import aws.smithy.kotlin.runtime.time.TimestampFormat
import kotlin.collections.mutableListOf


internal class GetCampaignOperationDeserializer: HttpDeserializer.NonStreaming {

    override fun deserialize(context: ExecutionContext, call: HttpCall, payload: ByteArray?): GetCampaignResponse {
        val response = call.response
        if (!response.status.isSuccess()) {
            throwGetCampaignError(context, call, payload)
        }
        val builder = GetCampaignResponse.Builder()

        if (payload != null) {
            deserializeGetCampaignOperationBody(builder, payload)
        }
        builder.correctErrors()
        return builder.build()
    }
}

private fun throwGetCampaignError(context: ExecutionContext, call: HttpCall, payload: ByteArray?): kotlin.Nothing {
    val wrappedResponse = call.response.withPayload(payload)
    val wrappedCall = call.copy(response = wrappedResponse)

    val errorDetails = try {
        RestJsonErrorDeserializer.deserialize(call.response.headers, payload)
    } catch (ex: Exception) {
        throw IotFleetWiseException("Failed to parse response as 'awsJson1_0' error", ex).also {
            setAseErrorMetadata(it, wrappedCall.response, null)
        }
    }

    val ex = when(errorDetails.code) {
        "ThrottlingException" -> ThrottlingExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "ValidationException" -> ValidationExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "AccessDeniedException" -> AccessDeniedExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "ResourceNotFoundException" -> ResourceNotFoundExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "InternalServerException" -> InternalServerExceptionDeserializer().deserialize(context, wrappedCall, payload)
        else -> IotFleetWiseException(errorDetails.message)
    }

    setAseErrorMetadata(ex, wrappedResponse, errorDetails)
    throw ex
}

private fun deserializeGetCampaignOperationBody(builder: GetCampaignResponse.Builder, payload: ByteArray) {
    val deserializer = JsonDeserializer(payload)
    val ARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("arn"))
    val COLLECTIONSCHEME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("collectionScheme"))
    val COMPRESSION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("compression"))
    val CREATIONTIME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Timestamp, JsonSerialName("creationTime"))
    val DATADESTINATIONCONFIGS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.List, JsonSerialName("dataDestinationConfigs"))
    val DATAEXTRADIMENSIONS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.List, JsonSerialName("dataExtraDimensions"))
    val DESCRIPTION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("description"))
    val DIAGNOSTICSMODE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("diagnosticsMode"))
    val EXPIRYTIME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Timestamp, JsonSerialName("expiryTime"))
    val LASTMODIFICATIONTIME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Timestamp, JsonSerialName("lastModificationTime"))
    val NAME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("name"))
    val POSTTRIGGERCOLLECTIONDURATION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Long, JsonSerialName("postTriggerCollectionDuration"))
    val PRIORITY_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Integer, JsonSerialName("priority"))
    val SIGNALCATALOGARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("signalCatalogArn"))
    val SIGNALSTOCOLLECT_DESCRIPTOR = SdkFieldDescriptor(SerialKind.List, JsonSerialName("signalsToCollect"))
    val SPOOLINGMODE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("spoolingMode"))
    val STARTTIME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Timestamp, JsonSerialName("startTime"))
    val STATUS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("status"))
    val TARGETARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("targetArn"))
    val OBJ_DESCRIPTOR = SdkObjectDescriptor.build {
        field(ARN_DESCRIPTOR)
        field(COLLECTIONSCHEME_DESCRIPTOR)
        field(COMPRESSION_DESCRIPTOR)
        field(CREATIONTIME_DESCRIPTOR)
        field(DATADESTINATIONCONFIGS_DESCRIPTOR)
        field(DATAEXTRADIMENSIONS_DESCRIPTOR)
        field(DESCRIPTION_DESCRIPTOR)
        field(DIAGNOSTICSMODE_DESCRIPTOR)
        field(EXPIRYTIME_DESCRIPTOR)
        field(LASTMODIFICATIONTIME_DESCRIPTOR)
        field(NAME_DESCRIPTOR)
        field(POSTTRIGGERCOLLECTIONDURATION_DESCRIPTOR)
        field(PRIORITY_DESCRIPTOR)
        field(SIGNALCATALOGARN_DESCRIPTOR)
        field(SIGNALSTOCOLLECT_DESCRIPTOR)
        field(SPOOLINGMODE_DESCRIPTOR)
        field(STARTTIME_DESCRIPTOR)
        field(STATUS_DESCRIPTOR)
        field(TARGETARN_DESCRIPTOR)
    }

    deserializer.deserializeStruct(OBJ_DESCRIPTOR) {
        loop@while (true) {
            when (findNextFieldIndex()) {
                ARN_DESCRIPTOR.index -> builder.arn = deserializeString()
                COLLECTIONSCHEME_DESCRIPTOR.index -> builder.collectionScheme = deserializeCollectionSchemeDocument(deserializer)
                COMPRESSION_DESCRIPTOR.index -> builder.compression = deserializeString().let { Compression.fromValue(it) }
                CREATIONTIME_DESCRIPTOR.index -> builder.creationTime = deserializeInstant(TimestampFormat.EPOCH_SECONDS)
                DATADESTINATIONCONFIGS_DESCRIPTOR.index -> builder.dataDestinationConfigs =
                    deserializer.deserializeList(DATADESTINATIONCONFIGS_DESCRIPTOR) {
                        val col0 = mutableListOf()
                        while (hasNextElement()) {
                            val el0 = if (nextHasValue()) { deserializeDataDestinationConfigDocument(deserializer) } else { deserializeNull(); continue }
                            col0.add(el0)
                        }
                        col0
                    }
                DATAEXTRADIMENSIONS_DESCRIPTOR.index -> builder.dataExtraDimensions =
                    deserializer.deserializeList(DATAEXTRADIMENSIONS_DESCRIPTOR) {
                        val col0 = mutableListOf()
                        while (hasNextElement()) {
                            val el0 = if (nextHasValue()) { deserializeString() } else { deserializeNull(); continue }
                            col0.add(el0)
                        }
                        col0
                    }
                DESCRIPTION_DESCRIPTOR.index -> builder.description = deserializeString()
                DIAGNOSTICSMODE_DESCRIPTOR.index -> builder.diagnosticsMode = deserializeString().let { DiagnosticsMode.fromValue(it) }
                EXPIRYTIME_DESCRIPTOR.index -> builder.expiryTime = deserializeInstant(TimestampFormat.EPOCH_SECONDS)
                LASTMODIFICATIONTIME_DESCRIPTOR.index -> builder.lastModificationTime = deserializeInstant(TimestampFormat.EPOCH_SECONDS)
                NAME_DESCRIPTOR.index -> builder.name = deserializeString()
                POSTTRIGGERCOLLECTIONDURATION_DESCRIPTOR.index -> builder.postTriggerCollectionDuration = deserializeLong()
                PRIORITY_DESCRIPTOR.index -> builder.priority = deserializeInt()
                SIGNALCATALOGARN_DESCRIPTOR.index -> builder.signalCatalogArn = deserializeString()
                SIGNALSTOCOLLECT_DESCRIPTOR.index -> builder.signalsToCollect =
                    deserializer.deserializeList(SIGNALSTOCOLLECT_DESCRIPTOR) {
                        val col0 = mutableListOf()
                        while (hasNextElement()) {
                            val el0 = if (nextHasValue()) { deserializeSignalInformationDocument(deserializer) } else { deserializeNull(); continue }
                            col0.add(el0)
                        }
                        col0
                    }
                SPOOLINGMODE_DESCRIPTOR.index -> builder.spoolingMode = deserializeString().let { SpoolingMode.fromValue(it) }
                STARTTIME_DESCRIPTOR.index -> builder.startTime = deserializeInstant(TimestampFormat.EPOCH_SECONDS)
                STATUS_DESCRIPTOR.index -> builder.status = deserializeString().let { CampaignStatus.fromValue(it) }
                TARGETARN_DESCRIPTOR.index -> builder.targetArn = deserializeString()
                null -> break@loop
                else -> skipValue()
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy