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

commonMain.aws.sdk.kotlin.services.pipes.serde.DescribePipeOperationDeserializer.kt Maven / Gradle / Ivy

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

package aws.sdk.kotlin.services.pipes.serde

import aws.sdk.kotlin.services.pipes.model.DescribePipeResponse
import aws.sdk.kotlin.services.pipes.model.PipeEnrichmentParameters
import aws.sdk.kotlin.services.pipes.model.PipeLogConfiguration
import aws.sdk.kotlin.services.pipes.model.PipeSourceParameters
import aws.sdk.kotlin.services.pipes.model.PipeState
import aws.sdk.kotlin.services.pipes.model.PipeTargetParameters
import aws.sdk.kotlin.services.pipes.model.PipesException
import aws.sdk.kotlin.services.pipes.model.RequestedPipeStateDescribeResponse
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 kotlin.collections.mutableMapOf


internal class DescribePipeOperationDeserializer: HttpDeserializer.NonStreaming {

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

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

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

    val ex = when(errorDetails.code) {
        "ThrottlingException" -> ThrottlingExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "InternalException" -> InternalExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "ValidationException" -> ValidationExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "NotFoundException" -> NotFoundExceptionDeserializer().deserialize(context, wrappedCall, payload)
        else -> PipesException(errorDetails.message)
    }

    setAseErrorMetadata(ex, wrappedResponse, errorDetails)
    throw ex
}

private fun deserializeDescribePipeOperationBody(builder: DescribePipeResponse.Builder, payload: ByteArray) {
    val deserializer = JsonDeserializer(payload)
    val ARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("Arn"))
    val CREATIONTIME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Timestamp, JsonSerialName("CreationTime"))
    val CURRENTSTATE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("CurrentState"))
    val DESCRIPTION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("Description"))
    val DESIREDSTATE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("DesiredState"))
    val ENRICHMENT_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("Enrichment"))
    val ENRICHMENTPARAMETERS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("EnrichmentParameters"))
    val LASTMODIFIEDTIME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Timestamp, JsonSerialName("LastModifiedTime"))
    val LOGCONFIGURATION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("LogConfiguration"))
    val NAME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("Name"))
    val ROLEARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("RoleArn"))
    val SOURCE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("Source"))
    val SOURCEPARAMETERS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("SourceParameters"))
    val STATEREASON_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("StateReason"))
    val TAGS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Map, JsonSerialName("Tags"))
    val TARGET_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("Target"))
    val TARGETPARAMETERS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("TargetParameters"))
    val OBJ_DESCRIPTOR = SdkObjectDescriptor.build {
        field(ARN_DESCRIPTOR)
        field(CREATIONTIME_DESCRIPTOR)
        field(CURRENTSTATE_DESCRIPTOR)
        field(DESCRIPTION_DESCRIPTOR)
        field(DESIREDSTATE_DESCRIPTOR)
        field(ENRICHMENT_DESCRIPTOR)
        field(ENRICHMENTPARAMETERS_DESCRIPTOR)
        field(LASTMODIFIEDTIME_DESCRIPTOR)
        field(LOGCONFIGURATION_DESCRIPTOR)
        field(NAME_DESCRIPTOR)
        field(ROLEARN_DESCRIPTOR)
        field(SOURCE_DESCRIPTOR)
        field(SOURCEPARAMETERS_DESCRIPTOR)
        field(STATEREASON_DESCRIPTOR)
        field(TAGS_DESCRIPTOR)
        field(TARGET_DESCRIPTOR)
        field(TARGETPARAMETERS_DESCRIPTOR)
    }

    deserializer.deserializeStruct(OBJ_DESCRIPTOR) {
        loop@while (true) {
            when (findNextFieldIndex()) {
                ARN_DESCRIPTOR.index -> builder.arn = deserializeString()
                CREATIONTIME_DESCRIPTOR.index -> builder.creationTime = deserializeString().let { Instant.fromEpochSeconds(it) }
                CURRENTSTATE_DESCRIPTOR.index -> builder.currentState = deserializeString().let { PipeState.fromValue(it) }
                DESCRIPTION_DESCRIPTOR.index -> builder.description = deserializeString()
                DESIREDSTATE_DESCRIPTOR.index -> builder.desiredState = deserializeString().let { RequestedPipeStateDescribeResponse.fromValue(it) }
                ENRICHMENT_DESCRIPTOR.index -> builder.enrichment = deserializeString()
                ENRICHMENTPARAMETERS_DESCRIPTOR.index -> builder.enrichmentParameters = deserializePipeEnrichmentParametersDocument(deserializer)
                LASTMODIFIEDTIME_DESCRIPTOR.index -> builder.lastModifiedTime = deserializeString().let { Instant.fromEpochSeconds(it) }
                LOGCONFIGURATION_DESCRIPTOR.index -> builder.logConfiguration = deserializePipeLogConfigurationDocument(deserializer)
                NAME_DESCRIPTOR.index -> builder.name = deserializeString()
                ROLEARN_DESCRIPTOR.index -> builder.roleArn = deserializeString()
                SOURCE_DESCRIPTOR.index -> builder.source = deserializeString()
                SOURCEPARAMETERS_DESCRIPTOR.index -> builder.sourceParameters = deserializePipeSourceParametersDocument(deserializer)
                STATEREASON_DESCRIPTOR.index -> builder.stateReason = deserializeString()
                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
                    }
                TARGET_DESCRIPTOR.index -> builder.target = deserializeString()
                TARGETPARAMETERS_DESCRIPTOR.index -> builder.targetParameters = deserializePipeTargetParametersDocument(deserializer)
                null -> break@loop
                else -> skipValue()
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy