commonMain.aws.sdk.kotlin.services.route53.serde.TestDNSAnswerOperationDeserializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of route53-jvm Show documentation
Show all versions of route53-jvm Show documentation
The AWS SDK for Kotlin client for Route 53
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!
package aws.sdk.kotlin.services.route53.serde
import aws.sdk.kotlin.services.route53.model.Route53Exception
import aws.sdk.kotlin.services.route53.model.RrType
import aws.sdk.kotlin.services.route53.model.TestDnsAnswerResponse
import aws.smithy.kotlin.runtime.awsprotocol.setAseErrorMetadata
import aws.smithy.kotlin.runtime.awsprotocol.withPayload
import aws.smithy.kotlin.runtime.awsprotocol.xml.parseRestXmlErrorResponseNoSuspend
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.getOrDeserializeErr
import aws.smithy.kotlin.runtime.serde.parse
import aws.smithy.kotlin.runtime.serde.xml.tryData
import aws.smithy.kotlin.runtime.serde.xml.xmlTagReader
internal class TestDNSAnswerOperationDeserializer: HttpDeserializer.NonStreaming {
override fun deserialize(context: ExecutionContext, call: HttpCall, payload: ByteArray?): TestDnsAnswerResponse {
val response = call.response
if (!response.status.isSuccess()) {
throwTestDnsAnswerError(context, call, payload)
}
val builder = TestDnsAnswerResponse.Builder()
if (payload != null) {
deserializeTestDNSAnswerOperationBody(builder, payload)
}
builder.correctErrors()
return builder.build()
}
}
private fun throwTestDnsAnswerError(context: ExecutionContext, call: HttpCall, payload: ByteArray?): kotlin.Nothing {
val wrappedResponse = call.response.withPayload(payload)
val wrappedCall = call.copy(response = wrappedResponse)
val errorDetails = try {
checkNotNull(payload){ "unable to parse error from empty response" }
parseRestXmlErrorResponseNoSuspend(payload)
} catch (ex: Exception) {
throw Route53Exception("Failed to parse response as 'restXml' error", ex).also {
setAseErrorMetadata(it, wrappedCall.response, null)
}
}
val ex = when(errorDetails.code) {
"InvalidInput" -> InvalidInputDeserializer().deserialize(context, wrappedCall, payload)
"NoSuchHostedZone" -> NoSuchHostedZoneDeserializer().deserialize(context, wrappedCall, payload)
else -> Route53Exception(errorDetails.message)
}
setAseErrorMetadata(ex, wrappedResponse, errorDetails)
throw ex
}
private fun deserializeTestDNSAnswerOperationBody(builder: TestDnsAnswerResponse.Builder, payload: ByteArray) {
val root = xmlTagReader(payload)
loop@while (true) {
val curr = root.nextTag() ?: break@loop
when (curr.tagName) {
// Nameserver com.amazonaws.route53#TestDNSAnswerResponse$Nameserver
"Nameserver" -> builder.nameserver = curr.tryData()
.getOrDeserializeErr { "expected (string: `com.amazonaws.route53#Nameserver`)" }
// Protocol com.amazonaws.route53#TestDNSAnswerResponse$Protocol
"Protocol" -> builder.protocol = curr.tryData()
.getOrDeserializeErr { "expected (string: `com.amazonaws.route53#TransportProtocol`)" }
// RecordData com.amazonaws.route53#TestDNSAnswerResponse$RecordData
"RecordData" -> builder.recordData = deserializeRecordDataShape(curr)
// RecordName com.amazonaws.route53#TestDNSAnswerResponse$RecordName
"RecordName" -> builder.recordName = curr.tryData()
.getOrDeserializeErr { "expected (string: `com.amazonaws.route53#DNSName`)" }
// RecordType com.amazonaws.route53#TestDNSAnswerResponse$RecordType
"RecordType" -> builder.recordType = curr.tryData()
.parse { RrType.fromValue(it) }
.getOrDeserializeErr { "expected (enum: `com.amazonaws.route53#RRType`)" }
// ResponseCode com.amazonaws.route53#TestDNSAnswerResponse$ResponseCode
"ResponseCode" -> builder.responseCode = curr.tryData()
.getOrDeserializeErr { "expected (string: `com.amazonaws.route53#DNSRCode`)" }
else -> {}
}
curr.drop()
}
}