From 61452120f61a8120fe36763f16bb235e4e48f791 Mon Sep 17 00:00:00 2001 From: pulimsr Date: Tue, 2 Jun 2026 10:32:53 -0400 Subject: [PATCH 1/2] headers for protocol shapes --- .../client/schema/CborShapeSerializer.h | 43 +++++++++++ .../client/schema/JsonShapeSerializer.h | 55 ++++++++++++++ .../client/schema/QueryShapeSerializer.h | 48 ++++++++++++ .../include/smithy/client/schema/Schema.h | 74 +++++++++++++++++++ .../smithy/client/schema/ShapeSerializer.h | 46 ++++++++++++ .../smithy/client/schema/XmlShapeSerializer.h | 51 +++++++++++++ .../client/schema/JsonShapeSerializer.cpp | 3 + 7 files changed, 320 insertions(+) create mode 100644 src/aws-cpp-sdk-core/include/smithy/client/schema/CborShapeSerializer.h create mode 100644 src/aws-cpp-sdk-core/include/smithy/client/schema/JsonShapeSerializer.h create mode 100644 src/aws-cpp-sdk-core/include/smithy/client/schema/QueryShapeSerializer.h create mode 100644 src/aws-cpp-sdk-core/include/smithy/client/schema/Schema.h create mode 100644 src/aws-cpp-sdk-core/include/smithy/client/schema/ShapeSerializer.h create mode 100644 src/aws-cpp-sdk-core/include/smithy/client/schema/XmlShapeSerializer.h create mode 100644 src/aws-cpp-sdk-core/source/smithy/client/schema/JsonShapeSerializer.cpp diff --git a/src/aws-cpp-sdk-core/include/smithy/client/schema/CborShapeSerializer.h b/src/aws-cpp-sdk-core/include/smithy/client/schema/CborShapeSerializer.h new file mode 100644 index 00000000000..43ea13505dd --- /dev/null +++ b/src/aws-cpp-sdk-core/include/smithy/client/schema/CborShapeSerializer.h @@ -0,0 +1,43 @@ +#pragma once + +#include +#include + +namespace smithy { + namespace schema { + class AWS_CORE_API CborShapeSerializer : public ShapeSerializer { + public: + CborShapeSerializer() = default; + + void BeginStructure(const Schema& schema) override; + void EndStructure() override; + + void WriteBoolean(const FieldSchema& field, bool value) override; + void WriteInteger(const FieldSchema& field, int value) override; + void WriteLong(const FieldSchema& field, int64_t value) override; + void WriteDouble(const FieldSchema& field, double value) override; + void WriteString(const FieldSchema& field, const Aws::String& value) override; + void WriteTimestamp(const FieldSchema& field, const Aws::Utils::DateTime& value) override; + void WriteBlob(const FieldSchema& field, const Aws::Utils::ByteBuffer& value) override; + void WriteEnum(const FieldSchema& field, int value) override; + void WriteNull(const FieldSchema& field) override; + + void BeginList(const FieldSchema& field, size_t count) override; + void EndList() override; + + void BeginMap(const FieldSchema& field,size_t count) override; + void WriteMapKey(const Aws::String& key) override; + void EndMap() override; + + void BeginNestedStructure(const FieldSchema& field) override; + void EndNestedStructure() override; + + Aws::String GetPayload() const; + private: + void WriteKey(const chat* key); + + Aws::Crt::Cbor::CborEncoder m_encoder; + size_t m_structFieldCount = 0; + }; + }; +} diff --git a/src/aws-cpp-sdk-core/include/smithy/client/schema/JsonShapeSerializer.h b/src/aws-cpp-sdk-core/include/smithy/client/schema/JsonShapeSerializer.h new file mode 100644 index 00000000000..6e1c412b99f --- /dev/null +++ b/src/aws-cpp-sdk-core/include/smithy/client/schema/JsonShapeSerializer.h @@ -0,0 +1,55 @@ +#pragma once + +#include +#include +#include + +namespace smithy { + namespace schema { + class JsonShapeSerializer: public ShapeSerializer { + public: + JsonShapeSerializer() = default; + + void BeginStructure(const Schema& schema) override; + void EndStructure() override; + + void WriteBoolean(const FieldSchema& field, bool value) override; + void WriteInteger(const FieldSchema& field, int value) override; + void WriteLong(const FieldSchema& field, int64_t value) override; + void WriteDouble(const FieldSchema& field, double value) override; + void WriteString(const FieldSchema& field, const Aws::String& value) override; + void WriteTimestamp(const FieldSchema& field, const Aws::Utils::DateTime& value) override; + void WriteBlob(const FieldSchema& field, const Aws::Utils::ByteBuffer& value) override; + void WriteEnum(const FieldSchema& field, int value) override; + void WriteNull(const FieldSchema& field) override; + + void BeginList(const FieldSchema& field, size_t count) override; + void EndList() override; + + void BeginMap(const FieldSchema& field,size_t count) override; + void WriteMapKey(const Aws::String& key) override; + void EndMap() override; + + void BeginNestedStructure(const FieldSchema& field) override; + void EndNestedStructure() override; + + Aws::Utils::Json::JsonValue GetResult() const { return m_root; } + Aws::String GetPayload() const; + private: + Aws::Utils::Json::JsonValue& CurrentObject(); + + Aws::Utils::Json::JsonValue m_root; + + struct StackEntry { + Aws::Utils::Json::JsonValue object; + const char* fieldName; + bool isList; + Aws::Utils::Array listItems; + size_t listIndex; + }; + Aws::Vector m_stack; + Aws::String m_currentMapKey; + bool m_inMap = false; + }; + } +} diff --git a/src/aws-cpp-sdk-core/include/smithy/client/schema/QueryShapeSerializer.h b/src/aws-cpp-sdk-core/include/smithy/client/schema/QueryShapeSerializer.h new file mode 100644 index 00000000000..28c6b4ab3af --- /dev/null +++ b/src/aws-cpp-sdk-core/include/smithy/client/schema/QueryShapeSerializer.h @@ -0,0 +1,48 @@ +#pragma once + +#include +#include +#include + +namespace smithy { + namespace schema { + class QueryShapeSerializer : public ShapeSerializer { + public: + QueryShapeSerializer(const Aws::String& action, const Aws::Crt::String& version); + + void BeginStructure(const Schema& schema) override; + void EndStructure() override; + + void WriteBoolean(const FieldSchema& field, bool value) override; + void WriteInteger(const FieldSchema& field, int value) override; + void WriteLong(const FieldSchema& field, int64_t value) override; + void WriteDouble(const FieldSchema& field, double value) override; + void WriteString(const FieldSchema& field, const Aws::String& value) override; + void WriteTimestamp(const FieldSchema& field, const Aws::Utils::DateTime& value) override; + void WriteBlob(const FieldSchema& field, const Aws::Utils::ByteBuffer& value) override; + void WriteEnum(const FieldSchema& field, int value) override; + void WriteNull(const FieldSchema& field) override; + + void BeginList(const FieldSchema& field, size_t count) override; + void EndList() override; + + void BeginMap(const FieldSchema& field,size_t count) override; + void WriteMapKey(const Aws::String& key) override; + void EndMap() override; + + void BeginNestedStructure(const FieldSchema& field) override; + void EndNestedStructure() override; + + Aws::String GetPayload() const; + + private: + void AppendParam(const Aws::String& key, const Aws::String& value); + Aws::String CurrentPrefix() const(); + + Aws::StringStream m_ss; + Aws::Vector m_prefixStack; + int m_listIndex = 0; + int m_mapIndex = 0; + }; + } +} diff --git a/src/aws-cpp-sdk-core/include/smithy/client/schema/Schema.h b/src/aws-cpp-sdk-core/include/smithy/client/schema/Schema.h new file mode 100644 index 00000000000..dafe5446036 --- /dev/null +++ b/src/aws-cpp-sdk-core/include/smithy/client/schema/Schema.h @@ -0,0 +1,74 @@ +#pragma once + +#include +#include +#include + +namespace smithy { + namespace schema { + enum class ShapeType : uint8_t { + Boolean, + Integer, + Long, + Double, + String, + Timestamp, + Blob, + Enum, + List, + Map, + Structure, + Union, + Document + }; + + enum class TimestampFormate : uint8_t { + EpochSeconds, + DateTime, + HttpData + }; + + enum class FieldLocation : uint8_t { + Bode, + QueryString, + Header, + UriLabel, + StatusCode + }; + + struct Schema; + + struct FieldSchema { + const chat* wireName; + uint16_t memberIndex; + ShapeType type; + FieldLocation location; + TimestampFormate timestampFormat; + const Schema* nestedSchema; + Aws::String (*enumToString)(int); + int (*stringToEnum)(const Aws::Strings&); + }; + + struct Schema { + const char* shapeName; + ShapeType type; + const FieldSchema* fields; + uint16_t fieldCount; + const Schema* elementSchema; + const Schema* keySchema; + + int GetFieldIndex(const char* name) const { + for (uint16_t i = 0; i < fieldCount; i++) { + if (fields[i].wireName !=nullptr && strcmp(fields[i].wireName, name) == 0) { + return static_cast(i); + } + } + return -1; + } + + int GetFieldIndex(const Aws::String& name) const { + return GetFieldIndex(name.c_str()); + } + }; + } +} \ No newline at end of file diff --git a/src/aws-cpp-sdk-core/include/smithy/client/schema/ShapeSerializer.h b/src/aws-cpp-sdk-core/include/smithy/client/schema/ShapeSerializer.h new file mode 100644 index 00000000000..df123fbd606 --- /dev/null +++ b/src/aws-cpp-sdk-core/include/smithy/client/schema/ShapeSerializer.h @@ -0,0 +1,46 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include "Schema.h" + + +namespace Aws::Utils { + class DateTime; +} + +namespace smithy { + namespace schema { + class ShapeSerializer { + public: + virtual ~ShapeSerializer() = default; + + virtual void BeginStructure(const Schema& schema) = 0; + virtual void EndStructure() = 0; + + virtual void WriteBoolean(const FieldSchema& field, bool value) =0; + virtual void WriteInteger(const FieldSchema& field, int value) = 0; + virtual void WriteLong(const FieldSchema& field, int64_t value) = 0; + virtual void WriteDouble(const FieldSchema& field, double value) = 0; + virtual void WriteString(const FieldSchema& field, const Aws::String& value) = 0; + virtual void WriteTimestamp(const FieldSchema& field, const Aws::Utils::DateTime& value) = 0; + virtual void WriteBlob(const FieldSchema& field, const Aws::Utils::ByteBuffer& value) = 0; + virtual void WriteEnum(const FieldSchema& field, int value) = 0; + virtual void WriteNull(const FieldSchema& field) = 0; + + virtual void BeginList(const FieldSchema& field, size_t count) = 0; + virtual void EndList() = 0; + + virtual void BeginMap(const FieldSchema& field, size_t count) = 0; + virtual void WriteMapKey(const Aws::String& key) = 0; + virtual void EndMap() = 0; + + virtual void BeginNestedStructure(const FieldSchema& field) = 0; + virtual void EndNestedStructure() = 0; + }; + } +} diff --git a/src/aws-cpp-sdk-core/include/smithy/client/schema/XmlShapeSerializer.h b/src/aws-cpp-sdk-core/include/smithy/client/schema/XmlShapeSerializer.h new file mode 100644 index 00000000000..883bc7c2a36 --- /dev/null +++ b/src/aws-cpp-sdk-core/include/smithy/client/schema/XmlShapeSerializer.h @@ -0,0 +1,51 @@ +#pragma once + +#include +#include +#include +#include + + +namespace smithy { + namespace schema { + class XmlShapeSerializer : public ShapeSerializer { + XmlShapeSerializer() = default; + + void BeginStructure(const Schema& schema) override; + void EndStructure() override; + + void WriteBoolean(const FieldSchema& field, bool value) override; + void WriteInteger(const FieldSchema& field, int value) override; + void WriteLong(const FieldSchema& field, int64_t value) override; + void WriteDouble(const FieldSchema& field, double value) override; + void WriteString(const FieldSchema& field, const Aws::String& value) override; + void WriteTimestamp(const FieldSchema& field, const Aws::Utils::DateTime& value) override; + void WriteBlob(const FieldSchema& field, const Aws::Utils::ByteBuffer& value) override; + void WriteEnum(const FieldSchema& field, int value) override; + void WriteNull(const FieldSchema& field) override; + + void BeginList(const FieldSchema& field, size_t count) override; + void EndList() override; + + void BeginMap(const FieldSchema& field,size_t count) override; + void WriteMapKey(const Aws::String& key) override; + void EndMap() override; + + void BeginNestedStructure(const FieldSchema& field) override; + void EndNestedStructure() override; + + Aws::String GetPayload() const; + + private: + Aws::OStringStream m_stream; + struct StackEntry { + const char* elementName; + bool isList; + bool isMap; + bool isFlattened; + }; + Aws::Vector m_stack; + Aws::String m_currentMapKey; + }; + } +} diff --git a/src/aws-cpp-sdk-core/source/smithy/client/schema/JsonShapeSerializer.cpp b/src/aws-cpp-sdk-core/source/smithy/client/schema/JsonShapeSerializer.cpp new file mode 100644 index 00000000000..8b75af491fe --- /dev/null +++ b/src/aws-cpp-sdk-core/source/smithy/client/schema/JsonShapeSerializer.cpp @@ -0,0 +1,3 @@ +// +// Created by Pulim, Snigdha on 6/2/26. +// \ No newline at end of file From 9e6b1072d2932fecad4defdde3a4060dbf2fa82d Mon Sep 17 00:00:00 2001 From: pulimsr Date: Wed, 3 Jun 2026 11:14:09 -0400 Subject: [PATCH 2/2] Schema class and ShapeSerializer interface with PIMPL serializers --- .../client/schema/CborShapeSerializer.h | 80 ++++++------ .../client/schema/JsonShapeSerializer.h | 91 ++++++------- .../client/schema/QueryShapeSerializer.h | 84 ++++++------ .../include/smithy/client/schema/Schema.h | 122 ++++++++---------- .../smithy/client/schema/ShapeSerializer.h | 76 ++++++----- .../smithy/client/schema/XmlShapeSerializer.h | 85 ++++++------ .../client/schema/JsonShapeSerializer.cpp | 3 - 7 files changed, 254 insertions(+), 287 deletions(-) delete mode 100644 src/aws-cpp-sdk-core/source/smithy/client/schema/JsonShapeSerializer.cpp diff --git a/src/aws-cpp-sdk-core/include/smithy/client/schema/CborShapeSerializer.h b/src/aws-cpp-sdk-core/include/smithy/client/schema/CborShapeSerializer.h index 43ea13505dd..13636bc3177 100644 --- a/src/aws-cpp-sdk-core/include/smithy/client/schema/CborShapeSerializer.h +++ b/src/aws-cpp-sdk-core/include/smithy/client/schema/CborShapeSerializer.h @@ -1,43 +1,47 @@ #pragma once +#include #include -#include + +#include namespace smithy { - namespace schema { - class AWS_CORE_API CborShapeSerializer : public ShapeSerializer { - public: - CborShapeSerializer() = default; - - void BeginStructure(const Schema& schema) override; - void EndStructure() override; - - void WriteBoolean(const FieldSchema& field, bool value) override; - void WriteInteger(const FieldSchema& field, int value) override; - void WriteLong(const FieldSchema& field, int64_t value) override; - void WriteDouble(const FieldSchema& field, double value) override; - void WriteString(const FieldSchema& field, const Aws::String& value) override; - void WriteTimestamp(const FieldSchema& field, const Aws::Utils::DateTime& value) override; - void WriteBlob(const FieldSchema& field, const Aws::Utils::ByteBuffer& value) override; - void WriteEnum(const FieldSchema& field, int value) override; - void WriteNull(const FieldSchema& field) override; - - void BeginList(const FieldSchema& field, size_t count) override; - void EndList() override; - - void BeginMap(const FieldSchema& field,size_t count) override; - void WriteMapKey(const Aws::String& key) override; - void EndMap() override; - - void BeginNestedStructure(const FieldSchema& field) override; - void EndNestedStructure() override; - - Aws::String GetPayload() const; - private: - void WriteKey(const chat* key); - - Aws::Crt::Cbor::CborEncoder m_encoder; - size_t m_structFieldCount = 0; - }; - }; -} +namespace schema { + +class AWS_CORE_API CborShapeSerializer : public ShapeSerializer { + public: + CborShapeSerializer(); + ~CborShapeSerializer(); + + void BeginStructure(const Schema& schema) override; + void EndStructure() override; + + void WriteBoolean(const Schema& schema, bool value) override; + void WriteInteger(const Schema& schema, int value) override; + void WriteLong(const Schema& schema, int64_t value) override; + void WriteDouble(const Schema& schema, double value) override; + void WriteString(const Schema& schema, const Aws::String& value) override; + void WriteTimestamp(const Schema& schema, const Aws::Utils::DateTime& value) override; + void WriteBlob(const Schema& schema, const Aws::Utils::ByteBuffer& value) override; + void WriteEnum(const Schema& schema, int value) override; + void WriteNull(const Schema& schema) override; + + void BeginList(const Schema& schema, size_t count) override; + void EndList() override; + + void BeginMap(const Schema& schema, size_t count) override; + void WriteMapKey(const Aws::String& key) override; + void EndMap() override; + + void BeginNestedStructure(const Schema& schema) override; + void EndNestedStructure() override; + + Aws::String GetPayload() const; + + private: + struct Impl; + std::unique_ptr m_impl; +}; + +} // namespace schema +} // namespace smithy diff --git a/src/aws-cpp-sdk-core/include/smithy/client/schema/JsonShapeSerializer.h b/src/aws-cpp-sdk-core/include/smithy/client/schema/JsonShapeSerializer.h index 6e1c412b99f..a2063a8bdd9 100644 --- a/src/aws-cpp-sdk-core/include/smithy/client/schema/JsonShapeSerializer.h +++ b/src/aws-cpp-sdk-core/include/smithy/client/schema/JsonShapeSerializer.h @@ -1,55 +1,46 @@ #pragma once #include -#include -#include + +#include namespace smithy { - namespace schema { - class JsonShapeSerializer: public ShapeSerializer { - public: - JsonShapeSerializer() = default; - - void BeginStructure(const Schema& schema) override; - void EndStructure() override; - - void WriteBoolean(const FieldSchema& field, bool value) override; - void WriteInteger(const FieldSchema& field, int value) override; - void WriteLong(const FieldSchema& field, int64_t value) override; - void WriteDouble(const FieldSchema& field, double value) override; - void WriteString(const FieldSchema& field, const Aws::String& value) override; - void WriteTimestamp(const FieldSchema& field, const Aws::Utils::DateTime& value) override; - void WriteBlob(const FieldSchema& field, const Aws::Utils::ByteBuffer& value) override; - void WriteEnum(const FieldSchema& field, int value) override; - void WriteNull(const FieldSchema& field) override; - - void BeginList(const FieldSchema& field, size_t count) override; - void EndList() override; - - void BeginMap(const FieldSchema& field,size_t count) override; - void WriteMapKey(const Aws::String& key) override; - void EndMap() override; - - void BeginNestedStructure(const FieldSchema& field) override; - void EndNestedStructure() override; - - Aws::Utils::Json::JsonValue GetResult() const { return m_root; } - Aws::String GetPayload() const; - private: - Aws::Utils::Json::JsonValue& CurrentObject(); - - Aws::Utils::Json::JsonValue m_root; - - struct StackEntry { - Aws::Utils::Json::JsonValue object; - const char* fieldName; - bool isList; - Aws::Utils::Array listItems; - size_t listIndex; - }; - Aws::Vector m_stack; - Aws::String m_currentMapKey; - bool m_inMap = false; - }; - } -} +namespace schema { + +class JsonShapeSerializer : public ShapeSerializer { + public: + JsonShapeSerializer(); + ~JsonShapeSerializer(); + + void BeginStructure(const Schema& schema) override; + void EndStructure() override; + + void WriteBoolean(const Schema& schema, bool value) override; + void WriteInteger(const Schema& schema, int value) override; + void WriteLong(const Schema& schema, int64_t value) override; + void WriteDouble(const Schema& schema, double value) override; + void WriteString(const Schema& schema, const Aws::String& value) override; + void WriteTimestamp(const Schema& schema, const Aws::Utils::DateTime& value) override; + void WriteBlob(const Schema& schema, const Aws::Utils::ByteBuffer& value) override; + void WriteEnum(const Schema& schema, int value) override; + void WriteNull(const Schema& schema) override; + + void BeginList(const Schema& schema, size_t count) override; + void EndList() override; + + void BeginMap(const Schema& schema, size_t count) override; + void WriteMapKey(const Aws::String& key) override; + void EndMap() override; + + void BeginNestedStructure(const Schema& schema) override; + void EndNestedStructure() override; + + Aws::String GetPayload() const; + + private: + struct Impl; + std::unique_ptr m_impl; +}; + +} // namespace schema +} // namespace smithy diff --git a/src/aws-cpp-sdk-core/include/smithy/client/schema/QueryShapeSerializer.h b/src/aws-cpp-sdk-core/include/smithy/client/schema/QueryShapeSerializer.h index 28c6b4ab3af..d31668e2695 100644 --- a/src/aws-cpp-sdk-core/include/smithy/client/schema/QueryShapeSerializer.h +++ b/src/aws-cpp-sdk-core/include/smithy/client/schema/QueryShapeSerializer.h @@ -1,48 +1,46 @@ #pragma once #include -#include -#include + +#include namespace smithy { - namespace schema { - class QueryShapeSerializer : public ShapeSerializer { - public: - QueryShapeSerializer(const Aws::String& action, const Aws::Crt::String& version); - - void BeginStructure(const Schema& schema) override; - void EndStructure() override; - - void WriteBoolean(const FieldSchema& field, bool value) override; - void WriteInteger(const FieldSchema& field, int value) override; - void WriteLong(const FieldSchema& field, int64_t value) override; - void WriteDouble(const FieldSchema& field, double value) override; - void WriteString(const FieldSchema& field, const Aws::String& value) override; - void WriteTimestamp(const FieldSchema& field, const Aws::Utils::DateTime& value) override; - void WriteBlob(const FieldSchema& field, const Aws::Utils::ByteBuffer& value) override; - void WriteEnum(const FieldSchema& field, int value) override; - void WriteNull(const FieldSchema& field) override; - - void BeginList(const FieldSchema& field, size_t count) override; - void EndList() override; - - void BeginMap(const FieldSchema& field,size_t count) override; - void WriteMapKey(const Aws::String& key) override; - void EndMap() override; - - void BeginNestedStructure(const FieldSchema& field) override; - void EndNestedStructure() override; - - Aws::String GetPayload() const; - - private: - void AppendParam(const Aws::String& key, const Aws::String& value); - Aws::String CurrentPrefix() const(); - - Aws::StringStream m_ss; - Aws::Vector m_prefixStack; - int m_listIndex = 0; - int m_mapIndex = 0; - }; - } -} +namespace schema { + +class QueryShapeSerializer : public ShapeSerializer { + public: + QueryShapeSerializer(const Aws::String& action, const Aws::String& version); + ~QueryShapeSerializer(); + + void BeginStructure(const Schema& schema) override; + void EndStructure() override; + + void WriteBoolean(const Schema& schema, bool value) override; + void WriteInteger(const Schema& schema, int value) override; + void WriteLong(const Schema& schema, int64_t value) override; + void WriteDouble(const Schema& schema, double value) override; + void WriteString(const Schema& schema, const Aws::String& value) override; + void WriteTimestamp(const Schema& schema, const Aws::Utils::DateTime& value) override; + void WriteBlob(const Schema& schema, const Aws::Utils::ByteBuffer& value) override; + void WriteEnum(const Schema& schema, int value) override; + void WriteNull(const Schema& schema) override; + + void BeginList(const Schema& schema, size_t count) override; + void EndList() override; + + void BeginMap(const Schema& schema, size_t count) override; + void WriteMapKey(const Aws::String& key) override; + void EndMap() override; + + void BeginNestedStructure(const Schema& schema) override; + void EndNestedStructure() override; + + Aws::String GetPayload() const; + + private: + struct Impl; + std::unique_ptr m_impl; +}; + +} // namespace schema +} // namespace smithy diff --git a/src/aws-cpp-sdk-core/include/smithy/client/schema/Schema.h b/src/aws-cpp-sdk-core/include/smithy/client/schema/Schema.h index dafe5446036..a8a8cacb3a6 100644 --- a/src/aws-cpp-sdk-core/include/smithy/client/schema/Schema.h +++ b/src/aws-cpp-sdk-core/include/smithy/client/schema/Schema.h @@ -1,74 +1,60 @@ #pragma once #include + #include -#include namespace smithy { - namespace schema { - enum class ShapeType : uint8_t { - Boolean, - Integer, - Long, - Double, - String, - Timestamp, - Blob, - Enum, - List, - Map, - Structure, - Union, - Document - }; - - enum class TimestampFormate : uint8_t { - EpochSeconds, - DateTime, - HttpData - }; - - enum class FieldLocation : uint8_t { - Bode, - QueryString, - Header, - UriLabel, - StatusCode - }; - - struct Schema; - - struct FieldSchema { - const chat* wireName; - uint16_t memberIndex; - ShapeType type; - FieldLocation location; - TimestampFormate timestampFormat; - const Schema* nestedSchema; - Aws::String (*enumToString)(int); - int (*stringToEnum)(const Aws::Strings&); - }; - - struct Schema { - const char* shapeName; - ShapeType type; - const FieldSchema* fields; - uint16_t fieldCount; - const Schema* elementSchema; - const Schema* keySchema; - - int GetFieldIndex(const char* name) const { - for (uint16_t i = 0; i < fieldCount; i++) { - if (fields[i].wireName !=nullptr && strcmp(fields[i].wireName, name) == 0) { - return static_cast(i); - } - } - return -1; - } - - int GetFieldIndex(const Aws::String& name) const { - return GetFieldIndex(name.c_str()); - } - }; - } -} \ No newline at end of file +namespace schema { + +enum class ShapeType : uint8_t { + Boolean, + Byte, + Short, + Integer, + Long, + Float, + Double, + BigInteger, + BigDecimal, + String, + Enum, + IntEnum, + Blob, + Timestamp, + Document, + List, + Map, + Structure, + Union, + Operation, + Resource, + Service +}; + +class Schema { + public: + Schema() = default; + + ShapeType GetType() const { return m_type; } + const char* GetId() const { return m_id; } + const char* GetMemberName() const { return m_memberName; } + int GetMemberIndex() const { return m_memberIndex; } + bool IsMember() const { return m_memberName != nullptr; } + + const Schema* GetMember(const char* name) const; + const Schema* GetMember(int index) const; + + uint16_t GetMemberCount() const { return m_memberCount; } + + private: + const char* m_id = nullptr; + ShapeType m_type = ShapeType::Structure; + const char* m_memberName = nullptr; + int m_memberIndex = 0; + const Schema* m_members = nullptr; + uint16_t m_memberCount = 0; +}; + +} // namespace schema +} // namespace smithy diff --git a/src/aws-cpp-sdk-core/include/smithy/client/schema/ShapeSerializer.h b/src/aws-cpp-sdk-core/include/smithy/client/schema/ShapeSerializer.h index df123fbd606..41279e7f5a9 100644 --- a/src/aws-cpp-sdk-core/include/smithy/client/schema/ShapeSerializer.h +++ b/src/aws-cpp-sdk-core/include/smithy/client/schema/ShapeSerializer.h @@ -1,46 +1,42 @@ #pragma once -#include -#include -#include -#include #include +#include +#include +#include -#include "Schema.h" - - -namespace Aws::Utils { - class DateTime; -} +#include namespace smithy { - namespace schema { - class ShapeSerializer { - public: - virtual ~ShapeSerializer() = default; - - virtual void BeginStructure(const Schema& schema) = 0; - virtual void EndStructure() = 0; - - virtual void WriteBoolean(const FieldSchema& field, bool value) =0; - virtual void WriteInteger(const FieldSchema& field, int value) = 0; - virtual void WriteLong(const FieldSchema& field, int64_t value) = 0; - virtual void WriteDouble(const FieldSchema& field, double value) = 0; - virtual void WriteString(const FieldSchema& field, const Aws::String& value) = 0; - virtual void WriteTimestamp(const FieldSchema& field, const Aws::Utils::DateTime& value) = 0; - virtual void WriteBlob(const FieldSchema& field, const Aws::Utils::ByteBuffer& value) = 0; - virtual void WriteEnum(const FieldSchema& field, int value) = 0; - virtual void WriteNull(const FieldSchema& field) = 0; - - virtual void BeginList(const FieldSchema& field, size_t count) = 0; - virtual void EndList() = 0; - - virtual void BeginMap(const FieldSchema& field, size_t count) = 0; - virtual void WriteMapKey(const Aws::String& key) = 0; - virtual void EndMap() = 0; - - virtual void BeginNestedStructure(const FieldSchema& field) = 0; - virtual void EndNestedStructure() = 0; - }; - } -} +namespace schema { + +class ShapeSerializer { + public: + virtual ~ShapeSerializer() = default; + + virtual void BeginStructure(const Schema& schema) = 0; + virtual void EndStructure() = 0; + + virtual void WriteBoolean(const Schema& schema, bool value) = 0; + virtual void WriteInteger(const Schema& schema, int value) = 0; + virtual void WriteLong(const Schema& schema, int64_t value) = 0; + virtual void WriteDouble(const Schema& schema, double value) = 0; + virtual void WriteString(const Schema& schema, const Aws::String& value) = 0; + virtual void WriteTimestamp(const Schema& schema, const Aws::Utils::DateTime& value) = 0; + virtual void WriteBlob(const Schema& schema, const Aws::Utils::ByteBuffer& value) = 0; + virtual void WriteEnum(const Schema& schema, int value) = 0; + virtual void WriteNull(const Schema& schema) = 0; + + virtual void BeginList(const Schema& schema, size_t count) = 0; + virtual void EndList() = 0; + + virtual void BeginMap(const Schema& schema, size_t count) = 0; + virtual void WriteMapKey(const Aws::String& key) = 0; + virtual void EndMap() = 0; + + virtual void BeginNestedStructure(const Schema& schema) = 0; + virtual void EndNestedStructure() = 0; +}; + +} // namespace schema +} // namespace smithy diff --git a/src/aws-cpp-sdk-core/include/smithy/client/schema/XmlShapeSerializer.h b/src/aws-cpp-sdk-core/include/smithy/client/schema/XmlShapeSerializer.h index 883bc7c2a36..9f35230dc7e 100644 --- a/src/aws-cpp-sdk-core/include/smithy/client/schema/XmlShapeSerializer.h +++ b/src/aws-cpp-sdk-core/include/smithy/client/schema/XmlShapeSerializer.h @@ -1,51 +1,46 @@ #pragma once #include -#include -#include -#include +#include namespace smithy { - namespace schema { - class XmlShapeSerializer : public ShapeSerializer { - XmlShapeSerializer() = default; - - void BeginStructure(const Schema& schema) override; - void EndStructure() override; - - void WriteBoolean(const FieldSchema& field, bool value) override; - void WriteInteger(const FieldSchema& field, int value) override; - void WriteLong(const FieldSchema& field, int64_t value) override; - void WriteDouble(const FieldSchema& field, double value) override; - void WriteString(const FieldSchema& field, const Aws::String& value) override; - void WriteTimestamp(const FieldSchema& field, const Aws::Utils::DateTime& value) override; - void WriteBlob(const FieldSchema& field, const Aws::Utils::ByteBuffer& value) override; - void WriteEnum(const FieldSchema& field, int value) override; - void WriteNull(const FieldSchema& field) override; - - void BeginList(const FieldSchema& field, size_t count) override; - void EndList() override; - - void BeginMap(const FieldSchema& field,size_t count) override; - void WriteMapKey(const Aws::String& key) override; - void EndMap() override; - - void BeginNestedStructure(const FieldSchema& field) override; - void EndNestedStructure() override; - - Aws::String GetPayload() const; - - private: - Aws::OStringStream m_stream; - struct StackEntry { - const char* elementName; - bool isList; - bool isMap; - bool isFlattened; - }; - Aws::Vector m_stack; - Aws::String m_currentMapKey; - }; - } -} +namespace schema { + +class XmlShapeSerializer : public ShapeSerializer { + public: + XmlShapeSerializer(); + ~XmlShapeSerializer(); + + void BeginStructure(const Schema& schema) override; + void EndStructure() override; + + void WriteBoolean(const Schema& schema, bool value) override; + void WriteInteger(const Schema& schema, int value) override; + void WriteLong(const Schema& schema, int64_t value) override; + void WriteDouble(const Schema& schema, double value) override; + void WriteString(const Schema& schema, const Aws::String& value) override; + void WriteTimestamp(const Schema& schema, const Aws::Utils::DateTime& value) override; + void WriteBlob(const Schema& schema, const Aws::Utils::ByteBuffer& value) override; + void WriteEnum(const Schema& schema, int value) override; + void WriteNull(const Schema& schema) override; + + void BeginList(const Schema& schema, size_t count) override; + void EndList() override; + + void BeginMap(const Schema& schema, size_t count) override; + void WriteMapKey(const Aws::String& key) override; + void EndMap() override; + + void BeginNestedStructure(const Schema& schema) override; + void EndNestedStructure() override; + + Aws::String GetPayload() const; + + private: + struct Impl; + std::unique_ptr m_impl; +}; + +} // namespace schema +} // namespace smithy diff --git a/src/aws-cpp-sdk-core/source/smithy/client/schema/JsonShapeSerializer.cpp b/src/aws-cpp-sdk-core/source/smithy/client/schema/JsonShapeSerializer.cpp deleted file mode 100644 index 8b75af491fe..00000000000 --- a/src/aws-cpp-sdk-core/source/smithy/client/schema/JsonShapeSerializer.cpp +++ /dev/null @@ -1,3 +0,0 @@ -// -// Created by Pulim, Snigdha on 6/2/26. -// \ No newline at end of file