Skip to content
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

Protocol tests issue 29 #3261

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations
<#+
}

void ProcessMembers(int level, string variableName, IEnumerable<Member> members)
void ProcessMembers(int level, string variableName, IEnumerable<Member> members, bool insideMap = false)
{
foreach(var member in members)
{
Expand All @@ -231,7 +231,22 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations
}
else if(member.IsMap)
{
ProcessMap(level, variableName, member);
if(member.IsFlattened)
{
ProcessFlattenedMap(level,variableName,member);
}
else
{
ProcessMap(level, variableName, member);
}
}
// we're processing members of a structure as a map's value
else if(insideMap)
{
#>
<#=new string(' ', level * 4)#> if(<#=variableName#>.IsSet<#=member.PropertyName#>())
<#=new string(' ', level * 4)#> xmlWriter.WriteElementString("<#=member.ModeledName#>", <#=member.PrimitiveMarshaller#>(<#=variableName#>.<#=member.PropertyName#><#=(member.UseNullable ? ".Value" : string.Empty)#>));
<#+
}
else
{
Expand Down Expand Up @@ -326,13 +341,13 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations
}

void ProcessMap(int level, string variableName, Member member)
{
{
#>
<#=new string(' ', level * 4)#> xmlWriter.WriteStartElement("<#=member.MarshallName#>");
<#=new string(' ', level * 4)#> foreach (var kvp in <#=variableName#>.<#=member.PropertyName#>)
<#=new string(' ', level * 4)#> {
<#=new string(' ', level * 4)#> xmlWriter.WriteStartElement("entry");
<#=new string(' ', level * 4)#> xmlWriter.WriteElementString("key", kvp.Key);
<#=new string(' ', level * 4)#> xmlWriter.WriteElementString("<#=member.Shape.KeyMarshallName#>", kvp.Key);
<#+
if(member.Shape.ValueShape.IsMap)
{
Expand All @@ -341,17 +356,18 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations
else if(member.Shape.ValueShape.IsStructure)
{
#>
<#=new string(' ', level * 4)#> xmlWriter.WriteStartElement("value");
<#=new string(' ', level * 4)#> xmlWriter.WriteStartElement("<#=member.Shape.ValueMarshallName#>");

<#+
ProcessStructure(level + 2, "kvp.Value", member.Shape.ValueShape);
ProcessStructureAsMapValue(level + 2, "kvp.Value", member.Shape.ValueShape);
#>
<#=new string(' ', level * 4)#> xmlWriter.WriteEndElement();
<#+
}
else
{
#>
<#=new string(' ', level * 4)#> xmlWriter.WriteElementString("value", kvp.Value<#=member.Shape.ValueShape.IsString ? "" : ".ToString()"#>);
<#=new string(' ', level * 4)#> xmlWriter.WriteElementString("<#=member.Shape.ValueMarshallName#>", kvp.Value<#=member.Shape.ValueShape.IsString ? "" : ".ToString()"#>);
<#+
}
#>
Expand All @@ -369,7 +385,7 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations
<#=new string(' ', level * 4)#> foreach (var kvp in <#=variableName#>.<#=member.PropertyName#>)
<#=new string(' ', level * 4)#> {
<#=new string(' ', level * 4)#> xmlWriter.WriteStartElement("<#=member.MarshallName#>");
<#=new string(' ', level * 4)#> xmlWriter.WriteElementString("key", kvp.Key);
<#=new string(' ', level * 4)#> xmlWriter.WriteElementString("<#=member.Shape.KeyMarshallName#>", kvp.Key);
<#+
if(member.Shape.ValueShape.IsMap)
{
Expand All @@ -378,17 +394,17 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations
else if(member.Shape.ValueShape.IsStructure)
{
#>
<#=new string(' ', level * 4)#> xmlWriter.WriteStartElement("value");
<#=new string(' ', level * 4)#> xmlWriter.WriteStartElement("<#=member.Shape.ValueMarshallName#>");
<#+
ProcessStructure(level + 2, "kvp.Value", member.Shape.ValueShape);
ProcessStructureAsMapValue(level + 2, "kvp.Value", member.Shape.ValueShape);
#>
<#=new string(' ', level * 4)#> xmlWriter.WriteEndElement();
<#+
}
else
{
#>
<#=new string(' ', level * 4)#> xmlWriter.WriteElementString("value", kvp.Value<#=member.Shape.ValueShape.IsString ? "" : ".ToString()"#>);
<#=new string(' ', level * 4)#> xmlWriter.WriteElementString("<#=member.Shape.ValueMarshallName#>", kvp.Value<#=member.Shape.ValueShape.IsString ? "" : ".ToString()"#>);
<#=new string(' ', level * 4)#> xmlWriter.WriteEndElement();
<#+
}
Expand All @@ -405,7 +421,7 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations
<#=new string(' ', level * 4)#> foreach (var kvp<#=level#> in <#=parentVariableName#>.Value)
<#=new string(' ', level * 4)#> {
<#=new string(' ', level * 4)#> xmlWriter.WriteStartElement("entry");
<#=new string(' ', level * 4)#> xmlWriter.WriteElementString("key", kvp<#=level#>.Key);
<#=new string(' ', level * 4)#> xmlWriter.WriteElementString("<#=shape.KeyMarshallName#>", kvp<#=level#>.Key);
<#+
if(shape.ValueShape.IsMap)
{
Expand All @@ -414,7 +430,7 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations
else
{
#>
<#=new string(' ', level * 4)#> xmlWriter.WriteElementString("value", kvp<#=level#>.Value);
<#=new string(' ', level * 4)#> xmlWriter.WriteElementString("<#=shape.ValueMarshallName#>", kvp<#=level#>.Value);
<#+
}
#>
Expand Down Expand Up @@ -442,4 +458,18 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations
<#+
}
}
#>
<#+
protected void ProcessStructureAsMapValue(int level, string variableName, Shape shape)
{
// Use shape's ListMarshallName if the structure is a list.
#>
<#=new string(' ', level * 4)#> if (<#=variableName#> != null)
<#=new string(' ', level * 4)#> {
<#+
ProcessMembers(level + 1, variableName, shape.Members, insideMap: true);
#>
<#=new string(' ', level * 4)#> }
<#+
}
#>
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public IRequest Marshall(FlattenedXmlMapRequest publicRequest)
xmlWriter.WriteElementString("key", kvp.Key);
xmlWriter.WriteElementString("value", kvp.Value);
xmlWriter.WriteEndElement();
}
}
}
xmlWriter.WriteEndElement();

xmlWriter.WriteEndElement();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ public IRequest Marshall(FlattenedXmlMapWithXmlNameRequest publicRequest)
{
foreach (var kvp in publicRequest.MyMap)
{
xmlWriter.WriteStartElement("KVP");
xmlWriter.WriteElementString("key", kvp.Key);
xmlWriter.WriteElementString("value", kvp.Value);
xmlWriter.WriteStartElement("entry");
xmlWriter.WriteElementString("K", kvp.Key);
xmlWriter.WriteElementString("V", kvp.Value);
xmlWriter.WriteEndElement();
}
}
}
xmlWriter.WriteEndElement();

xmlWriter.WriteEndElement();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ public IRequest Marshall(NestedXmlMapsRequest publicRequest)
xmlWriter.WriteEndElement();
}
xmlWriter.WriteEndElement();
}
}
if(publicRequest.IsSetNestedMap())
{
xmlWriter.WriteEndElement();
}
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement("nestedMap");
foreach (var kvp in publicRequest.NestedMap)
{
Expand All @@ -98,7 +97,6 @@ public IRequest Marshall(NestedXmlMapsRequest publicRequest)
xmlWriter.WriteEndElement();
}
xmlWriter.WriteEndElement();
}

xmlWriter.WriteEndElement();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,16 @@ public IRequest Marshall(XmlEmptyMapsRequest publicRequest)
xmlWriter.WriteStartElement("entry");
xmlWriter.WriteElementString("key", kvp.Key);
xmlWriter.WriteStartElement("value");

if (kvp.Value != null)
{
xmlWriter.WriteStartElement("GreetingStruct");
if(kvp.Value.IsSetHi())
xmlWriter.WriteElementString("hi", StringUtils.FromString(kvp.Value.Hi));

xmlWriter.WriteEndElement();
}
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
}
xmlWriter.WriteEndElement();
}

xmlWriter.WriteEndElement();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public IRequest Marshall(XmlEnumsRequest publicRequest)
xmlWriter.WriteEndElement();
}
xmlWriter.WriteEndElement();
}
var publicRequestFooEnumSet = publicRequest.FooEnumSet;
if (publicRequestFooEnumSet != null && publicRequestFooEnumSet.Count > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public IRequest Marshall(XmlIntEnumsRequest publicRequest)
xmlWriter.WriteEndElement();
}
xmlWriter.WriteEndElement();
}
var publicRequestIntEnumSet = publicRequest.IntEnumSet;
if (publicRequestIntEnumSet != null && publicRequestIntEnumSet.Count > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@ public IRequest Marshall(XmlMapWithXmlNamespaceRequest publicRequest)
foreach (var kvp in publicRequest.MyMap)
{
xmlWriter.WriteStartElement("entry");
xmlWriter.WriteElementString("key", kvp.Key);
xmlWriter.WriteElementString("value", kvp.Value);
xmlWriter.WriteElementString("K", kvp.Key);
xmlWriter.WriteElementString("V", kvp.Value);
xmlWriter.WriteEndElement();
}
xmlWriter.WriteEndElement();
}

xmlWriter.WriteEndElement();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,16 @@ public IRequest Marshall(XmlMapsRequest publicRequest)
xmlWriter.WriteStartElement("entry");
xmlWriter.WriteElementString("key", kvp.Key);
xmlWriter.WriteStartElement("value");

if (kvp.Value != null)
{
xmlWriter.WriteStartElement("GreetingStruct");
if(kvp.Value.IsSetHi())
xmlWriter.WriteElementString("hi", StringUtils.FromString(kvp.Value.Hi));

xmlWriter.WriteEndElement();
}
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
}
xmlWriter.WriteEndElement();
}

xmlWriter.WriteEndElement();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,18 @@ public IRequest Marshall(XmlMapsXmlNameRequest publicRequest)
foreach (var kvp in publicRequest.MyMap)
{
xmlWriter.WriteStartElement("entry");
xmlWriter.WriteElementString("key", kvp.Key);
xmlWriter.WriteStartElement("value");
xmlWriter.WriteElementString("Attribute", kvp.Key);
xmlWriter.WriteStartElement("Setting");

if (kvp.Value != null)
{
xmlWriter.WriteStartElement("GreetingStruct");
if(kvp.Value.IsSetHi())
xmlWriter.WriteElementString("hi", StringUtils.FromString(kvp.Value.Hi));

xmlWriter.WriteEndElement();
}
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
}
xmlWriter.WriteEndElement();
}

xmlWriter.WriteEndElement();
}
Expand Down