commonMain.aws.sdk.kotlin.services.connect.transform.GetCurrentMetricDataOperationDeserializer.kt Maven / Gradle / Ivy
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!
package aws.sdk.kotlin.services.connect.transform
import aws.sdk.kotlin.services.connect.model.ConnectException
import aws.sdk.kotlin.services.connect.model.CurrentMetricResult
import aws.sdk.kotlin.services.connect.model.GetCurrentMetricDataResponse
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
import aws.smithy.kotlin.runtime.time.Instant
import kotlin.collections.mutableListOf
internal class GetCurrentMetricDataOperationDeserializer: HttpDeserialize {
override suspend fun deserialize(context: ExecutionContext, response: HttpResponse): GetCurrentMetricDataResponse {
if (!response.status.isSuccess()) {
throwGetCurrentMetricDataError(context, response)
}
val builder = GetCurrentMetricDataResponse.Builder()
val payload = response.body.readAll()
if (payload != null) {
deserializeGetCurrentMetricDataOperationBody(builder, payload)
}
return builder.build()
}
}
private suspend fun throwGetCurrentMetricDataError(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 ConnectException("Failed to parse response as 'restJson1' error", ex).also {
setAseErrorMetadata(it, wrappedResponse, null)
}
}
val ex = when(errorDetails.code) {
"InternalServiceException" -> InternalServiceExceptionDeserializer().deserialize(context, wrappedResponse)
"InvalidParameterException" -> InvalidParameterExceptionDeserializer().deserialize(context, wrappedResponse)
"InvalidRequestException" -> InvalidRequestExceptionDeserializer().deserialize(context, wrappedResponse)
"ResourceNotFoundException" -> ResourceNotFoundExceptionDeserializer().deserialize(context, wrappedResponse)
"ThrottlingException" -> ThrottlingExceptionDeserializer().deserialize(context, wrappedResponse)
else -> ConnectException(errorDetails.message)
}
setAseErrorMetadata(ex, wrappedResponse, errorDetails)
throw ex
}
private fun deserializeGetCurrentMetricDataOperationBody(builder: GetCurrentMetricDataResponse.Builder, payload: ByteArray) {
val deserializer = JsonDeserializer(payload)
val APPROXIMATETOTALCOUNT_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Long, JsonSerialName("ApproximateTotalCount"))
val DATASNAPSHOTTIME_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Timestamp, JsonSerialName("DataSnapshotTime"))
val METRICRESULTS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.List, JsonSerialName("MetricResults"))
val NEXTTOKEN_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("NextToken"))
val OBJ_DESCRIPTOR = SdkObjectDescriptor.build {
field(APPROXIMATETOTALCOUNT_DESCRIPTOR)
field(DATASNAPSHOTTIME_DESCRIPTOR)
field(METRICRESULTS_DESCRIPTOR)
field(NEXTTOKEN_DESCRIPTOR)
}
deserializer.deserializeStruct(OBJ_DESCRIPTOR) {
loop@while (true) {
when (findNextFieldIndex()) {
APPROXIMATETOTALCOUNT_DESCRIPTOR.index -> builder.approximateTotalCount = deserializeLong()
DATASNAPSHOTTIME_DESCRIPTOR.index -> builder.dataSnapshotTime = deserializeString().let { Instant.fromEpochSeconds(it) }
METRICRESULTS_DESCRIPTOR.index -> builder.metricResults =
deserializer.deserializeList(METRICRESULTS_DESCRIPTOR) {
val col0 = mutableListOf()
while (hasNextElement()) {
val el0 = if (nextHasValue()) { deserializeCurrentMetricResultDocument(deserializer) } else { deserializeNull(); continue }
col0.add(el0)
}
col0
}
NEXTTOKEN_DESCRIPTOR.index -> builder.nextToken = deserializeString()
null -> break@loop
else -> skipValue()
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy