-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor smithy-json and fix several protocol tests for the new JsonS…
…erializerGenerator (#418) * Split out a JsonValueWriter from JsonObjectWriter/JsonArrayWriter * Add document support to JsonSerializerGenerator * Add operation support to JsonSerializerGenerator * Fix some bugs found by protocol tests * Fix struct serializer function naming bug * Fix handling of sparse lists and maps * CR feedback
- Loading branch information
Showing
7 changed files
with
451 additions
and
392 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
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
36 changes: 36 additions & 0 deletions
36
...c/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/InlineFunctionNamer.kt
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,36 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
|
||
package software.amazon.smithy.rust.codegen.smithy.protocols | ||
|
||
import software.amazon.smithy.model.shapes.MemberShape | ||
import software.amazon.smithy.model.shapes.OperationShape | ||
import software.amazon.smithy.model.shapes.Shape | ||
import software.amazon.smithy.model.shapes.StructureShape | ||
import software.amazon.smithy.model.shapes.UnionShape | ||
import software.amazon.smithy.rust.codegen.smithy.RustSymbolProvider | ||
import software.amazon.smithy.rust.codegen.util.toSnakeCase | ||
|
||
/** | ||
* Creates a unique name for a serialization function. | ||
* | ||
* The prefixes will look like the following (for grep): | ||
* - serialize_operation | ||
* - serialize_structure | ||
* - serialize_union | ||
* - serialize_payload | ||
*/ | ||
fun RustSymbolProvider.serializeFunctionName(shape: Shape): String = shapeFunctionName("serialize", shape) | ||
|
||
private fun RustSymbolProvider.shapeFunctionName(prefix: String, shape: Shape): String { | ||
val symbolNameSnakeCase = toSymbol(shape).name.toSnakeCase() | ||
return prefix + "_" + when (shape) { | ||
is OperationShape -> "operation_$symbolNameSnakeCase" | ||
is StructureShape -> "structure_$symbolNameSnakeCase" | ||
is UnionShape -> "union_$symbolNameSnakeCase" | ||
is MemberShape -> "payload_${shape.target.name.toSnakeCase()}_${shape.container.name.toSnakeCase()}" | ||
else -> TODO("SerializerFunctionNamer.name: $shape") | ||
} | ||
} |
325 changes: 172 additions & 153 deletions
325
...n/software/amazon/smithy/rust/codegen/smithy/protocols/parsers/JsonSerializerGenerator.kt
Large diffs are not rendered by default.
Oops, something went wrong.
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
Oops, something went wrong.