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

commonMain.aws.sdk.kotlin.services.glue.serde.GetSchemaOperationDeserializer.kt Maven / Gradle / Ivy

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

package aws.sdk.kotlin.services.glue.serde

import aws.sdk.kotlin.services.glue.model.Compatibility
import aws.sdk.kotlin.services.glue.model.DataFormat
import aws.sdk.kotlin.services.glue.model.GetSchemaResponse
import aws.sdk.kotlin.services.glue.model.GlueException
import aws.sdk.kotlin.services.glue.model.SchemaStatus
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 GetSchemaOperationDeserializer: HttpDeserializer.NonStreaming {

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

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

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

    val ex = when(errorDetails.code) {
        "InternalServiceException" -> InternalServiceExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "EntityNotFoundException" -> EntityNotFoundExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "InvalidInputException" -> InvalidInputExceptionDeserializer().deserialize(context, wrappedCall, payload)
        "AccessDeniedException" -> AccessDeniedExceptionDeserializer().deserialize(context, wrappedCall, payload)
        else -> GlueException(errorDetails.message)
    }

    setAseErrorMetadata(ex, wrappedResponse, errorDetails)
    throw ex
}

private fun deserializeGetSchemaOperationBody(builder: GetSchemaResponse.Builder, payload: ByteArray) {
    val deserializer = JsonDeserializer(payload)
    val COMPATIBILITY_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("Compatibility"))
    val CREATEDTIME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("CreatedTime"))
    val DATAFORMAT_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("DataFormat"))
    val DESCRIPTION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("Description"))
    val LATESTSCHEMAVERSION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Long, JsonSerialName("LatestSchemaVersion"))
    val NEXTSCHEMAVERSION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Long, JsonSerialName("NextSchemaVersion"))
    val REGISTRYARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("RegistryArn"))
    val REGISTRYNAME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("RegistryName"))
    val SCHEMAARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("SchemaArn"))
    val SCHEMACHECKPOINT_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Long, JsonSerialName("SchemaCheckpoint"))
    val SCHEMANAME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("SchemaName"))
    val SCHEMASTATUS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("SchemaStatus"))
    val UPDATEDTIME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("UpdatedTime"))
    val OBJ_DESCRIPTOR = SdkObjectDescriptor.build {
        field(COMPATIBILITY_DESCRIPTOR)
        field(CREATEDTIME_DESCRIPTOR)
        field(DATAFORMAT_DESCRIPTOR)
        field(DESCRIPTION_DESCRIPTOR)
        field(LATESTSCHEMAVERSION_DESCRIPTOR)
        field(NEXTSCHEMAVERSION_DESCRIPTOR)
        field(REGISTRYARN_DESCRIPTOR)
        field(REGISTRYNAME_DESCRIPTOR)
        field(SCHEMAARN_DESCRIPTOR)
        field(SCHEMACHECKPOINT_DESCRIPTOR)
        field(SCHEMANAME_DESCRIPTOR)
        field(SCHEMASTATUS_DESCRIPTOR)
        field(UPDATEDTIME_DESCRIPTOR)
    }

    deserializer.deserializeStruct(OBJ_DESCRIPTOR) {
        loop@while (true) {
            when (findNextFieldIndex()) {
                COMPATIBILITY_DESCRIPTOR.index -> builder.compatibility = deserializeString().let { Compatibility.fromValue(it) }
                CREATEDTIME_DESCRIPTOR.index -> builder.createdTime = deserializeString()
                DATAFORMAT_DESCRIPTOR.index -> builder.dataFormat = deserializeString().let { DataFormat.fromValue(it) }
                DESCRIPTION_DESCRIPTOR.index -> builder.description = deserializeString()
                LATESTSCHEMAVERSION_DESCRIPTOR.index -> builder.latestSchemaVersion = deserializeLong()
                NEXTSCHEMAVERSION_DESCRIPTOR.index -> builder.nextSchemaVersion = deserializeLong()
                REGISTRYARN_DESCRIPTOR.index -> builder.registryArn = deserializeString()
                REGISTRYNAME_DESCRIPTOR.index -> builder.registryName = deserializeString()
                SCHEMAARN_DESCRIPTOR.index -> builder.schemaArn = deserializeString()
                SCHEMACHECKPOINT_DESCRIPTOR.index -> builder.schemaCheckpoint = deserializeLong()
                SCHEMANAME_DESCRIPTOR.index -> builder.schemaName = deserializeString()
                SCHEMASTATUS_DESCRIPTOR.index -> builder.schemaStatus = deserializeString().let { SchemaStatus.fromValue(it) }
                UPDATEDTIME_DESCRIPTOR.index -> builder.updatedTime = deserializeString()
                null -> break@loop
                else -> skipValue()
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy