-
Notifications
You must be signed in to change notification settings - Fork 656
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rpc2cbor: sdk protocol generator extension
- Loading branch information
Showing
90 changed files
with
16,042 additions
and
7,477 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"id": "41575353-444b-40ff-bf47-4f4155544f00", | ||
"type": "release", | ||
"description": "New AWS service client module", | ||
"modules": [ | ||
"internal/protocoltest/smithyrpcv2cbor" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...ain/java/software/amazon/smithy/aws/go/codegen/protocol/AwsRpc2CborProtocolGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.smithy.aws.go.codegen.protocol; | ||
|
||
import static software.amazon.smithy.go.codegen.protocol.ProtocolUtil.hasEventStream; | ||
|
||
import software.amazon.smithy.aws.go.codegen.AwsEventStreamUtils; | ||
import software.amazon.smithy.aws.go.codegen.AwsFnProvider; | ||
import software.amazon.smithy.aws.go.codegen.AwsProtocolUtils; | ||
import software.amazon.smithy.go.codegen.GoWriter; | ||
import software.amazon.smithy.go.codegen.endpoints.EndpointResolutionGenerator; | ||
import software.amazon.smithy.go.codegen.protocol.rpc2.cbor.Rpc2CborProtocolGenerator; | ||
import software.amazon.smithy.model.knowledge.TopDownIndex; | ||
|
||
/** | ||
* Extension of the smithy-borne Rpc2CborProtocolGenerator to do protocol tests and event streams since that's currently | ||
* a 2000+ line dumpster fire in this repo. | ||
*/ | ||
public final class AwsRpc2CborProtocolGenerator extends Rpc2CborProtocolGenerator { | ||
@Override | ||
public void generateProtocolTests(GenerationContext context) { | ||
AwsProtocolUtils.generateHttpProtocolTests(context); | ||
} | ||
|
||
@Override | ||
public void generateEventStreamComponents(GenerationContext context) { | ||
// This automagically wires up ALL the framing logic for both directions of streams. All we have to do is fill | ||
// in the serde elsewhere (it's different signatures than normal request/response), see: | ||
// * CborEventStreamSerializer | ||
// * CborEventStreamDeserializer | ||
AwsEventStreamUtils.generateEventStreamComponents(context); | ||
} | ||
|
||
@Override | ||
public void generateEndpointResolution(GenerationContext context) { | ||
new EndpointResolutionGenerator(new AwsFnProvider()).generate(context); | ||
} | ||
|
||
@Override | ||
public void generateSharedSerializerComponents(GenerationContext ctx) { | ||
super.generateSharedSerializerComponents(ctx); | ||
|
||
var model = ctx.getModel(); | ||
var streamSerializers = TopDownIndex.of(model).getContainedOperations(ctx.getService()).stream() | ||
.filter(it -> hasEventStream(model, model.expectShape(it.getOutputShape()))) | ||
.map(it -> (GoWriter.Writable) new CborEventStreamSerializer(ctx, it)) | ||
.toList(); | ||
ctx.getWriter().get().write(GoWriter.ChainWritable.of(streamSerializers).compose()); | ||
} | ||
|
||
@Override | ||
public void generateSharedDeserializerComponents(GenerationContext ctx) { | ||
super.generateSharedDeserializerComponents(ctx); | ||
|
||
var model = ctx.getModel(); | ||
var streamDeserializers = TopDownIndex.of(model).getContainedOperations(ctx.getService()).stream() | ||
.filter(it -> hasEventStream(model, model.expectShape(it.getOutputShape()))) | ||
.map(it -> (GoWriter.Writable) new CborEventStreamDeserializer(ctx, it)) | ||
.toList(); | ||
ctx.getWriter().get().write(GoWriter.ChainWritable.of(streamDeserializers).compose()); | ||
} | ||
} |
Oops, something went wrong.