
commonMain.aws.sdk.kotlin.services.medialive.transform.DescribeOfferingOperationDeserializer.kt Maven / Gradle / Ivy
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!
package aws.sdk.kotlin.services.medialive.transform
import aws.sdk.kotlin.services.medialive.model.DescribeOfferingResponse
import aws.sdk.kotlin.services.medialive.model.MediaLiveException
import aws.sdk.kotlin.services.medialive.model.OfferingDurationUnits
import aws.sdk.kotlin.services.medialive.model.OfferingType
import aws.sdk.kotlin.services.medialive.model.ReservationResourceSpecification
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
internal class DescribeOfferingOperationDeserializer: HttpDeserialize {
override suspend fun deserialize(context: ExecutionContext, response: HttpResponse): DescribeOfferingResponse {
if (!response.status.isSuccess()) {
throwDescribeOfferingError(context, response)
}
val builder = DescribeOfferingResponse.Builder()
val payload = response.body.readAll()
if (payload != null) {
deserializeDescribeOfferingOperationBody(builder, payload)
}
return builder.build()
}
}
private suspend fun throwDescribeOfferingError(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 MediaLiveException("Failed to parse response as 'restJson1' error", ex).also {
setAseErrorMetadata(it, wrappedResponse, null)
}
}
val ex = when(errorDetails.code) {
"BadGatewayException" -> BadGatewayExceptionDeserializer().deserialize(context, wrappedResponse)
"BadRequestException" -> BadRequestExceptionDeserializer().deserialize(context, wrappedResponse)
"ForbiddenException" -> ForbiddenExceptionDeserializer().deserialize(context, wrappedResponse)
"GatewayTimeoutException" -> GatewayTimeoutExceptionDeserializer().deserialize(context, wrappedResponse)
"InternalServerErrorException" -> InternalServerErrorExceptionDeserializer().deserialize(context, wrappedResponse)
"NotFoundException" -> NotFoundExceptionDeserializer().deserialize(context, wrappedResponse)
"TooManyRequestsException" -> TooManyRequestsExceptionDeserializer().deserialize(context, wrappedResponse)
else -> MediaLiveException(errorDetails.message)
}
setAseErrorMetadata(ex, wrappedResponse, errorDetails)
throw ex
}
private fun deserializeDescribeOfferingOperationBody(builder: DescribeOfferingResponse.Builder, payload: ByteArray) {
val deserializer = JsonDeserializer(payload)
val ARN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("arn"))
val CURRENCYCODE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("currencyCode"))
val DURATION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Integer, JsonSerialName("duration"))
val DURATIONUNITS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("durationUnits"))
val FIXEDPRICE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Double, JsonSerialName("fixedPrice"))
val OFFERINGDESCRIPTION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("offeringDescription"))
val OFFERINGID_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("offeringId"))
val OFFERINGTYPE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Enum, JsonSerialName("offeringType"))
val REGION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("region"))
val RESOURCESPECIFICATION_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, JsonSerialName("resourceSpecification"))
val USAGEPRICE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Double, JsonSerialName("usagePrice"))
val OBJ_DESCRIPTOR = SdkObjectDescriptor.build {
field(ARN_DESCRIPTOR)
field(CURRENCYCODE_DESCRIPTOR)
field(DURATION_DESCRIPTOR)
field(DURATIONUNITS_DESCRIPTOR)
field(FIXEDPRICE_DESCRIPTOR)
field(OFFERINGDESCRIPTION_DESCRIPTOR)
field(OFFERINGID_DESCRIPTOR)
field(OFFERINGTYPE_DESCRIPTOR)
field(REGION_DESCRIPTOR)
field(RESOURCESPECIFICATION_DESCRIPTOR)
field(USAGEPRICE_DESCRIPTOR)
}
deserializer.deserializeStruct(OBJ_DESCRIPTOR) {
loop@while (true) {
when (findNextFieldIndex()) {
ARN_DESCRIPTOR.index -> builder.arn = deserializeString()
CURRENCYCODE_DESCRIPTOR.index -> builder.currencyCode = deserializeString()
DURATION_DESCRIPTOR.index -> builder.duration = deserializeInt()
DURATIONUNITS_DESCRIPTOR.index -> builder.durationUnits = deserializeString().let { OfferingDurationUnits.fromValue(it) }
FIXEDPRICE_DESCRIPTOR.index -> builder.fixedPrice = deserializeDouble()
OFFERINGDESCRIPTION_DESCRIPTOR.index -> builder.offeringDescription = deserializeString()
OFFERINGID_DESCRIPTOR.index -> builder.offeringId = deserializeString()
OFFERINGTYPE_DESCRIPTOR.index -> builder.offeringType = deserializeString().let { OfferingType.fromValue(it) }
REGION_DESCRIPTOR.index -> builder.region = deserializeString()
RESOURCESPECIFICATION_DESCRIPTOR.index -> builder.resourceSpecification = deserializeReservationResourceSpecificationDocument(deserializer)
USAGEPRICE_DESCRIPTOR.index -> builder.usagePrice = deserializeDouble()
null -> break@loop
else -> skipValue()
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy