Skip to content

Commit c1c5202

Browse files
committed
fix cbor deserialization of map when a enum is the key
1 parent 30ff47d commit c1c5202

3 files changed

Lines changed: 45 additions & 34 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ if(peekType_${recursionDepth}.has_value()){
231231
for (size_t j_${recursionDepth} = 0; j_${recursionDepth} < mapSize_${recursionDepth}.value(); j_${recursionDepth}++) {
232232
#set($value = "nestedMap_${recursionDepth}")
233233
#set($recursionDepth = $recursionDepth + 1)
234+
#set($mapKeyShape = $shapeMember.mapKey.shape)
234235
#set($shapeMember = $template.nestedShapeMember)
235236
#parse("com/amazonaws/util/awsclientgenerator/velocity/cpp/cbor/CborDecodeMapValue.vm")
236237
#set($recursionDepth = $recursionDepth - 1)
@@ -253,6 +254,7 @@ if(peekType_${recursionDepth}.has_value()){
253254
}
254255
#set($value = "nestedMap_${recursionDepth}")
255256
#set($recursionDepth = $recursionDepth + 1)
257+
#set($mapKeyShape = $shapeMember.mapKey.shape)
256258
#set($shapeMember = $template.nestedShapeMember)
257259
#parse("com/amazonaws/util/awsclientgenerator/velocity/cpp/cbor/CborDecodeMapValue.vm")
258260
#set($recursionDepth = $recursionDepth - 1)

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

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,30 @@
22
auto key_${recursionDepth} = decoder->PopNextTextVal();
33
if (key_${recursionDepth}.has_value()) {
44
Aws::String keyStr_${recursionDepth} = Aws::String(reinterpret_cast<const char*>(key_${recursionDepth}.value().ptr), key_${recursionDepth}.value().len);
5+
#if($mapKeyShape && $mapKeyShape.enum)
6+
#set($template.keyExpr = "${mapKeyShape.name}Mapper::Get${mapKeyShape.name}ForName(keyStr_${recursionDepth})")
7+
#else
8+
#set($template.keyExpr = "keyStr_${recursionDepth}")
9+
#end
510
#if($member.shape.sparse)
611
{
712
auto nullPeek_${recursionDepth} = decoder->PeekType();
813
if (nullPeek_${recursionDepth}.has_value() && nullPeek_${recursionDepth}.value() == Aws::Crt::Cbor::CborType::Null) {
914
decoder->ConsumeNextSingleElement();
1015
#if($parentMapDepth == 0)
11-
${memberVarName}[keyStr_${recursionDepth}];
16+
${memberVarName}[${template.keyExpr}];
1217
#else
13-
nestedMap_${parentMapDepth}[keyStr_${recursionDepth}];
18+
nestedMap_${parentMapDepth}[${template.keyExpr}];
1419
#end
1520
} else {
1621
#end
1722
#if($shapeMember.enum)
1823
auto ${containerVar} = decoder->PopNextTextVal();
1924
if (${containerVar}.has_value()) {
2025
#if($parentMapDepth == 0)
21-
${memberVarName}[keyStr_${recursionDepth}] = ${shapeMember.name}Mapper::Get${shapeMember.name}ForName(Aws::String(reinterpret_cast<const char*>(${containerVar}.value().ptr), ${containerVar}.value().len));
26+
${memberVarName}[${template.keyExpr}] = ${shapeMember.name}Mapper::Get${shapeMember.name}ForName(Aws::String(reinterpret_cast<const char*>(${containerVar}.value().ptr), ${containerVar}.value().len));
2227
#else
23-
nestedMap_${parentMapDepth}[keyStr_${recursionDepth}] = ${shapeMember.name}Mapper::Get${shapeMember.name}ForName(Aws::String(reinterpret_cast<const char*>(${containerVar}.value().ptr), ${containerVar}.value().len));
28+
nestedMap_${parentMapDepth}[${template.keyExpr}] = ${shapeMember.name}Mapper::Get${shapeMember.name}ForName(Aws::String(reinterpret_cast<const char*>(${containerVar}.value().ptr), ${containerVar}.value().len));
2429
#end
2530
}
2631
#elseif($shapeMember.string)
@@ -30,9 +35,9 @@ if(peekType_${recursionDepth}){
3035
auto ${containerVar} = decoder->PopNextTextVal();
3136
if (${containerVar}.has_value()) {
3237
#if($parentMapDepth == 0)
33-
${memberVarName}[keyStr_${recursionDepth}] = Aws::String(reinterpret_cast<const char*>(${containerVar}.value().ptr), ${containerVar}.value().len);
38+
${memberVarName}[${template.keyExpr}] = Aws::String(reinterpret_cast<const char*>(${containerVar}.value().ptr), ${containerVar}.value().len);
3439
#else
35-
nestedMap_${parentMapDepth}[keyStr_${recursionDepth}] = Aws::String(reinterpret_cast<const char*>(${containerVar}.value().ptr), ${containerVar}.value().len);
40+
nestedMap_${parentMapDepth}[${template.keyExpr}] = Aws::String(reinterpret_cast<const char*>(${containerVar}.value().ptr), ${containerVar}.value().len);
3641
#end
3742
}
3843
} else {
@@ -52,9 +57,9 @@ if(peekType_${recursionDepth}){
5257
}
5358
}
5459
#if($parentMapDepth == 0)
55-
${memberVarName}[keyStr_${recursionDepth}] = ss_${recursionDepth}.str();
60+
${memberVarName}[${template.keyExpr}] = ss_${recursionDepth}.str();
5661
#else
57-
nestedMap_${parentMapDepth}[keyStr_${recursionDepth}] = ss_${recursionDepth}.str();
62+
nestedMap_${parentMapDepth}[${template.keyExpr}] = ss_${recursionDepth}.str();
5863
#end
5964
ss_${recursionDepth}.clear();
6065
}
@@ -63,27 +68,27 @@ if(peekType_${recursionDepth}){
6368
auto ${containerVar} = decoder->PopNextBooleanVal();
6469
if (${containerVar}.has_value()) {
6570
#if($parentMapDepth == 0)
66-
${memberVarName}[keyStr_${recursionDepth}] = ${containerVar}.value();
71+
${memberVarName}[${template.keyExpr}] = ${containerVar}.value();
6772
#else
68-
nestedMap_${parentMapDepth}[keyStr_${recursionDepth}] = ${containerVar}.value();
73+
nestedMap_${parentMapDepth}[${template.keyExpr}] = ${containerVar}.value();
6974
#end
7075
}
7176
#elseif($shapeMember.double)
7277
auto ${containerVar} = decoder->PopNextFloatVal();
7378
if (${containerVar}.has_value()) {
7479
#if($parentMapDepth == 0)
75-
${memberVarName}[keyStr_${recursionDepth}] = ${containerVar}.value();
80+
${memberVarName}[${template.keyExpr}] = ${containerVar}.value();
7681
#else
77-
nestedMap_${parentMapDepth}[keyStr_${recursionDepth}] = ${containerVar}.value();
82+
nestedMap_${parentMapDepth}[${template.keyExpr}] = ${containerVar}.value();
7883
#end
7984
}
8085
#elseif($shapeMember.float)
8186
auto ${containerVar} = decoder->PopNextFloatVal();
8287
if (${containerVar}.has_value()) {
8388
#if($parentMapDepth == 0)
84-
${memberVarName}[keyStr_${recursionDepth}] = ${containerVar}.value();
89+
${memberVarName}[${template.keyExpr}] = ${containerVar}.value();
8590
#else
86-
nestedMap_${parentMapDepth}[keyStr_${recursionDepth}] = ${containerVar}.value();
91+
nestedMap_${parentMapDepth}[${template.keyExpr}] = ${containerVar}.value();
8792
#end
8893
}
8994
#elseif($shapeMember.blob)
@@ -93,9 +98,9 @@ if(peekType_${recursionDepth}){
9398
auto ${containerVar} = decoder->PopNextBytesVal();
9499
if (${containerVar}.has_value()) {
95100
#if($parentMapDepth == 0)
96-
${memberVarName}[keyStr_${recursionDepth}] = Aws::Utils::ByteBuffer(${containerVar}.value().ptr, ${containerVar}.value().len);
101+
${memberVarName}[${template.keyExpr}] = Aws::Utils::ByteBuffer(${containerVar}.value().ptr, ${containerVar}.value().len);
97102
#else
98-
nestedMap_${parentMapDepth}[keyStr_${recursionDepth}] = Aws::Utils::ByteBuffer(${containerVar}.value().ptr, ${containerVar}.value().len);
103+
nestedMap_${parentMapDepth}[${template.keyExpr}] = Aws::Utils::ByteBuffer(${containerVar}.value().ptr, ${containerVar}.value().len);
99104
#end
100105
}
101106
} else {
@@ -115,9 +120,9 @@ if(peekType_${recursionDepth}){
115120
}
116121
}
117122
#if($parentMapDepth == 0)
118-
${memberVarName}[keyStr_${recursionDepth}] = Aws::Utils::ByteBuffer(ss_${recursionDepth}.str());
123+
${memberVarName}[${template.keyExpr}] = Aws::Utils::ByteBuffer(ss_${recursionDepth}.str());
119124
#else
120-
nestedMap_${parentMapDepth}[keyStr_${recursionDepth}] = Aws::Utils::ByteBuffer(ss_${recursionDepth}.str());
125+
nestedMap_${parentMapDepth}[${template.keyExpr}] = Aws::Utils::ByteBuffer(ss_${recursionDepth}.str());
121126
#end
122127
ss_${recursionDepth}.clear();
123128
}
@@ -134,9 +139,9 @@ if(peekType_${recursionDepth}){
134139
auto ${containerVar} = decoder->PopNextFloatVal();
135140
if (${containerVar}.has_value()) {
136141
#if($parentMapDepth == 0)
137-
${memberVarName}[keyStr_${recursionDepth}] = Aws::Utils::DateTime(${containerVar}.value());
142+
${memberVarName}[${template.keyExpr}] = Aws::Utils::DateTime(${containerVar}.value());
138143
#else
139-
nestedMap_${parentMapDepth}[keyStr_${recursionDepth}] = Aws::Utils::DateTime(${containerVar}.value());
144+
nestedMap_${parentMapDepth}[${template.keyExpr}] = Aws::Utils::DateTime(${containerVar}.value());
140145
#end
141146
}
142147
}
@@ -145,9 +150,9 @@ if(peekType_${recursionDepth}){
145150
auto ${containerVar} = decoder->PopNextUnsignedIntVal();
146151
if (${containerVar}.has_value()) {
147152
#if($parentMapDepth == 0)
148-
${memberVarName}[keyStr_${recursionDepth}] = Aws::Utils::DateTime(${containerVar}.value());
153+
${memberVarName}[${template.keyExpr}] = Aws::Utils::DateTime(${containerVar}.value());
149154
#else
150-
nestedMap_${parentMapDepth}[keyStr_${recursionDepth}] = Aws::Utils::DateTime(${containerVar}.value());
155+
nestedMap_${parentMapDepth}[${template.keyExpr}] = Aws::Utils::DateTime(${containerVar}.value());
151156
#end
152157
}
153158
}
@@ -156,15 +161,15 @@ if(peekType_${recursionDepth}){
156161
#elseif($shapeMember.structure)
157162
#if($member.shape.isMutuallyReferencedWith($shape) || $member.shape.getName() == $shape.getName())
158163
#if($parentMapDepth == 0)
159-
${memberVarName}[keyStr_${recursionDepth}] = Aws::MakeShared<${shapeMember.name}>("${typeInfo.className}", ${shapeMember.name}(decoder));
164+
${memberVarName}[${template.keyExpr}] = Aws::MakeShared<${shapeMember.name}>("${typeInfo.className}", ${shapeMember.name}(decoder));
160165
#else
161-
nestedMap_${parentMapDepth}[keyStr_${recursionDepth}] = Aws::MakeShared<${shapeMember.name}>("${typeInfo.className}", ${shapeMember.name}(decoder));
166+
nestedMap_${parentMapDepth}[${template.keyExpr}] = Aws::MakeShared<${shapeMember.name}>("${typeInfo.className}", ${shapeMember.name}(decoder));
162167
#end
163168
#else
164169
#if($parentMapDepth == 0)
165-
${memberVarName}[keyStr_${recursionDepth}] = ${shapeMember.name}(decoder);
170+
${memberVarName}[${template.keyExpr}] = ${shapeMember.name}(decoder);
166171
#else
167-
nestedMap_${parentMapDepth}[keyStr_${recursionDepth}] = ${shapeMember.name}(decoder);
172+
nestedMap_${parentMapDepth}[${template.keyExpr}] = ${shapeMember.name}(decoder);
168173
#end
169174
#end
170175
#elseif($shapeMember.map)
@@ -183,6 +188,7 @@ if(peekType_${recursionDepth}){
183188
for (size_t j_${recursionDepth} = 0; j_${recursionDepth} < mapSize_${recursionDepth}.value(); j_${recursionDepth}++) {
184189
#set($value = "nestedMap_${recursionDepth}")
185190
#set($recursionDepth = $recursionDepth + 1)
191+
#set($mapKeyShape = $shapeMember.mapKey.shape)
186192
#set($shapeMember = $template.nestedShapeMember)
187193
#parse("com/amazonaws/util/awsclientgenerator/velocity/cpp/cbor/CborDecodeMapValue.vm")
188194
#set($recursionDepth = $recursionDepth - 1)
@@ -204,16 +210,17 @@ if(peekType_${recursionDepth}){
204210
}
205211
#set($value = "nestedMap_${recursionDepth}")
206212
#set($recursionDepth = $recursionDepth + 1)
213+
#set($mapKeyShape = $shapeMember.mapKey.shape)
207214
#set($shapeMember = $template.nestedShapeMember)
208215
#parse("com/amazonaws/util/awsclientgenerator/velocity/cpp/cbor/CborDecodeMapValue.vm")
209216
#set($recursionDepth = $recursionDepth - 1)
210217
}
211218
}
212219
#if($recursionDepth > 1)
213220
#set($parentDepth = $recursionDepth - 1)
214-
nestedMap_${parentDepth}[keyStr_${recursionDepth}] = nestedMap_${recursionDepth};
221+
nestedMap_${parentDepth}[${template.keyExpr}] = nestedMap_${recursionDepth};
215222
#else
216-
${memberVarName}[keyStr_${recursionDepth}] = nestedMap_${recursionDepth};
223+
${memberVarName}[${template.keyExpr}] = nestedMap_${recursionDepth};
217224
#end
218225
}
219226
#elseif($shapeMember.list)
@@ -262,9 +269,9 @@ if(peekType_${recursionDepth}){
262269
}
263270
#if($recursionDepth > 1)
264271
#set($parentDepth = $recursionDepth - 1)
265-
nestedMap_${parentDepth}[keyStr_${recursionDepth}] = nestedList_${recursionDepth};
272+
nestedMap_${parentDepth}[${template.keyExpr}] = nestedList_${recursionDepth};
266273
#else
267-
${memberVarName}[keyStr_${recursionDepth}] = nestedList_${recursionDepth};
274+
${memberVarName}[${template.keyExpr}] = nestedList_${recursionDepth};
268275
#end
269276
}
270277
#else
@@ -274,18 +281,18 @@ if(peekType_${recursionDepth}){
274281
auto ${containerVar} = decoder->PopNextUnsignedIntVal();
275282
if (${containerVar}.has_value()) {
276283
#if($parentMapDepth == 0)
277-
${memberVarName}[keyStr_${recursionDepth}] = static_cast<int64_t>(${containerVar}.value());
284+
${memberVarName}[${template.keyExpr}] = static_cast<int64_t>(${containerVar}.value());
278285
#else
279-
nestedMap_${parentMapDepth}[keyStr_${recursionDepth}] = static_cast<int64_t>(${containerVar}.value());
286+
nestedMap_${parentMapDepth}[${template.keyExpr}] = static_cast<int64_t>(${containerVar}.value());
280287
#end
281288
}
282289
} else {
283290
auto ${containerVar} = decoder->PopNextNegativeIntVal();
284291
if (${containerVar}.has_value()) {
285292
#if($parentMapDepth == 0)
286-
${memberVarName}[keyStr_${recursionDepth}] = static_cast<int64_t>(1 - ${containerVar}.value());
293+
${memberVarName}[${template.keyExpr}] = static_cast<int64_t>(1 - ${containerVar}.value());
287294
#else
288-
nestedMap_${parentMapDepth}[keyStr_${recursionDepth}] = static_cast<int64_t>(1 - ${containerVar}.value());
295+
nestedMap_${parentMapDepth}[${template.keyExpr}] = static_cast<int64_t>(1 - ${containerVar}.value());
289296
#end
290297
}
291298
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ if (peekType_${recursionDepth}.has_value() && (peekType_${recursionDepth}.value(
4747
auto mapSize_${recursionDepth} = decoder->PopNextMapStart();
4848
if(mapSize_${recursionDepth}.has_value()){
4949
for (size_t j_${recursionDepth} = 0; j_${recursionDepth} < mapSize_${recursionDepth}.value(); j_${recursionDepth}++) {
50+
#set($mapKeyShape = $member.shape.mapKey.shape)
5051
#set($shapeMember = $member.shape.mapValue.shape)
5152
#set($recursionDepth= $recursionDepth + 1)
5253
#parse("com/amazonaws/util/awsclientgenerator/velocity/cpp/cbor/CborDecodeMapValue.vm")
@@ -68,6 +69,7 @@ if (peekType_${recursionDepth}.has_value() && (peekType_${recursionDepth}.value(
6869
}
6970
break;
7071
}
72+
#set($mapKeyShape = $member.shape.mapKey.shape)
7173
#set($shapeMember = $member.shape.mapValue.shape)
7274
#set($recursionDepth= $recursionDepth + 1)
7375
#parse("com/amazonaws/util/awsclientgenerator/velocity/cpp/cbor/CborDecodeMapValue.vm")

0 commit comments

Comments
 (0)