Skip to content

Commit abaf995

Browse files
authored
Schema types and ShapeSerializer interface (#3837)
* headers for protocol shapes * Schema class and ShapeSerializer interface with PIMPL serializers * making the inheritance for the shapeSerializer's final
1 parent 764992d commit abaf995

6 files changed

Lines changed: 287 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#pragma once
2+
3+
#include <aws/core/Core_EXPORTS.h>
4+
#include <smithy/client/schema/ShapeSerializer.h>
5+
6+
#include <memory>
7+
8+
namespace smithy {
9+
namespace schema {
10+
11+
class AWS_CORE_API CborShapeSerialize final : public ShapeSerializer {
12+
public:
13+
CborShapeSerializer();
14+
~CborShapeSerializer();
15+
16+
void BeginStructure(const Schema& schema) override;
17+
void EndStructure() override;
18+
19+
void WriteBoolean(const Schema& schema, bool value) override;
20+
void WriteInteger(const Schema& schema, int value) override;
21+
void WriteLong(const Schema& schema, int64_t value) override;
22+
void WriteDouble(const Schema& schema, double value) override;
23+
void WriteString(const Schema& schema, const Aws::String& value) override;
24+
void WriteTimestamp(const Schema& schema, const Aws::Utils::DateTime& value) override;
25+
void WriteBlob(const Schema& schema, const Aws::Utils::ByteBuffer& value) override;
26+
void WriteEnum(const Schema& schema, int value) override;
27+
void WriteNull(const Schema& schema) override;
28+
29+
void BeginList(const Schema& schema, size_t count) override;
30+
void EndList() override;
31+
32+
void BeginMap(const Schema& schema, size_t count) override;
33+
void WriteMapKey(const Aws::String& key) override;
34+
void EndMap() override;
35+
36+
void BeginNestedStructure(const Schema& schema) override;
37+
void EndNestedStructure() override;
38+
39+
Aws::String GetPayload() const;
40+
41+
private:
42+
struct Impl;
43+
std::unique_ptr<Impl> m_impl;
44+
};
45+
46+
} // namespace schema
47+
} // namespace smithy
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#pragma once
2+
3+
#include <smithy/client/schema/ShapeSerializer.h>
4+
5+
#include <memory>
6+
7+
namespace smithy {
8+
namespace schema {
9+
10+
class JsonShapeSerializer final : public ShapeSerializer {
11+
public:
12+
JsonShapeSerializer();
13+
~JsonShapeSerializer();
14+
15+
void BeginStructure(const Schema& schema) override;
16+
void EndStructure() override;
17+
18+
void WriteBoolean(const Schema& schema, bool value) override;
19+
void WriteInteger(const Schema& schema, int value) override;
20+
void WriteLong(const Schema& schema, int64_t value) override;
21+
void WriteDouble(const Schema& schema, double value) override;
22+
void WriteString(const Schema& schema, const Aws::String& value) override;
23+
void WriteTimestamp(const Schema& schema, const Aws::Utils::DateTime& value) override;
24+
void WriteBlob(const Schema& schema, const Aws::Utils::ByteBuffer& value) override;
25+
void WriteEnum(const Schema& schema, int value) override;
26+
void WriteNull(const Schema& schema) override;
27+
28+
void BeginList(const Schema& schema, size_t count) override;
29+
void EndList() override;
30+
31+
void BeginMap(const Schema& schema, size_t count) override;
32+
void WriteMapKey(const Aws::String& key) override;
33+
void EndMap() override;
34+
35+
void BeginNestedStructure(const Schema& schema) override;
36+
void EndNestedStructure() override;
37+
38+
Aws::String GetPayload() const;
39+
40+
private:
41+
struct Impl;
42+
std::unique_ptr<Impl> m_impl;
43+
};
44+
45+
} // namespace schema
46+
} // namespace smithy
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#pragma once
2+
3+
#include <smithy/client/schema/ShapeSerializer.h>
4+
5+
#include <memory>
6+
7+
namespace smithy {
8+
namespace schema {
9+
10+
class QueryShapeSerializer final : public ShapeSerializer {
11+
public:
12+
QueryShapeSerializer(const Aws::String& action, const Aws::String& version);
13+
~QueryShapeSerializer();
14+
15+
void BeginStructure(const Schema& schema) override;
16+
void EndStructure() override;
17+
18+
void WriteBoolean(const Schema& schema, bool value) override;
19+
void WriteInteger(const Schema& schema, int value) override;
20+
void WriteLong(const Schema& schema, int64_t value) override;
21+
void WriteDouble(const Schema& schema, double value) override;
22+
void WriteString(const Schema& schema, const Aws::String& value) override;
23+
void WriteTimestamp(const Schema& schema, const Aws::Utils::DateTime& value) override;
24+
void WriteBlob(const Schema& schema, const Aws::Utils::ByteBuffer& value) override;
25+
void WriteEnum(const Schema& schema, int value) override;
26+
void WriteNull(const Schema& schema) override;
27+
28+
void BeginList(const Schema& schema, size_t count) override;
29+
void EndList() override;
30+
31+
void BeginMap(const Schema& schema, size_t count) override;
32+
void WriteMapKey(const Aws::String& key) override;
33+
void EndMap() override;
34+
35+
void BeginNestedStructure(const Schema& schema) override;
36+
void EndNestedStructure() override;
37+
38+
Aws::String GetPayload() const;
39+
40+
private:
41+
struct Impl;
42+
std::unique_ptr<Impl> m_impl;
43+
};
44+
45+
} // namespace schema
46+
} // namespace smithy
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#pragma once
2+
3+
#include <aws/core/utils/memory/stl/AWSString.h>
4+
5+
#include <cstdint>
6+
7+
namespace smithy {
8+
namespace schema {
9+
10+
enum class ShapeType : uint8_t {
11+
Boolean,
12+
Byte,
13+
Short,
14+
Integer,
15+
Long,
16+
Float,
17+
Double,
18+
BigInteger,
19+
BigDecimal,
20+
String,
21+
Enum,
22+
IntEnum,
23+
Blob,
24+
Timestamp,
25+
Document,
26+
List,
27+
Map,
28+
Structure,
29+
Union,
30+
Operation,
31+
Resource,
32+
Service
33+
};
34+
35+
class Schema {
36+
public:
37+
Schema() = default;
38+
39+
ShapeType GetType() const { return m_type; }
40+
const char* GetId() const { return m_id; }
41+
const char* GetMemberName() const { return m_memberName; }
42+
int GetMemberIndex() const { return m_memberIndex; }
43+
bool IsMember() const { return m_memberName != nullptr; }
44+
45+
const Schema* GetMember(const char* name) const;
46+
const Schema* GetMember(int index) const;
47+
48+
uint16_t GetMemberCount() const { return m_memberCount; }
49+
50+
private:
51+
const char* m_id = nullptr;
52+
ShapeType m_type = ShapeType::Structure;
53+
const char* m_memberName = nullptr;
54+
int m_memberIndex = 0;
55+
const Schema* m_members = nullptr;
56+
uint16_t m_memberCount = 0;
57+
};
58+
59+
} // namespace schema
60+
} // namespace smithy
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#pragma once
2+
3+
#include <aws/core/utils/Array.h>
4+
#include <aws/core/utils/DateTime.h>
5+
#include <aws/core/utils/memory/stl/AWSString.h>
6+
#include <smithy/client/schema/Schema.h>
7+
8+
#include <cstdint>
9+
10+
namespace smithy {
11+
namespace schema {
12+
13+
class ShapeSerializer {
14+
public:
15+
virtual ~ShapeSerializer() = default;
16+
17+
virtual void BeginStructure(const Schema& schema) = 0;
18+
virtual void EndStructure() = 0;
19+
20+
virtual void WriteBoolean(const Schema& schema, bool value) = 0;
21+
virtual void WriteInteger(const Schema& schema, int value) = 0;
22+
virtual void WriteLong(const Schema& schema, int64_t value) = 0;
23+
virtual void WriteDouble(const Schema& schema, double value) = 0;
24+
virtual void WriteString(const Schema& schema, const Aws::String& value) = 0;
25+
virtual void WriteTimestamp(const Schema& schema, const Aws::Utils::DateTime& value) = 0;
26+
virtual void WriteBlob(const Schema& schema, const Aws::Utils::ByteBuffer& value) = 0;
27+
virtual void WriteEnum(const Schema& schema, int value) = 0;
28+
virtual void WriteNull(const Schema& schema) = 0;
29+
30+
virtual void BeginList(const Schema& schema, size_t count) = 0;
31+
virtual void EndList() = 0;
32+
33+
virtual void BeginMap(const Schema& schema, size_t count) = 0;
34+
virtual void WriteMapKey(const Aws::String& key) = 0;
35+
virtual void EndMap() = 0;
36+
37+
virtual void BeginNestedStructure(const Schema& schema) = 0;
38+
virtual void EndNestedStructure() = 0;
39+
};
40+
41+
} // namespace schema
42+
} // namespace smithy
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#pragma once
2+
3+
#include <smithy/client/schema/ShapeSerializer.h>
4+
5+
#include <memory>
6+
7+
namespace smithy {
8+
namespace schema {
9+
10+
class XmlShapeSerializer final : public ShapeSerializer {
11+
public:
12+
XmlShapeSerializer();
13+
~XmlShapeSerializer();
14+
15+
void BeginStructure(const Schema& schema) override;
16+
void EndStructure() override;
17+
18+
void WriteBoolean(const Schema& schema, bool value) override;
19+
void WriteInteger(const Schema& schema, int value) override;
20+
void WriteLong(const Schema& schema, int64_t value) override;
21+
void WriteDouble(const Schema& schema, double value) override;
22+
void WriteString(const Schema& schema, const Aws::String& value) override;
23+
void WriteTimestamp(const Schema& schema, const Aws::Utils::DateTime& value) override;
24+
void WriteBlob(const Schema& schema, const Aws::Utils::ByteBuffer& value) override;
25+
void WriteEnum(const Schema& schema, int value) override;
26+
void WriteNull(const Schema& schema) override;
27+
28+
void BeginList(const Schema& schema, size_t count) override;
29+
void EndList() override;
30+
31+
void BeginMap(const Schema& schema, size_t count) override;
32+
void WriteMapKey(const Aws::String& key) override;
33+
void EndMap() override;
34+
35+
void BeginNestedStructure(const Schema& schema) override;
36+
void EndNestedStructure() override;
37+
38+
Aws::String GetPayload() const;
39+
40+
private:
41+
struct Impl;
42+
std::unique_ptr<Impl> m_impl;
43+
};
44+
45+
} // namespace schema
46+
} // namespace smithy

0 commit comments

Comments
 (0)