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

commonMain.aws.sdk.kotlin.services.backup.serde.DescribeRecoveryPointOperationDeserializer.kt Maven / Gradle / Ivy

There is a newer version: 1.3.37
Show newest version
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!

package aws.sdk.kotlin.services.backup.serde

import aws.sdk.kotlin.services.backup.model.BackupException
import aws.sdk.kotlin.services.backup.model.CalculatedLifecycle
import aws.sdk.kotlin.services.backup.model.DescribeRecoveryPointResponse
import aws.sdk.kotlin.services.backup.model.Lifecycle
import aws.sdk.kotlin.services.backup.model.RecoveryPointCreator
import aws.sdk.kotlin.services.backup.model.RecoveryPointStatus
import aws.sdk.kotlin.services.backup.model.StorageClass
import aws.sdk.kotlin.services.backup.model.VaultType
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


internal class DescribeRecoveryPointOperationDeserializer: HttpDeserializer.NonStreaming {

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

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

private fun throwDescribeRecoveryPointError(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 BackupException("Failed to parse response as 'restJson1' error", ex).also {
            setAseErrorMetadata(it, wrappedCall.response, null)
        }
    }

    val ex = when(errorDetails.code) {
        "ResourceNotFoundException" -> ResourceNotFoundExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "MissingParameterValueException" -> MissingParameterValueExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "InvalidParameterValueException" -> InvalidParameterValueExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "ServiceUnavailableException" -> ServiceUnavailableExceptionDeserializer().deserialize(context, wrappedCall, payload)
        else -> BackupException(errorDetails.message)
    }

    setAseErrorMetadata(ex, wrappedResponse, errorDetails)
    throw ex
}

private fun deserializeDescribeRecoveryPointOperationBody(builder: DescribeRecoveryPointResponse.Builder, payload: ByteArray) {
    val deserializer = JsonDeserializer(payload)
    val BACKUPSIZEINBYTES_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Long, JsonSerialName("BackupSizeInBytes"))
    val BACKUPVAULTARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("BackupVaultArn"))
    val BACKUPVAULTNAME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("BackupVaultName"))
    val CALCULATEDLIFECYCLE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("CalculatedLifecycle"))
    val COMPLETIONDATE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Timestamp, JsonSerialName("CompletionDate"))
    val COMPOSITEMEMBERIDENTIFIER_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("CompositeMemberIdentifier"))
    val CREATEDBY_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("CreatedBy"))
    val CREATIONDATE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Timestamp, JsonSerialName("CreationDate"))
    val ENCRYPTIONKEYARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("EncryptionKeyArn"))
    val IAMROLEARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("IamRoleArn"))
    val ISENCRYPTED_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Boolean, JsonSerialName("IsEncrypted"))
    val ISPARENT_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Boolean, JsonSerialName("IsParent"))
    val LASTRESTORETIME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Timestamp, JsonSerialName("LastRestoreTime"))
    val LIFECYCLE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("Lifecycle"))
    val PARENTRECOVERYPOINTARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("ParentRecoveryPointArn"))
    val RECOVERYPOINTARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("RecoveryPointArn"))
    val RESOURCEARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("ResourceArn"))
    val RESOURCENAME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("ResourceName"))
    val RESOURCETYPE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("ResourceType"))
    val SOURCEBACKUPVAULTARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("SourceBackupVaultArn"))
    val STATUS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("Status"))
    val STATUSMESSAGE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("StatusMessage"))
    val STORAGECLASS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("StorageClass"))
    val VAULTTYPE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("VaultType"))
    val OBJ_DESCRIPTOR = SdkObjectDescriptor.build {
        field(BACKUPSIZEINBYTES_DESCRIPTOR)
        field(BACKUPVAULTARN_DESCRIPTOR)
        field(BACKUPVAULTNAME_DESCRIPTOR)
        field(CALCULATEDLIFECYCLE_DESCRIPTOR)
        field(COMPLETIONDATE_DESCRIPTOR)
        field(COMPOSITEMEMBERIDENTIFIER_DESCRIPTOR)
        field(CREATEDBY_DESCRIPTOR)
        field(CREATIONDATE_DESCRIPTOR)
        field(ENCRYPTIONKEYARN_DESCRIPTOR)
        field(IAMROLEARN_DESCRIPTOR)
        field(ISENCRYPTED_DESCRIPTOR)
        field(ISPARENT_DESCRIPTOR)
        field(LASTRESTORETIME_DESCRIPTOR)
        field(LIFECYCLE_DESCRIPTOR)
        field(PARENTRECOVERYPOINTARN_DESCRIPTOR)
        field(RECOVERYPOINTARN_DESCRIPTOR)
        field(RESOURCEARN_DESCRIPTOR)
        field(RESOURCENAME_DESCRIPTOR)
        field(RESOURCETYPE_DESCRIPTOR)
        field(SOURCEBACKUPVAULTARN_DESCRIPTOR)
        field(STATUS_DESCRIPTOR)
        field(STATUSMESSAGE_DESCRIPTOR)
        field(STORAGECLASS_DESCRIPTOR)
        field(VAULTTYPE_DESCRIPTOR)
    }

    deserializer.deserializeStruct(OBJ_DESCRIPTOR) {
        loop@while (true) {
            when (findNextFieldIndex()) {
                BACKUPSIZEINBYTES_DESCRIPTOR.index -> builder.backupSizeInBytes = deserializeLong()
                BACKUPVAULTARN_DESCRIPTOR.index -> builder.backupVaultArn = deserializeString()
                BACKUPVAULTNAME_DESCRIPTOR.index -> builder.backupVaultName = deserializeString()
                CALCULATEDLIFECYCLE_DESCRIPTOR.index -> builder.calculatedLifecycle = deserializeCalculatedLifecycleDocument(deserializer)
                COMPLETIONDATE_DESCRIPTOR.index -> builder.completionDate = deserializeInstant(TimestampFormat.EPOCH_SECONDS)
                COMPOSITEMEMBERIDENTIFIER_DESCRIPTOR.index -> builder.compositeMemberIdentifier = deserializeString()
                CREATEDBY_DESCRIPTOR.index -> builder.createdBy = deserializeRecoveryPointCreatorDocument(deserializer)
                CREATIONDATE_DESCRIPTOR.index -> builder.creationDate = deserializeInstant(TimestampFormat.EPOCH_SECONDS)
                ENCRYPTIONKEYARN_DESCRIPTOR.index -> builder.encryptionKeyArn = deserializeString()
                IAMROLEARN_DESCRIPTOR.index -> builder.iamRoleArn = deserializeString()
                ISENCRYPTED_DESCRIPTOR.index -> builder.isEncrypted = deserializeBoolean()
                ISPARENT_DESCRIPTOR.index -> builder.isParent = deserializeBoolean()
                LASTRESTORETIME_DESCRIPTOR.index -> builder.lastRestoreTime = deserializeInstant(TimestampFormat.EPOCH_SECONDS)
                LIFECYCLE_DESCRIPTOR.index -> builder.lifecycle = deserializeLifecycleDocument(deserializer)
                PARENTRECOVERYPOINTARN_DESCRIPTOR.index -> builder.parentRecoveryPointArn = deserializeString()
                RECOVERYPOINTARN_DESCRIPTOR.index -> builder.recoveryPointArn = deserializeString()
                RESOURCEARN_DESCRIPTOR.index -> builder.resourceArn = deserializeString()
                RESOURCENAME_DESCRIPTOR.index -> builder.resourceName = deserializeString()
                RESOURCETYPE_DESCRIPTOR.index -> builder.resourceType = deserializeString()
                SOURCEBACKUPVAULTARN_DESCRIPTOR.index -> builder.sourceBackupVaultArn = deserializeString()
                STATUS_DESCRIPTOR.index -> builder.status = deserializeString().let { RecoveryPointStatus.fromValue(it) }
                STATUSMESSAGE_DESCRIPTOR.index -> builder.statusMessage = deserializeString()
                STORAGECLASS_DESCRIPTOR.index -> builder.storageClass = deserializeString().let { StorageClass.fromValue(it) }
                VAULTTYPE_DESCRIPTOR.index -> builder.vaultType = deserializeString().let { VaultType.fromValue(it) }
                null -> break@loop
                else -> skipValue()
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy