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

commonMain.aws.sdk.kotlin.services.qldbsession.serde.SendCommandOperationDeserializer.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.qldbsession.serde

import aws.sdk.kotlin.services.qldbsession.model.AbortTransactionResult
import aws.sdk.kotlin.services.qldbsession.model.CommitTransactionResult
import aws.sdk.kotlin.services.qldbsession.model.EndSessionResult
import aws.sdk.kotlin.services.qldbsession.model.ExecuteStatementResult
import aws.sdk.kotlin.services.qldbsession.model.FetchPageResult
import aws.sdk.kotlin.services.qldbsession.model.QldbSessionException
import aws.sdk.kotlin.services.qldbsession.model.SendCommandResponse
import aws.sdk.kotlin.services.qldbsession.model.StartSessionResult
import aws.sdk.kotlin.services.qldbsession.model.StartTransactionResult
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


internal class SendCommandOperationDeserializer: HttpDeserializer.NonStreaming {

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

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

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

    val ex = when(errorDetails.code) {
        "CapacityExceededException" -> CapacityExceededExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "InvalidSessionException" -> InvalidSessionExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "OccConflictException" -> OccConflictExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "RateExceededException" -> RateExceededExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "BadRequestException" -> BadRequestExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "LimitExceededException" -> LimitExceededExceptionDeserializer().deserialize(context, wrappedCall, payload)
        else -> QldbSessionException(errorDetails.message)
    }

    setAseErrorMetadata(ex, wrappedResponse, errorDetails)
    throw ex
}

private fun deserializeSendCommandOperationBody(builder: SendCommandResponse.Builder, payload: ByteArray) {
    val deserializer = JsonDeserializer(payload)
    val ABORTTRANSACTION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("AbortTransaction"))
    val COMMITTRANSACTION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("CommitTransaction"))
    val ENDSESSION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("EndSession"))
    val EXECUTESTATEMENT_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("ExecuteStatement"))
    val FETCHPAGE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("FetchPage"))
    val STARTSESSION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("StartSession"))
    val STARTTRANSACTION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("StartTransaction"))
    val OBJ_DESCRIPTOR = SdkObjectDescriptor.build {
        field(ABORTTRANSACTION_DESCRIPTOR)
        field(COMMITTRANSACTION_DESCRIPTOR)
        field(ENDSESSION_DESCRIPTOR)
        field(EXECUTESTATEMENT_DESCRIPTOR)
        field(FETCHPAGE_DESCRIPTOR)
        field(STARTSESSION_DESCRIPTOR)
        field(STARTTRANSACTION_DESCRIPTOR)
    }

    deserializer.deserializeStruct(OBJ_DESCRIPTOR) {
        loop@while (true) {
            when (findNextFieldIndex()) {
                ABORTTRANSACTION_DESCRIPTOR.index -> builder.abortTransaction = deserializeAbortTransactionResultDocument(deserializer)
                COMMITTRANSACTION_DESCRIPTOR.index -> builder.commitTransaction = deserializeCommitTransactionResultDocument(deserializer)
                ENDSESSION_DESCRIPTOR.index -> builder.endSession = deserializeEndSessionResultDocument(deserializer)
                EXECUTESTATEMENT_DESCRIPTOR.index -> builder.executeStatement = deserializeExecuteStatementResultDocument(deserializer)
                FETCHPAGE_DESCRIPTOR.index -> builder.fetchPage = deserializeFetchPageResultDocument(deserializer)
                STARTSESSION_DESCRIPTOR.index -> builder.startSession = deserializeStartSessionResultDocument(deserializer)
                STARTTRANSACTION_DESCRIPTOR.index -> builder.startTransaction = deserializeStartTransactionResultDocument(deserializer)
                null -> break@loop
                else -> skipValue()
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy