diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerProtocolLoader.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerProtocolLoader.kt index 1f3cabcb9b124f4bdf699d46127a0cef8df06e9e..ebbd163b66811d9e34f0561e64e971ed64076d60 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerProtocolLoader.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerProtocolLoader.kt @@ -9,35 +9,13 @@ import software.amazon.smithy.aws.traits.protocols.AwsJson1_0Trait import software.amazon.smithy.aws.traits.protocols.AwsJson1_1Trait import software.amazon.smithy.aws.traits.protocols.RestJson1Trait import software.amazon.smithy.aws.traits.protocols.RestXmlTrait -import software.amazon.smithy.codegen.core.CodegenException -import software.amazon.smithy.model.Model -import software.amazon.smithy.model.knowledge.ServiceIndex -import software.amazon.smithy.model.shapes.ServiceShape -import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.model.traits.Trait import software.amazon.smithy.rust.codegen.smithy.ServerCodegenContext -import software.amazon.smithy.rust.codegen.smithy.generators.protocol.ProtocolGenerator import software.amazon.smithy.rust.codegen.smithy.protocols.AwsJsonVersion -import software.amazon.smithy.rust.codegen.smithy.protocols.ProtocolGeneratorFactory +import software.amazon.smithy.rust.codegen.smithy.protocols.ProtocolLoader import software.amazon.smithy.rust.codegen.smithy.protocols.ProtocolMap -/* - * Protocol dispatcher, responsible for protocol selection. - */ -class ServerProtocolLoader(private val supportedProtocols: ProtocolMap) { - fun protocolFor( - model: Model, - serviceShape: ServiceShape, - ): Pair> { - val protocols: MutableMap = ServiceIndex.of(model).getProtocols(serviceShape) - val matchingProtocols = - protocols.keys.mapNotNull { protocolId -> supportedProtocols[protocolId]?.let { protocolId to it } } - if (matchingProtocols.isEmpty()) { - throw CodegenException("No matching protocol — service offers: ${protocols.keys}. We offer: ${supportedProtocols.keys}") - } - val pair = matchingProtocols.first() - return Pair(pair.first, pair.second) - } +class ServerProtocolLoader(supportedProtocols: ProtocolMap) : + ProtocolLoader(supportedProtocols) { companion object { val DefaultProtocols = mapOf( diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/Protocol.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/Protocol.kt index 10537993c84a98bf7d9b5096beac72a9ba4041f0..63a8569f383c968ab05c6000563ef5cd4e7367ca 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/Protocol.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/Protocol.kt @@ -100,7 +100,7 @@ interface ProtocolGeneratorFactory(private val supportedProtocols: ProtocolMap) { +open class ProtocolLoader(private val supportedProtocols: ProtocolMap) { fun protocolFor( model: Model, serviceShape: ServiceShape,