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

commonMain.aws.sdk.kotlin.services.backup.serde.DescribeRestoreJobOperationDeserializer.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.DescribeRestoreJobResponse
import aws.sdk.kotlin.services.backup.model.RestoreDeletionStatus
import aws.sdk.kotlin.services.backup.model.RestoreJobCreator
import aws.sdk.kotlin.services.backup.model.RestoreJobStatus
import aws.sdk.kotlin.services.backup.model.RestoreValidationStatus
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 DescribeRestoreJobOperationDeserializer: HttpDeserializer.NonStreaming {

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

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

private fun throwDescribeRestoreJobError(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)
        "DependencyFailureException" -> DependencyFailureExceptionDeserializer().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 deserializeDescribeRestoreJobOperationBody(builder: DescribeRestoreJobResponse.Builder, payload: ByteArray) {
    val deserializer = JsonDeserializer(payload)
    val ACCOUNTID_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("AccountId"))
    val BACKUPSIZEINBYTES_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Long, JsonSerialName("BackupSizeInBytes"))
    val COMPLETIONDATE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Timestamp, JsonSerialName("CompletionDate"))
    val CREATEDBY_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("CreatedBy"))
    val CREATEDRESOURCEARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("CreatedResourceArn"))
    val CREATIONDATE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Timestamp, JsonSerialName("CreationDate"))
    val DELETIONSTATUS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("DeletionStatus"))
    val DELETIONSTATUSMESSAGE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("DeletionStatusMessage"))
    val EXPECTEDCOMPLETIONTIMEMINUTES_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Long, JsonSerialName("ExpectedCompletionTimeMinutes"))
    val IAMROLEARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("IamRoleArn"))
    val PERCENTDONE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("PercentDone"))
    val RECOVERYPOINTARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("RecoveryPointArn"))
    val RECOVERYPOINTCREATIONDATE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Timestamp, JsonSerialName("RecoveryPointCreationDate"))
    val RESOURCETYPE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("ResourceType"))
    val RESTOREJOBID_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("RestoreJobId"))
    val STATUS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("Status"))
    val STATUSMESSAGE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("StatusMessage"))
    val VALIDATIONSTATUS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("ValidationStatus"))
    val VALIDATIONSTATUSMESSAGE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("ValidationStatusMessage"))
    val OBJ_DESCRIPTOR = SdkObjectDescriptor.build {
        field(ACCOUNTID_DESCRIPTOR)
        field(BACKUPSIZEINBYTES_DESCRIPTOR)
        field(COMPLETIONDATE_DESCRIPTOR)
        field(CREATEDBY_DESCRIPTOR)
        field(CREATEDRESOURCEARN_DESCRIPTOR)
        field(CREATIONDATE_DESCRIPTOR)
        field(DELETIONSTATUS_DESCRIPTOR)
        field(DELETIONSTATUSMESSAGE_DESCRIPTOR)
        field(EXPECTEDCOMPLETIONTIMEMINUTES_DESCRIPTOR)
        field(IAMROLEARN_DESCRIPTOR)
        field(PERCENTDONE_DESCRIPTOR)
        field(RECOVERYPOINTARN_DESCRIPTOR)
        field(RECOVERYPOINTCREATIONDATE_DESCRIPTOR)
        field(RESOURCETYPE_DESCRIPTOR)
        field(RESTOREJOBID_DESCRIPTOR)
        field(STATUS_DESCRIPTOR)
        field(STATUSMESSAGE_DESCRIPTOR)
        field(VALIDATIONSTATUS_DESCRIPTOR)
        field(VALIDATIONSTATUSMESSAGE_DESCRIPTOR)
    }

    deserializer.deserializeStruct(OBJ_DESCRIPTOR) {
        loop@while (true) {
            when (findNextFieldIndex()) {
                ACCOUNTID_DESCRIPTOR.index -> builder.accountId = deserializeString()
                BACKUPSIZEINBYTES_DESCRIPTOR.index -> builder.backupSizeInBytes = deserializeLong()
                COMPLETIONDATE_DESCRIPTOR.index -> builder.completionDate = deserializeInstant(TimestampFormat.EPOCH_SECONDS)
                CREATEDBY_DESCRIPTOR.index -> builder.createdBy = deserializeRestoreJobCreatorDocument(deserializer)
                CREATEDRESOURCEARN_DESCRIPTOR.index -> builder.createdResourceArn = deserializeString()
                CREATIONDATE_DESCRIPTOR.index -> builder.creationDate = deserializeInstant(TimestampFormat.EPOCH_SECONDS)
                DELETIONSTATUS_DESCRIPTOR.index -> builder.deletionStatus = deserializeString().let { RestoreDeletionStatus.fromValue(it) }
                DELETIONSTATUSMESSAGE_DESCRIPTOR.index -> builder.deletionStatusMessage = deserializeString()
                EXPECTEDCOMPLETIONTIMEMINUTES_DESCRIPTOR.index -> builder.expectedCompletionTimeMinutes = deserializeLong()
                IAMROLEARN_DESCRIPTOR.index -> builder.iamRoleArn = deserializeString()
                PERCENTDONE_DESCRIPTOR.index -> builder.percentDone = deserializeString()
                RECOVERYPOINTARN_DESCRIPTOR.index -> builder.recoveryPointArn = deserializeString()
                RECOVERYPOINTCREATIONDATE_DESCRIPTOR.index -> builder.recoveryPointCreationDate = deserializeInstant(TimestampFormat.EPOCH_SECONDS)
                RESOURCETYPE_DESCRIPTOR.index -> builder.resourceType = deserializeString()
                RESTOREJOBID_DESCRIPTOR.index -> builder.restoreJobId = deserializeString()
                STATUS_DESCRIPTOR.index -> builder.status = deserializeString().let { RestoreJobStatus.fromValue(it) }
                STATUSMESSAGE_DESCRIPTOR.index -> builder.statusMessage = deserializeString()
                VALIDATIONSTATUS_DESCRIPTOR.index -> builder.validationStatus = deserializeString().let { RestoreValidationStatus.fromValue(it) }
                VALIDATIONSTATUSMESSAGE_DESCRIPTOR.index -> builder.validationStatusMessage = deserializeString()
                null -> break@loop
                else -> skipValue()
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy