-
Notifications
You must be signed in to change notification settings - Fork 1.2k
splitting Schema into a base class with a builder and factories #3895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
74 changes: 74 additions & 0 deletions
74
src/aws-cpp-sdk-core/include/smithy/client/schema/InterceptingSerializer.h
This file contains hidden or 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,74 @@ | ||
| #pragma once | ||
|
|
||
| #include <smithy/Smithy_EXPORTS.h> | ||
| #include <smithy/client/schema/ShapeSerializer.h> | ||
|
|
||
| #include <functional> | ||
|
|
||
| namespace smithy { | ||
| namespace schema { | ||
|
|
||
| // Routes each write through Before()/After(). Before() returns the serializer | ||
| // that performs the write; After() runs once it returns. | ||
| class SMITHY_API InterceptingSerializer : public ShapeSerializer { | ||
| public: | ||
| void WriteStruct(const Schema& schema, const SerializableStruct& value) override { | ||
| Before(schema).WriteStruct(schema, value); | ||
| After(schema); | ||
| } | ||
| void WriteList(const Schema& schema, size_t size, const std::function<void(ShapeSerializer&)>& consumer) override { | ||
| Before(schema).WriteList(schema, size, consumer); | ||
| After(schema); | ||
| } | ||
| void WriteMap(const Schema& schema, size_t size, const std::function<void(MapSerializer&)>& consumer) override { | ||
| Before(schema).WriteMap(schema, size, consumer); | ||
| After(schema); | ||
| } | ||
| void WriteBoolean(const Schema& schema, bool value) override { | ||
| Before(schema).WriteBoolean(schema, value); | ||
| After(schema); | ||
| } | ||
| void WriteInteger(const Schema& schema, int value) override { | ||
| Before(schema).WriteInteger(schema, value); | ||
| After(schema); | ||
| } | ||
| void WriteLong(const Schema& schema, int64_t value) override { | ||
| Before(schema).WriteLong(schema, value); | ||
| After(schema); | ||
| } | ||
| void WriteFloat(const Schema& schema, float value) override { | ||
| Before(schema).WriteFloat(schema, value); | ||
| After(schema); | ||
| } | ||
| void WriteDouble(const Schema& schema, double value) override { | ||
| Before(schema).WriteDouble(schema, value); | ||
| After(schema); | ||
| } | ||
| void WriteString(const Schema& schema, const Aws::String& value) override { | ||
| Before(schema).WriteString(schema, value); | ||
| After(schema); | ||
| } | ||
| void WriteTimestamp(const Schema& schema, const Aws::Utils::DateTime& value) override { | ||
| Before(schema).WriteTimestamp(schema, value); | ||
| After(schema); | ||
| } | ||
| void WriteBlob(const Schema& schema, const Aws::Utils::ByteBuffer& value) override { | ||
| Before(schema).WriteBlob(schema, value); | ||
| After(schema); | ||
| } | ||
| void WriteEnum(const Schema& schema, int value) override { | ||
| Before(schema).WriteEnum(schema, value); | ||
| After(schema); | ||
| } | ||
| void WriteNull(const Schema& schema) override { | ||
| Before(schema).WriteNull(schema); | ||
| After(schema); | ||
| } | ||
|
|
||
| protected: | ||
| virtual ShapeSerializer& Before(const Schema& schema) = 0; | ||
| virtual void After(const Schema& /*schema*/) {} | ||
| }; | ||
|
|
||
| } // namespace schema | ||
| } // namespace smithy |
This file contains hidden or 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
22 changes: 22 additions & 0 deletions
22
src/aws-cpp-sdk-core/include/smithy/client/schema/MapSerializer.h
This file contains hidden or 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,22 @@ | ||
| #pragma once | ||
|
|
||
| #include <aws/core/utils/memory/stl/AWSString.h> | ||
| #include <smithy/Smithy_EXPORTS.h> | ||
|
|
||
| #include <functional> | ||
|
|
||
| namespace smithy { | ||
| namespace schema { | ||
|
|
||
| class ShapeSerializer; | ||
|
|
||
| // Handed to the WriteMap consumer; writes each entry's key then its value. | ||
| class SMITHY_API MapSerializer { | ||
| public: | ||
| virtual ~MapSerializer() = default; | ||
|
|
||
| virtual void WriteEntry(const Aws::String& key, const std::function<void(ShapeSerializer&)>& value) = 0; | ||
| }; | ||
|
|
||
| } // namespace schema | ||
| } // namespace smithy |
This file contains hidden or 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
38 changes: 38 additions & 0 deletions
38
src/aws-cpp-sdk-core/include/smithy/client/schema/SchemaBuilder.h
This file contains hidden or 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,38 @@ | ||
| #pragma once | ||
|
|
||
| #include <aws/core/utils/memory/AWSMemory.h> | ||
| #include <smithy/Smithy_EXPORTS.h> | ||
| #include <smithy/client/schema/Schema.h> | ||
|
|
||
| #include <memory> | ||
|
|
||
| namespace smithy { | ||
| namespace schema { | ||
|
|
||
| // Assembles a shape that carries members (structure, union, list, map). Move-only; | ||
| // obtained from Schema::StructureBuilder and friends. | ||
| class SMITHY_API SchemaBuilder final { | ||
| public: | ||
| ~SchemaBuilder(); | ||
| SchemaBuilder(SchemaBuilder&&) noexcept; | ||
| SchemaBuilder& operator=(SchemaBuilder&&) noexcept; | ||
|
|
||
| SchemaBuilder& PutMember(const char* name, std::shared_ptr<const Schema> target, TraitList traits = {}); | ||
| SchemaBuilder& PutMember(const char* name, SchemaBuilder& target, TraitList traits = {}); | ||
|
|
||
| std::shared_ptr<const Schema> Build(); | ||
|
|
||
| private: | ||
| friend class Schema; | ||
| class SchemaBuilderImpl; | ||
|
|
||
| explicit SchemaBuilder(Aws::UniquePtr<SchemaBuilderImpl> impl); | ||
|
|
||
| Aws::UniquePtr<SchemaBuilderImpl> m_impl; | ||
|
|
||
| SchemaBuilder(const SchemaBuilder&) = delete; | ||
| SchemaBuilder& operator=(const SchemaBuilder&) = delete; | ||
| }; | ||
|
|
||
| } // namespace schema | ||
| } // namespace smithy | ||
22 changes: 22 additions & 0 deletions
22
src/aws-cpp-sdk-core/include/smithy/client/schema/SerializableStruct.h
This file contains hidden or 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,22 @@ | ||
| #pragma once | ||
|
|
||
| #include <smithy/Smithy_EXPORTS.h> | ||
| #include <smithy/client/schema/Schema.h> | ||
|
|
||
| namespace smithy { | ||
| namespace schema { | ||
|
|
||
| class ShapeSerializer; | ||
|
|
||
| // Implemented by generated shapes: knows its Schema and how to write its members | ||
| // to whichever ShapeSerializer is passed in. | ||
| class SMITHY_API SerializableStruct { | ||
| public: | ||
| virtual ~SerializableStruct() = default; | ||
|
|
||
| virtual const Schema& GetSchema() const = 0; | ||
| virtual void SerializeMembers(ShapeSerializer& serializer) const = 0; | ||
| }; | ||
|
|
||
| } // namespace schema | ||
| } // namespace smithy |
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.