-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Xml Shape Serializer - Schema serde #3855
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
base: main
Are you sure you want to change the base?
Changes from all commits
c2b364a
d95ac61
bdb15ac
ca248df
e488b57
774dcb6
4524ff2
3b01877
3758abe
5a4437f
cbf16ed
1d59efc
951c3de
b14f0b1
941821f
ef07e8d
24c99c9
865c6bc
0572359
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /** | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include <aws/core/utils/memory/stl/AWSString.h> | ||
| #include <smithy/client/schema/Trait.h> | ||
| #include <smithy/client/schema/TraitKey.h> | ||
|
|
||
| namespace smithy { | ||
| namespace schema { | ||
|
|
||
| class JsonNameTrait : public Trait { | ||
| public: | ||
| explicit JsonNameTrait(const Aws::String& value) : m_value(value) {} | ||
| const Aws::String& GetValue() const { return m_value; } | ||
| static const TraitKey<JsonNameTrait>& KEY() { return TraitKey<JsonNameTrait>::Instance(); } | ||
|
|
||
| private: | ||
| Aws::String m_value; | ||
| }; | ||
|
|
||
| } // namespace schema | ||
| } // namespace smithy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /** | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include <smithy/client/schema/Trait.h> | ||
| #include <smithy/client/schema/TraitKey.h> | ||
|
|
||
| namespace smithy { | ||
| namespace schema { | ||
|
|
||
| class TimestampFormatTrait : public Trait { | ||
| public: | ||
| enum class Format { DATE_TIME, HTTP_DATE, EPOCH_SECONDS }; | ||
|
|
||
| explicit TimestampFormatTrait(Format format) : m_format(format) {} | ||
| Format GetFormat() const { return m_format; } | ||
| static const TraitKey<TimestampFormatTrait>& KEY() { return TraitKey<TimestampFormatTrait>::Instance(); } | ||
|
|
||
| private: | ||
| Format m_format; | ||
| }; | ||
|
|
||
| } // namespace schema | ||
| } // namespace smithy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #pragma once | ||
|
|
||
| #include <smithy/Smithy_EXPORTS.h> | ||
|
|
||
| namespace smithy { | ||
| namespace schema { | ||
| class SMITHY_API Trait { | ||
| public: | ||
| virtual ~Trait() = default; | ||
| }; | ||
| } // namespace schema | ||
| } // namespace smithy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #pragma once | ||
|
|
||
| #include <smithy/Smithy_EXPORTS.h> | ||
|
|
||
| namespace smithy { | ||
| namespace schema { | ||
| class SMITHY_API TraitKeyBase { | ||
| public: | ||
| int GetId() const { return m_id; } | ||
|
|
||
| protected: | ||
| explicit TraitKeyBase(int id) : m_id(id) {} | ||
|
|
||
| private: | ||
| int m_id; | ||
| }; | ||
|
|
||
| SMITHY_API int NextTraitKey(); | ||
|
|
||
| template <typename T> | ||
| class TraitKey : public TraitKeyBase { | ||
| public: | ||
| static const TraitKey& Instance() { | ||
| static const TraitKey instance(NextTraitKey()); | ||
|
sbiscigl marked this conversation as resolved.
|
||
| return instance; | ||
| } | ||
|
|
||
| private: | ||
| explicit TraitKey(int id) : TraitKeyBase(id) {} | ||
| }; | ||
| } // namespace schema | ||
| } // namespace smithy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #pragma once | ||
|
|
||
| #include <aws/core/utils/memory/stl/AWSVector.h> | ||
| #include <smithy/Smithy_EXPORTS.h> | ||
| #include <smithy/client/schema/Trait.h> | ||
| #include <smithy/client/schema/TraitKey.h> | ||
|
|
||
| namespace smithy { | ||
| namespace schema { | ||
| class SMITHY_API TraitMap { | ||
| public: | ||
| TraitMap() = default; | ||
|
|
||
| template <typename T> | ||
| const T* Get(const TraitKey<T>& key) const { | ||
|
sbiscigl marked this conversation as resolved.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets return by value and copy or shared pointer if we want to share lifetimes, raw pointer or ref will create lifetime issues |
||
| int idx = key.GetId(); | ||
| if (idx >= static_cast<int>(m_value.size())) return nullptr; | ||
| return static_cast<const T*>(m_value[idx]); | ||
| } | ||
|
|
||
| bool Has(const TraitKeyBase& key) const { | ||
| int idx = key.GetId(); | ||
| if (idx >= static_cast<int>(m_value.size())) return false; | ||
| return m_value[idx] != nullptr; | ||
| } | ||
|
|
||
| void Set(const TraitKeyBase& key, const Trait* trait) { | ||
| int idx = key.GetId(); | ||
| if (idx >= static_cast<int>(m_value.size())) { | ||
| m_value.resize(idx + 1, nullptr); | ||
| } | ||
| m_value[idx] = trait; | ||
| } | ||
|
|
||
| private: | ||
| Aws::Vector<const Trait*> m_value; | ||
| }; | ||
| } // namespace schema | ||
| } // namespace smithy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /** | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include <aws/core/utils/memory/stl/AWSString.h> | ||
| #include <smithy/client/schema/Trait.h> | ||
| #include <smithy/client/schema/TraitKey.h> | ||
|
|
||
| namespace smithy { | ||
| namespace schema { | ||
|
|
||
| class XmlNameTrait : public Trait { | ||
| public: | ||
| explicit XmlNameTrait(const Aws::String& value) : m_value(value) {} | ||
| const Aws::String& GetValue() const { return m_value; } | ||
| static const TraitKey<XmlNameTrait>& KEY() { return TraitKey<XmlNameTrait>::Instance(); } | ||
|
|
||
| private: | ||
| Aws::String m_value; | ||
| }; | ||
|
|
||
| class XmlFlattenedTrait : public Trait { | ||
| public: | ||
| static const TraitKey<XmlFlattenedTrait>& KEY() { return TraitKey<XmlFlattenedTrait>::Instance(); } | ||
| }; | ||
|
|
||
| class XmlAttributeTrait : public Trait { | ||
| public: | ||
| static const TraitKey<XmlAttributeTrait>& KEY() { return TraitKey<XmlAttributeTrait>::Instance(); } | ||
| }; | ||
|
|
||
| class XmlNamespaceTrait : public Trait { | ||
| public: | ||
| XmlNamespaceTrait(const Aws::String& uri, const Aws::String& prefix = "") : m_uri(uri), m_prefix(prefix) {} | ||
| const Aws::String& GetUri() const { return m_uri; } | ||
| const Aws::String& GetPrefix() const { return m_prefix; } | ||
| static const TraitKey<XmlNamespaceTrait>& KEY() { return TraitKey<XmlNamespaceTrait>::Instance(); } | ||
|
|
||
| private: | ||
| Aws::String m_uri; | ||
| Aws::String m_prefix; | ||
| }; | ||
|
|
||
| class XmlListItemNameTrait : public Trait { | ||
| public: | ||
| explicit XmlListItemNameTrait(const Aws::String& value) : m_value(value) {} | ||
| const Aws::String& GetValue() const { return m_value; } | ||
| static const TraitKey<XmlListItemNameTrait>& KEY() { return TraitKey<XmlListItemNameTrait>::Instance(); } | ||
|
|
||
| private: | ||
| Aws::String m_value; | ||
| }; | ||
|
|
||
| class XmlMapEntryNameTrait : public Trait { | ||
| public: | ||
| explicit XmlMapEntryNameTrait(const Aws::String& value) : m_value(value) {} | ||
| const Aws::String& GetValue() const { return m_value; } | ||
| static const TraitKey<XmlMapEntryNameTrait>& KEY() { return TraitKey<XmlMapEntryNameTrait>::Instance(); } | ||
|
|
||
| private: | ||
| Aws::String m_value; | ||
| }; | ||
|
|
||
| class XmlMapKeyNameTrait : public Trait { | ||
| public: | ||
| explicit XmlMapKeyNameTrait(const Aws::String& value) : m_value(value) {} | ||
| const Aws::String& GetValue() const { return m_value; } | ||
| static const TraitKey<XmlMapKeyNameTrait>& KEY() { return TraitKey<XmlMapKeyNameTrait>::Instance(); } | ||
|
|
||
| private: | ||
| Aws::String m_value; | ||
| }; | ||
|
|
||
| class XmlMapValueNameTrait : public Trait { | ||
| public: | ||
| explicit XmlMapValueNameTrait(const Aws::String& value) : m_value(value) {} | ||
| const Aws::String& GetValue() const { return m_value; } | ||
| static const TraitKey<XmlMapValueNameTrait>& KEY() { return TraitKey<XmlMapValueNameTrait>::Instance(); } | ||
|
|
||
| private: | ||
| Aws::String m_value; | ||
| }; | ||
|
|
||
| } // namespace schema | ||
| } // namespace smithy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #include <smithy/client/schema/TraitKey.h> | ||
|
|
||
| namespace smithy { | ||
| namespace schema { | ||
|
|
||
| static int s_traitIdCounter = 0; | ||
|
sbiscigl marked this conversation as resolved.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be std::atomic to match how java does it |
||
|
|
||
| int NextTraitKey() { return s_traitIdCounter++; } | ||
| } // namespace schema | ||
| } // namespace smithy | ||
Uh oh!
There was an error while loading. Please reload this page.