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

commonMain.aws.sdk.kotlin.services.mgn.transform.UpdateReplicationConfigurationTemplateOperationDeserializer.kt Maven / Gradle / Ivy

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

package aws.sdk.kotlin.services.mgn.transform

import aws.sdk.kotlin.runtime.http.setAseErrorMetadata
import aws.sdk.kotlin.runtime.http.withPayload
import aws.sdk.kotlin.runtime.protocol.json.RestJsonErrorDeserializer
import aws.sdk.kotlin.services.mgn.model.MgnException
import aws.sdk.kotlin.services.mgn.model.ReplicationConfigurationDataPlaneRouting
import aws.sdk.kotlin.services.mgn.model.ReplicationConfigurationDefaultLargeStagingDiskType
import aws.sdk.kotlin.services.mgn.model.ReplicationConfigurationEbsEncryption
import aws.sdk.kotlin.services.mgn.model.UpdateReplicationConfigurationTemplateResponse
import aws.smithy.kotlin.runtime.client.ExecutionContext
import aws.smithy.kotlin.runtime.http.isSuccess
import aws.smithy.kotlin.runtime.http.operation.HttpDeserialize
import aws.smithy.kotlin.runtime.http.readAll
import aws.smithy.kotlin.runtime.http.response.HttpResponse
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


internal class UpdateReplicationConfigurationTemplateOperationDeserializer: HttpDeserialize {

    override suspend fun deserialize(context: ExecutionContext, response: HttpResponse): UpdateReplicationConfigurationTemplateResponse {
        if (!response.status.isSuccess()) {
            throwUpdateReplicationConfigurationTemplateError(context, response)
        }
        val builder = UpdateReplicationConfigurationTemplateResponse.Builder()

        val payload = response.body.readAll()
        if (payload != null) {
            deserializeUpdateReplicationConfigurationTemplateOperationBody(builder, payload)
        }
        return builder.build()
    }
}

private suspend fun throwUpdateReplicationConfigurationTemplateError(context: ExecutionContext, response: HttpResponse): kotlin.Nothing {
    val payload = response.body.readAll()
    val wrappedResponse = response.withPayload(payload)

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

    val ex = when(errorDetails.code) {
        "AccessDeniedException" -> AccessDeniedExceptionDeserializer().deserialize(context, wrappedResponse)
        "ResourceNotFoundException" -> ResourceNotFoundExceptionDeserializer().deserialize(context, wrappedResponse)
        "UninitializedAccountException" -> UninitializedAccountExceptionDeserializer().deserialize(context, wrappedResponse)
        "ValidationException" -> ValidationExceptionDeserializer().deserialize(context, wrappedResponse)
        else -> MgnException(errorDetails.message)
    }

    setAseErrorMetadata(ex, wrappedResponse, errorDetails)
    throw ex
}

private fun deserializeUpdateReplicationConfigurationTemplateOperationBody(builder: UpdateReplicationConfigurationTemplateResponse.Builder, payload: ByteArray) {
    val deserializer = JsonDeserializer(payload)
    val ARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("arn"))
    val ASSOCIATEDEFAULTSECURITYGROUP_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Boolean, JsonSerialName("associateDefaultSecurityGroup"))
    val BANDWIDTHTHROTTLING_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Long, JsonSerialName("bandwidthThrottling"))
    val CREATEPUBLICIP_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Boolean, JsonSerialName("createPublicIP"))
    val DATAPLANEROUTING_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("dataPlaneRouting"))
    val DEFAULTLARGESTAGINGDISKTYPE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("defaultLargeStagingDiskType"))
    val EBSENCRYPTION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("ebsEncryption"))
    val EBSENCRYPTIONKEYARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("ebsEncryptionKeyArn"))
    val REPLICATIONCONFIGURATIONTEMPLATEID_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("replicationConfigurationTemplateID"))
    val REPLICATIONSERVERINSTANCETYPE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("replicationServerInstanceType"))
    val REPLICATIONSERVERSSECURITYGROUPSIDS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.List, JsonSerialName("replicationServersSecurityGroupsIDs"))
    val STAGINGAREASUBNETID_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("stagingAreaSubnetId"))
    val STAGINGAREATAGS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Map, JsonSerialName("stagingAreaTags"))
    val TAGS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Map, JsonSerialName("tags"))
    val USEDEDICATEDREPLICATIONSERVER_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Boolean, JsonSerialName("useDedicatedReplicationServer"))
    val OBJ_DESCRIPTOR = SdkObjectDescriptor.build {
        field(ARN_DESCRIPTOR)
        field(ASSOCIATEDEFAULTSECURITYGROUP_DESCRIPTOR)
        field(BANDWIDTHTHROTTLING_DESCRIPTOR)
        field(CREATEPUBLICIP_DESCRIPTOR)
        field(DATAPLANEROUTING_DESCRIPTOR)
        field(DEFAULTLARGESTAGINGDISKTYPE_DESCRIPTOR)
        field(EBSENCRYPTION_DESCRIPTOR)
        field(EBSENCRYPTIONKEYARN_DESCRIPTOR)
        field(REPLICATIONCONFIGURATIONTEMPLATEID_DESCRIPTOR)
        field(REPLICATIONSERVERINSTANCETYPE_DESCRIPTOR)
        field(REPLICATIONSERVERSSECURITYGROUPSIDS_DESCRIPTOR)
        field(STAGINGAREASUBNETID_DESCRIPTOR)
        field(STAGINGAREATAGS_DESCRIPTOR)
        field(TAGS_DESCRIPTOR)
        field(USEDEDICATEDREPLICATIONSERVER_DESCRIPTOR)
    }

    deserializer.deserializeStruct(OBJ_DESCRIPTOR) {
        loop@while (true) {
            when (findNextFieldIndex()) {
                ARN_DESCRIPTOR.index -> builder.arn = deserializeString()
                ASSOCIATEDEFAULTSECURITYGROUP_DESCRIPTOR.index -> builder.associateDefaultSecurityGroup = deserializeBoolean()
                BANDWIDTHTHROTTLING_DESCRIPTOR.index -> builder.bandwidthThrottling = deserializeLong()
                CREATEPUBLICIP_DESCRIPTOR.index -> builder.createPublicIp = deserializeBoolean()
                DATAPLANEROUTING_DESCRIPTOR.index -> builder.dataPlaneRouting = deserializeString().let { ReplicationConfigurationDataPlaneRouting.fromValue(it) }
                DEFAULTLARGESTAGINGDISKTYPE_DESCRIPTOR.index -> builder.defaultLargeStagingDiskType = deserializeString().let { ReplicationConfigurationDefaultLargeStagingDiskType.fromValue(it) }
                EBSENCRYPTION_DESCRIPTOR.index -> builder.ebsEncryption = deserializeString().let { ReplicationConfigurationEbsEncryption.fromValue(it) }
                EBSENCRYPTIONKEYARN_DESCRIPTOR.index -> builder.ebsEncryptionKeyArn = deserializeString()
                REPLICATIONCONFIGURATIONTEMPLATEID_DESCRIPTOR.index -> builder.replicationConfigurationTemplateId = deserializeString()
                REPLICATIONSERVERINSTANCETYPE_DESCRIPTOR.index -> builder.replicationServerInstanceType = deserializeString()
                REPLICATIONSERVERSSECURITYGROUPSIDS_DESCRIPTOR.index -> builder.replicationServersSecurityGroupsIDs =
                    deserializer.deserializeList(REPLICATIONSERVERSSECURITYGROUPSIDS_DESCRIPTOR) {
                        val col0 = mutableListOf()
                        while (hasNextElement()) {
                            val el0 = if (nextHasValue()) { deserializeString() } else { deserializeNull(); continue }
                            col0.add(el0)
                        }
                        col0
                    }
                STAGINGAREASUBNETID_DESCRIPTOR.index -> builder.stagingAreaSubnetId = deserializeString()
                STAGINGAREATAGS_DESCRIPTOR.index -> builder.stagingAreaTags =
                    deserializer.deserializeMap(STAGINGAREATAGS_DESCRIPTOR) {
                        val map0 = mutableMapOf()
                        while (hasNextEntry()) {
                            val k0 = key()
                            val v0 = if (nextHasValue()) { deserializeString() } else { deserializeNull(); continue }
                            map0[k0] = v0
                        }
                        map0
                    }
                TAGS_DESCRIPTOR.index -> builder.tags =
                    deserializer.deserializeMap(TAGS_DESCRIPTOR) {
                        val map0 = mutableMapOf()
                        while (hasNextEntry()) {
                            val k0 = key()
                            val v0 = if (nextHasValue()) { deserializeString() } else { deserializeNull(); continue }
                            map0[k0] = v0
                        }
                        map0
                    }
                USEDEDICATEDREPLICATIONSERVER_DESCRIPTOR.index -> builder.useDedicatedReplicationServer = deserializeBoolean()
                null -> break@loop
                else -> skipValue()
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy