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

commonMain.aws.sdk.kotlin.services.efs.transform.CreateFileSystemOperationDeserializer.kt Maven / Gradle / Ivy

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

package aws.sdk.kotlin.services.efs.transform

import aws.sdk.kotlin.services.efs.model.CreateFileSystemResponse
import aws.sdk.kotlin.services.efs.model.EfsException
import aws.sdk.kotlin.services.efs.model.FileSystemSize
import aws.sdk.kotlin.services.efs.model.LifeCycleState
import aws.sdk.kotlin.services.efs.model.PerformanceMode
import aws.sdk.kotlin.services.efs.model.Tag
import aws.sdk.kotlin.services.efs.model.ThroughputMode
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.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.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 kotlin.collections.mutableListOf


internal class CreateFileSystemOperationDeserializer: HttpDeserialize {

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

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

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

    val ex = when(errorDetails.code) {
        "BadRequest" -> BadRequestDeserializer().deserialize(context, wrappedResponse)
        "FileSystemAlreadyExists" -> FileSystemAlreadyExistsDeserializer().deserialize(context, wrappedResponse)
        "FileSystemLimitExceeded" -> FileSystemLimitExceededDeserializer().deserialize(context, wrappedResponse)
        "InsufficientThroughputCapacity" -> InsufficientThroughputCapacityDeserializer().deserialize(context, wrappedResponse)
        "InternalServerError" -> InternalServerErrorDeserializer().deserialize(context, wrappedResponse)
        "ThroughputLimitExceeded" -> ThroughputLimitExceededDeserializer().deserialize(context, wrappedResponse)
        "UnsupportedAvailabilityZone" -> UnsupportedAvailabilityZoneDeserializer().deserialize(context, wrappedResponse)
        else -> EfsException(errorDetails.message)
    }

    setAseErrorMetadata(ex, wrappedResponse, errorDetails)
    throw ex
}

private fun deserializeCreateFileSystemOperationBody(builder: CreateFileSystemResponse.Builder, payload: ByteArray) {
    val deserializer = JsonDeserializer(payload)
    val AVAILABILITYZONEID_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("AvailabilityZoneId"))
    val AVAILABILITYZONENAME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("AvailabilityZoneName"))
    val CREATIONTIME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Timestamp, JsonSerialName("CreationTime"))
    val CREATIONTOKEN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("CreationToken"))
    val ENCRYPTED_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Boolean, JsonSerialName("Encrypted"))
    val FILESYSTEMARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("FileSystemArn"))
    val FILESYSTEMID_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("FileSystemId"))
    val KMSKEYID_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("KmsKeyId"))
    val LIFECYCLESTATE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("LifeCycleState"))
    val NAME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("Name"))
    val NUMBEROFMOUNTTARGETS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Integer, JsonSerialName("NumberOfMountTargets"))
    val OWNERID_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("OwnerId"))
    val PERFORMANCEMODE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("PerformanceMode"))
    val PROVISIONEDTHROUGHPUTINMIBPS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Double, JsonSerialName("ProvisionedThroughputInMibps"))
    val SIZEINBYTES_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("SizeInBytes"))
    val TAGS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.List, JsonSerialName("Tags"))
    val THROUGHPUTMODE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("ThroughputMode"))
    val OBJ_DESCRIPTOR = SdkObjectDescriptor.build {
        field(AVAILABILITYZONEID_DESCRIPTOR)
        field(AVAILABILITYZONENAME_DESCRIPTOR)
        field(CREATIONTIME_DESCRIPTOR)
        field(CREATIONTOKEN_DESCRIPTOR)
        field(ENCRYPTED_DESCRIPTOR)
        field(FILESYSTEMARN_DESCRIPTOR)
        field(FILESYSTEMID_DESCRIPTOR)
        field(KMSKEYID_DESCRIPTOR)
        field(LIFECYCLESTATE_DESCRIPTOR)
        field(NAME_DESCRIPTOR)
        field(NUMBEROFMOUNTTARGETS_DESCRIPTOR)
        field(OWNERID_DESCRIPTOR)
        field(PERFORMANCEMODE_DESCRIPTOR)
        field(PROVISIONEDTHROUGHPUTINMIBPS_DESCRIPTOR)
        field(SIZEINBYTES_DESCRIPTOR)
        field(TAGS_DESCRIPTOR)
        field(THROUGHPUTMODE_DESCRIPTOR)
    }

    deserializer.deserializeStruct(OBJ_DESCRIPTOR) {
        loop@while (true) {
            when (findNextFieldIndex()) {
                AVAILABILITYZONEID_DESCRIPTOR.index -> builder.availabilityZoneId = deserializeString()
                AVAILABILITYZONENAME_DESCRIPTOR.index -> builder.availabilityZoneName = deserializeString()
                CREATIONTIME_DESCRIPTOR.index -> builder.creationTime = deserializeString().let { Instant.fromEpochSeconds(it) }
                CREATIONTOKEN_DESCRIPTOR.index -> builder.creationToken = deserializeString()
                ENCRYPTED_DESCRIPTOR.index -> builder.encrypted = deserializeBoolean()
                FILESYSTEMARN_DESCRIPTOR.index -> builder.fileSystemArn = deserializeString()
                FILESYSTEMID_DESCRIPTOR.index -> builder.fileSystemId = deserializeString()
                KMSKEYID_DESCRIPTOR.index -> builder.kmsKeyId = deserializeString()
                LIFECYCLESTATE_DESCRIPTOR.index -> builder.lifeCycleState = deserializeString().let { LifeCycleState.fromValue(it) }
                NAME_DESCRIPTOR.index -> builder.name = deserializeString()
                NUMBEROFMOUNTTARGETS_DESCRIPTOR.index -> builder.numberOfMountTargets = deserializeInt()
                OWNERID_DESCRIPTOR.index -> builder.ownerId = deserializeString()
                PERFORMANCEMODE_DESCRIPTOR.index -> builder.performanceMode = deserializeString().let { PerformanceMode.fromValue(it) }
                PROVISIONEDTHROUGHPUTINMIBPS_DESCRIPTOR.index -> builder.provisionedThroughputInMibps = deserializeDouble()
                SIZEINBYTES_DESCRIPTOR.index -> builder.sizeInBytes = deserializeFileSystemSizeDocument(deserializer)
                TAGS_DESCRIPTOR.index -> builder.tags =
                    deserializer.deserializeList(TAGS_DESCRIPTOR) {
                        val col0 = mutableListOf()
                        while (hasNextElement()) {
                            val el0 = if (nextHasValue()) { deserializeTagDocument(deserializer) } else { deserializeNull(); continue }
                            col0.add(el0)
                        }
                        col0
                    }
                THROUGHPUTMODE_DESCRIPTOR.index -> builder.throughputMode = deserializeString().let { ThroughputMode.fromValue(it) }
                null -> break@loop
                else -> skipValue()
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy