Skip to content

Commit 2fa2000

Browse files
sbalujasbaluja
andauthored
ByteBuffer reference access implementation (#3482)
* Add AccessB() function to Aws::Utils::ByteBuffer class for reference access * TableOperationTest - TestAttributeValues - Include checks for when byteBuffer should be empty --------- Co-authored-by: sbaluja <[email protected]>
1 parent 64ae473 commit 2fa2000

File tree

7 files changed

+52
-1
lines changed

7 files changed

+52
-1
lines changed

generated/src/aws-cpp-sdk-dynamodb/include/aws/dynamodb/model/AttributeValue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class AWS_DYNAMODB_API AttributeValue
6565

6666
/// returns the ByteBuffer if the value is specialized to this type, otherwise an empty Buffer
6767
const Aws::Utils::ByteBuffer GetB() const;
68+
/// returns a reference to the ByteBuffer if the value is specialized to this type, otherwise a reference to an empty Buffer
69+
const Aws::Utils::ByteBuffer& AccessB() const;
6870
/// if already specialized to a ByteBuffer, sets the value to this value
6971
/// if uninitialized, specializes the type to a ByteBuffer with the specified value
7072
/// if already specialized to another type then the behavior is undefined

generated/src/aws-cpp-sdk-dynamodb/include/aws/dynamodb/model/AttributeValueValue.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class AttributeValueValue
3232

3333
virtual const Aws::Utils::ByteBuffer GetB() const { return {}; }
3434

35+
virtual const Aws::Utils::ByteBuffer& AccessB() const {
36+
static const Aws::Utils::ByteBuffer empty;
37+
return empty;
38+
}
39+
3540
virtual const Aws::Vector<Aws::String> GetSS() const { return {}; }
3641

3742
virtual void AddSItem(const Aws::String& ) { assert(false); }
@@ -104,6 +109,7 @@ class AttributeValueByteBuffer final : public AttributeValueValue
104109
explicit AttributeValueByteBuffer(const Aws::Utils::ByteBuffer& value) : m_b(value) {}
105110
explicit AttributeValueByteBuffer(Aws::Utils::Json::JsonView jsonValue);
106111
const Aws::Utils::ByteBuffer GetB() const override { return m_b; }
112+
const Aws::Utils::ByteBuffer& AccessB() const override { return m_b; }
107113
bool IsDefault() const override { return m_b.GetLength() == 0; }
108114
bool operator == (const AttributeValueValue& other) const override { return GetType() == other.GetType() && m_b == other.GetB(); }
109115
Aws::Utils::Json::JsonValue Jsonize() const override;

generated/src/aws-cpp-sdk-dynamodb/source/model/AttributeValue.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ AttributeValue& AttributeValue::SetB(const ByteBuffer& b)
6666
return *this;
6767
}
6868

69+
const ByteBuffer& AttributeValue::AccessB() const
70+
{
71+
if (m_value)
72+
{
73+
return m_value->AccessB();
74+
}
75+
else
76+
{
77+
static const ByteBuffer empty;
78+
return empty;
79+
}
80+
}
81+
6982
const Aws::Vector<Aws::String> AttributeValue::GetSS() const
7083
{
7184
if (m_value)

tests/aws-cpp-sdk-dynamodb-integration-tests/TableOperationTest.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ TEST_F(TableOperationTest, TestAttributeValues)
907907
const Aws::Utils::ByteBuffer byteBuffer1(buffer1, 6);
908908
unsigned char buffer2[6] = { 21, 35, 55, 68, 11, 6 };
909909
const Aws::Utils::ByteBuffer byteBuffer2(buffer2, 6);
910-
910+
const Aws::Utils::ByteBuffer emptyBuf;
911911
// create the Hash Key value
912912
AttributeValue hashKey("TestValue");
913913

@@ -947,6 +947,9 @@ TEST_F(TableOperationTest, TestAttributeValues)
947947
//ReturnedItemCollection returnedItemCollection = result.GetItems();
948948
EXPECT_EQ("TestValue", returnedItemCollection[HASH_KEY_NAME].GetS());
949949
EXPECT_EQ("String Value", returnedItemCollection["String"].GetS());
950+
951+
EXPECT_EQ(emptyBuf, returnedItemCollection["ByteBuffer"].GetB());
952+
EXPECT_EQ(emptyBuf, returnedItemCollection["ByteBuffer"].AccessB());
950953
}
951954

952955
// Number Value
@@ -1058,6 +1061,7 @@ TEST_F(TableOperationTest, TestAttributeValues)
10581061
EXPECT_EQ("String Value", returnedItemCollection["String"].GetS());
10591062
EXPECT_EQ("1001", returnedItemCollection["Number"].GetN());
10601063
EXPECT_EQ(byteBuffer1, returnedItemCollection["ByteBuffer"].GetB()); // on the 3rd day of xmas...
1064+
EXPECT_EQ(byteBuffer1, returnedItemCollection["ByteBuffer"].AccessB());
10611065
}
10621066

10631067
// StringSet
@@ -1097,6 +1101,7 @@ TEST_F(TableOperationTest, TestAttributeValues)
10971101
EXPECT_EQ("String Value", returnedItemCollection["String"].GetS());
10981102
EXPECT_EQ("1001", returnedItemCollection["Number"].GetN());
10991103
EXPECT_EQ(byteBuffer1, returnedItemCollection["ByteBuffer"].GetB());
1104+
EXPECT_EQ(byteBuffer1, returnedItemCollection["ByteBuffer"].AccessB());
11001105
auto ss = returnedItemCollection["String Set"].GetSS();
11011106
EXPECT_EQ(2u, ss.size());
11021107
EXPECT_NE(ss.end(), std::find(ss.begin(), ss.end(), "test1"));
@@ -1140,6 +1145,7 @@ TEST_F(TableOperationTest, TestAttributeValues)
11401145
EXPECT_EQ("String Value", returnedItemCollection["String"].GetS());
11411146
EXPECT_EQ("1001", returnedItemCollection["Number"].GetN());
11421147
EXPECT_EQ(byteBuffer1, returnedItemCollection["ByteBuffer"].GetB());
1148+
EXPECT_EQ(byteBuffer1, returnedItemCollection["ByteBuffer"].AccessB());
11431149
auto ss = returnedItemCollection["String Set"].GetSS();
11441150
EXPECT_EQ(2u, ss.size());
11451151
EXPECT_NE(ss.end(), std::find(ss.begin(), ss.end(), "test1"));
@@ -1187,6 +1193,7 @@ TEST_F(TableOperationTest, TestAttributeValues)
11871193
EXPECT_EQ("String Value", returnedItemCollection["String"].GetS());
11881194
EXPECT_EQ("1001", returnedItemCollection["Number"].GetN());
11891195
EXPECT_EQ(byteBuffer1, returnedItemCollection["ByteBuffer"].GetB());
1196+
EXPECT_EQ(byteBuffer1, returnedItemCollection["ByteBuffer"].AccessB());
11901197
auto ss = returnedItemCollection["String Set"].GetSS();
11911198
EXPECT_EQ(2u, ss.size());
11921199
EXPECT_NE(ss.end(), std::find(ss.begin(), ss.end(), "test1"));
@@ -1240,6 +1247,7 @@ TEST_F(TableOperationTest, TestAttributeValues)
12401247
EXPECT_EQ("String Value", returnedItemCollection["String"].GetS());
12411248
EXPECT_EQ("1001", returnedItemCollection["Number"].GetN());
12421249
EXPECT_EQ(byteBuffer1, returnedItemCollection["ByteBuffer"].GetB());
1250+
EXPECT_EQ(byteBuffer1, returnedItemCollection["ByteBuffer"].AccessB());
12431251
auto ss = returnedItemCollection["String Set"].GetSS();
12441252
EXPECT_EQ(2u, ss.size());
12451253
EXPECT_NE(ss.end(), std::find(ss.begin(), ss.end(), "test1"));
@@ -1334,6 +1342,7 @@ TEST_F(TableOperationTest, TestAttributeValues)
13341342
EXPECT_EQ("String Value", returnedItemCollection["String"].GetS());
13351343
EXPECT_EQ("1001", returnedItemCollection["Number"].GetN());
13361344
EXPECT_EQ(byteBuffer1, returnedItemCollection["ByteBuffer"].GetB());
1345+
EXPECT_EQ(byteBuffer1, returnedItemCollection["ByteBuffer"].AccessB());
13371346
auto ss = returnedItemCollection["String Set"].GetSS();
13381347
EXPECT_EQ(2u, ss.size());
13391348
EXPECT_NE(ss.end(), std::find(ss.begin(), ss.end(), "test1"));

tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/dynamodb/AttributeValueHeader.vm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public:
6262

6363
/// returns the ByteBuffer if the value is specialized to this type, otherwise an empty Buffer
6464
const Aws::Utils::ByteBuffer GetB() const;
65+
/// returns a reference to the ByteBuffer if the value is specialized to this type, otherwise a reference to an empty Buffer
66+
const Aws::Utils::ByteBuffer& AccessB() const;
6567
/// if already specialized to a ByteBuffer, sets the value to this value
6668
/// if uninitialized, specializes the type to a ByteBuffer with the specified value
6769
/// if already specialized to another type then the behavior is undefined

tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/dynamodb/AttributeValueSource.vm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ AttributeValue& AttributeValue::SetB(const ByteBuffer& b)
6363
return *this;
6464
}
6565

66+
const ByteBuffer& AttributeValue::AccessB() const
67+
{
68+
if (m_value)
69+
{
70+
return m_value->AccessB();
71+
}
72+
else
73+
{
74+
static const ByteBuffer empty;
75+
return empty;
76+
}
77+
}
78+
6679
const Aws::Vector<Aws::String> AttributeValue::GetSS() const
6780
{
6881
if (m_value)

tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/dynamodb/AttributeValueValueHeader.vm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public:
2929

3030
virtual const Aws::Utils::ByteBuffer GetB() const { return {}; }
3131

32+
virtual const Aws::Utils::ByteBuffer& AccessB() const {
33+
static const Aws::Utils::ByteBuffer empty;
34+
return empty;
35+
}
36+
3237
virtual const Aws::Vector<Aws::String> GetSS() const { return {}; }
3338

3439
virtual void AddSItem(const Aws::String& ) { assert(false); }
@@ -101,6 +106,7 @@ public:
101106
explicit AttributeValueByteBuffer(const Aws::Utils::ByteBuffer& value) : m_b(value) {}
102107
explicit AttributeValueByteBuffer(Aws::Utils::Json::JsonView jsonValue);
103108
const Aws::Utils::ByteBuffer GetB() const override { return m_b; }
109+
const Aws::Utils::ByteBuffer& AccessB() const override { return m_b; }
104110
bool IsDefault() const override { return m_b.GetLength() == 0; }
105111
bool operator == (const AttributeValueValue& other) const override { return GetType() == other.GetType() && m_b == other.GetB(); }
106112
Aws::Utils::Json::JsonValue Jsonize() const override;

0 commit comments

Comments
 (0)