Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

using System.Formats.Cbor;
using Amazon.Extensions.CborProtocol.Internal.Transform;
using Amazon.Runtime.EventStreams;
using Amazon.Runtime.Internal;

namespace Amazon.Extensions.CborProtocol.Internal.EventStreams
{
/// <summary>
/// Base class for cbor event stream publishers.
/// </summary>
public abstract class CborEventStreamPublisher : EventStreamPublisher
{
/// <summary>
/// Construct a CborMarshallerContext that subclasses can use to run the marshaller for the event type
/// that should be sent.
/// </summary>
/// <param name="writer">The writer that the marshaller will use to write as it is marshalling the user's object into it's CBOR representation.</param>
/// <returns></returns>
protected static CborMarshallerContext CreateCborMarshallerContext(CborWriter writer)
{
// The original request and service are not needed for event serialization so placeholder values are used.
IRequest request = new DefaultRequest(new EventStreamRequest(), "eventstream");
return new CborMarshallerContext(request, writer);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System;
using System.Collections.Generic;
using System.Formats.Cbor;
using System.Globalization;
using System.IO;
using Amazon;
using Amazon.Runtime;
Expand Down Expand Up @@ -378,6 +379,33 @@ public static CborNullableDateTimeUnmarshaller Instance
}
}

public class CborNullableDateTimeEpochLongMillisecondsUnmarshaller
: ICborUnmarshaller<DateTime?, CborUnmarshallerContext>
{

private CborNullableDateTimeEpochLongMillisecondsUnmarshaller() { }

private static CborNullableDateTimeEpochLongMillisecondsUnmarshaller _instance =
new CborNullableDateTimeEpochLongMillisecondsUnmarshaller();

public static CborNullableDateTimeEpochLongMillisecondsUnmarshaller Instance
{
get { return _instance; }
}

public DateTime? Unmarshall(CborUnmarshallerContext context)
{
if (context.Reader.PeekState() == CborReaderState.Null)
{
context.Reader.ReadNull();
return null;
}
var millseconds = CborLongUnmarshaller.Instance.Unmarshall(context);
var ret = Amazon.Util.AWSSDKUtils.EPOCH_START.AddMilliseconds(millseconds);
return ret;
}
}

public class CborMemoryStreamUnmarshaller
: ICborUnmarshaller<MemoryStream, CborUnmarshallerContext>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ public override string TransformText()

#line 32 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborStructureUnmarshaller.tt"

Member eventPayloadMember = this.Structure.GetExplicitEventPayloadMember();
//HasImplicitEventPayloadMembers means that the structure does not have a member with the EventPayload trait
if(this.Structure != null && this.Structure.IsEvent && !this.Structure.HasImplicitEventPayloadMembers())
if(this.Structure != null && this.Structure.IsEvent && !this.Structure.HasImplicitEventPayloadMembers() && eventPayloadMember != null)
{
Member eventPayloadMember = this.Structure.GetExplicitEventPayloadMember();
if(eventPayloadMember.ModelShape.IsString)
{

Expand Down Expand Up @@ -185,16 +185,6 @@ public override string TransformText()

#line 71 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborStructureUnmarshaller.tt"

}


#line default
#line hidden

#line 74 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborStructureUnmarshaller.tt"

if(this.Structure != null && (!this.Structure.IsEvent || this.Structure.HasImplicitEventPayloadMembers()))
{
foreach (var member in this.Structure.Members)
{

Expand All @@ -203,68 +193,57 @@ public override string TransformText()
#line hidden
this.Write(" case \"");

#line 80 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborStructureUnmarshaller.tt"
#line 75 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborStructureUnmarshaller.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(member.MarshallName));

#line default
#line hidden
this.Write("\":\r\n {\r\n context.AddPathSegment" +
"(\"");

#line 82 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborStructureUnmarshaller.tt"
#line 77 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborStructureUnmarshaller.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(member.PropertyName));

#line default
#line hidden
this.Write("\");\r\n var unmarshaller = ");

#line 83 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborStructureUnmarshaller.tt"
#line 78 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborStructureUnmarshaller.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(member.DetermineTypeUnmarshallerInstantiate()));

#line default
#line hidden
this.Write(";\r\n unmarshalledObject.");

#line 84 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborStructureUnmarshaller.tt"
#line 79 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborStructureUnmarshaller.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(member.PropertyName));

#line default
#line hidden
this.Write(" = unmarshaller.Unmarshall(context);\r\n context.PopPath" +
"Segment();\r\n break;\r\n }\r\n");

#line 88 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborStructureUnmarshaller.tt"
#line 83 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborStructureUnmarshaller.tt"

}
}


#line default
#line hidden
this.Write(" default:\r\n reader.SkipValue();\r\n " +
" break;\r\n }\r\n");

#line 96 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborStructureUnmarshaller.tt"

if(this.Structure != null && (!this.Structure.IsEvent || this.Structure.HasImplicitEventPayloadMembers()))
{


#line default
#line hidden
this.Write(" }\r\n");
" break;\r\n }\r\n }\r\n reader.R" +
"eadEndMap();\r\n");

#line 101 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborStructureUnmarshaller.tt"
#line 92 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborStructureUnmarshaller.tt"

}


#line default
#line hidden
this.Write(" reader.ReadEndMap();\r\n return unmarshalledObject;\r\n " +
" }\r\n\r\n\r\n");
this.Write(" return unmarshalledObject;\r\n }\r\n\r\n\r\n");

#line 109 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborStructureUnmarshaller.tt"
#line 99 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborStructureUnmarshaller.tt"

this.AddStructureSingletonMethod();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations
return null;
var reader = context.Reader;
<#
Member eventPayloadMember = this.Structure.GetExplicitEventPayloadMember();
//HasImplicitEventPayloadMembers means that the structure does not have a member with the EventPayload trait
if(this.Structure != null && this.Structure.IsEvent && !this.Structure.HasImplicitEventPayloadMembers())
if(this.Structure != null && this.Structure.IsEvent && !this.Structure.HasImplicitEventPayloadMembers() && eventPayloadMember != null)
{
Member eventPayloadMember = this.Structure.GetExplicitEventPayloadMember();
if(eventPayloadMember.ModelShape.IsString)
{
#>
Expand Down Expand Up @@ -69,11 +69,6 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations
switch (propertyName)
{
<#
}
#>
<#
if(this.Structure != null && (!this.Structure.IsEvent || this.Structure.HasImplicitEventPayloadMembers()))
{
foreach (var member in this.Structure.Members)
{
#>
Expand All @@ -87,21 +82,16 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations
}
<#
}
}
#>
default:
reader.SkipValue();
break;
}
<#
if(this.Structure != null && (!this.Structure.IsEvent || this.Structure.HasImplicitEventPayloadMembers()))
{
#>
}
reader.ReadEndMap();
Copy link
Preview

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reader.ReadEndMap() call has been moved outside the conditional block, but it should only be called when a map was actually started. This could cause issues when handling event structures with explicit payload members.

Copilot uses AI. Check for mistakes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it wasn't, the duplicate if conditions was merged in one condition.

<#
}
#>
reader.ReadEndMap();
return unmarshalledObject;
}

Expand Down
Loading