From af6e4b4a1328b5ed334605f738483c3581294a52 Mon Sep 17 00:00:00 2001 From: Muhammad Othman Date: Thu, 12 Jun 2025 18:54:59 -0400 Subject: [PATCH 01/15] Add CborProtocol extension project --- ...xtensions.CborProtocol.NetFramework.csproj | 45 +++++ ...Extensions.CborProtocol.NetStandard.csproj | 51 +++++ .../CborWriterExtensions.cs | 103 ++++++++++ .../Directory.Build.props | 6 + .../Internal/CborMarshallerContext.cs | 37 ++++ .../Internal/CborWriterPool.cs | 66 +++++++ .../Properties/AssemblyInfo.cs | 19 ++ .../GeneratorEnumerations.cs | 2 +- .../ProjectFiles/VS2017ProjectFile.cs | 185 ++++++++++-------- .../ProjectFiles/VS2017ProjectFile.tt | 6 + .../ProjectFileCreator.cs | 13 +- .../ServiceClientGeneratorLib/ServiceModel.cs | 5 + .../SolutionFileCreator.cs | 41 ++-- sdk/AWSSDK.NetFramework.sln | 7 + sdk/AWSSDK.NetStandard.sln | 7 + 15 files changed, 492 insertions(+), 101 deletions(-) create mode 100644 extensions/src/AWSSDK.Extensions.CborProtocol/AWSSDK.Extensions.CborProtocol.NetFramework.csproj create mode 100644 extensions/src/AWSSDK.Extensions.CborProtocol/AWSSDK.Extensions.CborProtocol.NetStandard.csproj create mode 100644 extensions/src/AWSSDK.Extensions.CborProtocol/CborWriterExtensions.cs create mode 100644 extensions/src/AWSSDK.Extensions.CborProtocol/Directory.Build.props create mode 100644 extensions/src/AWSSDK.Extensions.CborProtocol/Internal/CborMarshallerContext.cs create mode 100644 extensions/src/AWSSDK.Extensions.CborProtocol/Internal/CborWriterPool.cs create mode 100644 extensions/src/AWSSDK.Extensions.CborProtocol/Properties/AssemblyInfo.cs diff --git a/extensions/src/AWSSDK.Extensions.CborProtocol/AWSSDK.Extensions.CborProtocol.NetFramework.csproj b/extensions/src/AWSSDK.Extensions.CborProtocol/AWSSDK.Extensions.CborProtocol.NetFramework.csproj new file mode 100644 index 000000000000..3bfc21e83660 --- /dev/null +++ b/extensions/src/AWSSDK.Extensions.CborProtocol/AWSSDK.Extensions.CborProtocol.NetFramework.csproj @@ -0,0 +1,45 @@ + + + + net472 + AWSSDK.Extensions.CborProtocol + AWSSDK.Extensions.CborProtocol + false + false + false + false + false + false + false + false + true + true + $(NoWarn);CS1591 + True + + + + + + + + + + ..\..\..\sdk\awssdk.dll.snk + + + + + $(AWSKeyFile) + + + + + + + + + + + + diff --git a/extensions/src/AWSSDK.Extensions.CborProtocol/AWSSDK.Extensions.CborProtocol.NetStandard.csproj b/extensions/src/AWSSDK.Extensions.CborProtocol/AWSSDK.Extensions.CborProtocol.NetStandard.csproj new file mode 100644 index 000000000000..e326b545b9bc --- /dev/null +++ b/extensions/src/AWSSDK.Extensions.CborProtocol/AWSSDK.Extensions.CborProtocol.NetStandard.csproj @@ -0,0 +1,51 @@ + + + + netstandard2.0;netcoreapp3.1;net8.0 + AWSSDK.Extensions.CborProtocol + AWSSDK.Extensions.CborProtocol + false + false + false + false + false + false + false + false + true + true + true + $(NoWarn);CS1591 + True + + + + + + + + IL2026,IL2075 + true + + + + + + ..\..\..\sdk\awssdk.dll.snk + + + + + $(AWSKeyFile) + + + + + + + + + + + + diff --git a/extensions/src/AWSSDK.Extensions.CborProtocol/CborWriterExtensions.cs b/extensions/src/AWSSDK.Extensions.CborProtocol/CborWriterExtensions.cs new file mode 100644 index 000000000000..e06250550e71 --- /dev/null +++ b/extensions/src/AWSSDK.Extensions.CborProtocol/CborWriterExtensions.cs @@ -0,0 +1,103 @@ +/* + * 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 Amazon.Runtime; +using Amazon.Runtime.Internal; +using Amazon.Runtime.Internal.Transform; +using Amazon.Runtime.Internal.Util; +using Amazon.Util; +using System; +using System.Collections.Generic; +using System.Formats.Cbor; +using System.IO; +using System.Text.RegularExpressions; + +namespace AWSSDK.Extensions.CborProtocol +{ + public static class CborWriterExtensions + { + /// + /// Writes the DateTime as UnixEpochSeconds which is the only type we support for CBOR. + /// + /// The CBOR writer to use. + /// The DateTime value to write. + public static void WriteDateTime(this CborWriter writer, DateTime value) + { + writer.WriteTag(CborTag.UnixTimeSeconds); + writer.WriteOptimizedNumber(AWSSDKUtils.ConvertToUnixEpochSecondsDouble(value)); + } + + /// + /// Writes a double using the smallest CBOR representation that preserves value and precision. + /// + /// The CBOR writer to use. + /// The double value to write. + public static void WriteOptimizedNumber(this CborWriter writer, double value) + { + if (double.IsNaN(value) || double.IsInfinity(value)) + { + writer.WriteDouble(value); + return; + } + + if (value % 1 == 0) + { + if (value >= long.MinValue && value <= long.MaxValue) + { + writer.WriteInt64((long)value); + return; + } + + if (value >= 0 && value <= ulong.MaxValue) + { + writer.WriteUInt64((ulong)value); + return; + } + } + + writer.WriteDouble(value); + } + + /// + /// Writes a float using the smallest CBOR representation that preserves value and precision. + /// + /// The CBOR writer to use. + /// The float value to write. + public static void WriteOptimizedNumber(this CborWriter writer, float value) + { + if (float.IsNaN(value) || float.IsInfinity(value)) + { + writer.WriteSingle(value); + return; + } + + if (value % 1 == 0) + { + if (value >= long.MinValue && value <= long.MaxValue) + { + writer.WriteInt64((long)value); + return; + } + + if (value >= 0 && value <= ulong.MaxValue) + { + writer.WriteUInt64((ulong)value); + return; + } + } + + writer.WriteSingle(value); + } + } +} diff --git a/extensions/src/AWSSDK.Extensions.CborProtocol/Directory.Build.props b/extensions/src/AWSSDK.Extensions.CborProtocol/Directory.Build.props new file mode 100644 index 000000000000..7ace368652d0 --- /dev/null +++ b/extensions/src/AWSSDK.Extensions.CborProtocol/Directory.Build.props @@ -0,0 +1,6 @@ + + + + $(MSBuildProjectDirectory)\obj\$(MSBuildProjectName) + + \ No newline at end of file diff --git a/extensions/src/AWSSDK.Extensions.CborProtocol/Internal/CborMarshallerContext.cs b/extensions/src/AWSSDK.Extensions.CborProtocol/Internal/CborMarshallerContext.cs new file mode 100644 index 000000000000..687e153f0be8 --- /dev/null +++ b/extensions/src/AWSSDK.Extensions.CborProtocol/Internal/CborMarshallerContext.cs @@ -0,0 +1,37 @@ +/* + * 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 Amazon.Runtime; +using Amazon.Runtime.Internal; +using Amazon.Runtime.Internal.Transform; +using Amazon.Runtime.Internal.Util; +using Amazon.Util; +using System; +using System.Collections.Generic; +using System.Formats.Cbor; +using System.IO; + +namespace AWSSDK.Extensions.CborProtocol.Internal +{ + public class CborMarshallerContext : MarshallerContext + { + public CborWriter Writer { get; private set; } + + public CborMarshallerContext(IRequest request, CborWriter writer) + : base(request) + { + Writer = writer; + } + } +} diff --git a/extensions/src/AWSSDK.Extensions.CborProtocol/Internal/CborWriterPool.cs b/extensions/src/AWSSDK.Extensions.CborProtocol/Internal/CborWriterPool.cs new file mode 100644 index 000000000000..10b770c43715 --- /dev/null +++ b/extensions/src/AWSSDK.Extensions.CborProtocol/Internal/CborWriterPool.cs @@ -0,0 +1,66 @@ +/* + * 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; +using System.Collections.Concurrent; +using System.Formats.Cbor; +using System.Threading; + +namespace AWSSDK.Extensions.CborProtocol.Internal +{ + public static class CborWriterPool + { + // Internal pool storage using thread-safe collection + private static readonly ConcurrentBag _pool = new ConcurrentBag(); + + // Maximum number of CborWriter instances the pool can hold + private static int _maxPoolSize = 16; + + /// + /// Gets or sets the maximum size of the writer pool. + /// Minimum value is 1. + /// + public static int MaxPoolSize + { + get => Volatile.Read(ref _maxPoolSize); + set => Volatile.Write(ref _maxPoolSize, Math.Max(1, value)); + } + + /// + /// Retrieves a CborWriter from the pool, or creates a new one if the pool is empty. + /// + public static CborWriter Rent() + { + if (_pool.TryTake(out var writer)) + { + return writer; + } + // Create a new CborWriter if the pool is empty + return new CborWriter(CborConformanceMode.Canonical, true); + } + + /// + /// Returns a CborWriter to the pool for reuse. + /// If the pool is already full then the writer will be discard. + /// + public static void Return(CborWriter writer) + { + if (_pool.Count >= Volatile.Read(ref _maxPoolSize)) + return; + + writer.Reset(); // Ensure the writer is in a clean state before pooling + _pool.Add(writer); + } + } +} diff --git a/extensions/src/AWSSDK.Extensions.CborProtocol/Properties/AssemblyInfo.cs b/extensions/src/AWSSDK.Extensions.CborProtocol/Properties/AssemblyInfo.cs new file mode 100644 index 000000000000..d9897716be94 --- /dev/null +++ b/extensions/src/AWSSDK.Extensions.CborProtocol/Properties/AssemblyInfo.cs @@ -0,0 +1,19 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("AWSSDK.Extensions.CborProtocol")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Amazon.com, Inc")] +[assembly: AssemblyProduct("AWS SDK for .NET extensions for Cbor protocol support")] +[assembly: AssemblyDescription("AWS SDK for .NET extensions for Cbor protocol support")] +[assembly: AssemblyCopyright("Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.")] +[assembly: AssemblyTrademark("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +[assembly: AssemblyVersion("4.0")] +[assembly: AssemblyFileVersion("4.0.0.0")] diff --git a/generator/ServiceClientGeneratorLib/GeneratorEnumerations.cs b/generator/ServiceClientGeneratorLib/GeneratorEnumerations.cs index c4893f0ccf9c..4f49f69e46e2 100644 --- a/generator/ServiceClientGeneratorLib/GeneratorEnumerations.cs +++ b/generator/ServiceClientGeneratorLib/GeneratorEnumerations.cs @@ -9,7 +9,7 @@ namespace ServiceClientGenerator /// /// The set of data protocols used by AWS services /// - public enum ServiceType { Json, Query, Rest_Xml, Rest_Json }; + public enum ServiceType { Json, Query, Rest_Xml, Rest_Json, Cbor }; /// /// Where the properties of the request should be placed diff --git a/generator/ServiceClientGeneratorLib/Generators/ProjectFiles/VS2017ProjectFile.cs b/generator/ServiceClientGeneratorLib/Generators/ProjectFiles/VS2017ProjectFile.cs index d6b1b7d76f15..dd55635d6f3e 100644 --- a/generator/ServiceClientGeneratorLib/Generators/ProjectFiles/VS2017ProjectFile.cs +++ b/generator/ServiceClientGeneratorLib/Generators/ProjectFiles/VS2017ProjectFile.cs @@ -16,7 +16,7 @@ namespace ServiceClientGenerator.Generators.ProjectFiles /// Class to produce the template output /// - #line 1 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 1 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] public partial class VS2017ProjectFile : VS2017ProjectFileBase { @@ -29,7 +29,7 @@ public virtual string TransformText() this.Write("\r\n \r\n true\r\n"); - #line 7 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 7 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" if (this.Project.TargetFrameworks.Count() == 1) { @@ -39,14 +39,14 @@ public virtual string TransformText() #line hidden this.Write(" "); - #line 11 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 11 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" this.Write(this.ToStringHelper.ToStringWithCulture(this.Project.TargetFrameworks.Single())); #line default #line hidden this.Write("\r\n"); - #line 12 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 12 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } else @@ -57,14 +57,14 @@ public virtual string TransformText() #line hidden this.Write(" "); - #line 17 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 17 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" this.Write(this.ToStringHelper.ToStringWithCulture(string.Join(";", this.Project.TargetFrameworks))); #line default #line hidden this.Write("\r\n"); - #line 19 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 19 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } @@ -73,14 +73,14 @@ public virtual string TransformText() #line hidden this.Write(" $(DefineConstants);"); - #line 22 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 22 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" this.Write(this.ToStringHelper.ToStringWithCulture(string.Join(";", this.Project.DefineConstants))); #line default #line hidden this.Write("\r\n"); - #line 24 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 24 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" if (this.Project.TargetFrameworks.Contains("netstandard2.0")) { @@ -91,7 +91,7 @@ public virtual string TransformText() this.Write(" $(Defin" + "eConstants);NETSTANDARD20;AWS_ASYNC_ENUMERABLES_API\r\n"); - #line 29 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 29 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } if (this.Project.TargetFrameworks.Contains("netcoreapp3.1")) @@ -103,7 +103,7 @@ public virtual string TransformText() this.Write(" $(Define" + "Constants);AWS_ASYNC_ENUMERABLES_API\r\n"); - #line 35 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 35 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } if (this.Project.TargetFrameworks.Contains("net8.0")) @@ -115,7 +115,7 @@ public virtual string TransformText() this.Write(" $(DefineConstan" + "ts);AWS_ASYNC_ENUMERABLES_API\r\n"); - #line 41 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 41 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } @@ -125,14 +125,14 @@ public virtual string TransformText() this.Write(" portable\r\n true\r\n "); - #line 46 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 46 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" this.Write(this.ToStringHelper.ToStringWithCulture(this.Project.AssemblyName)); #line default #line hidden this.Write("\r\n "); - #line 47 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 47 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" this.Write(this.ToStringHelper.ToStringWithCulture(this.Project.AssemblyName)); #line default @@ -152,8 +152,19 @@ public virtual string TransformText() "); - #line 60 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 60 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + if (this.Project.TargetFrameworks.Contains("netcoreapp3.1") && this.ServiceConfiguration.ServiceModel.Type == ServiceType.Cbor) + { + + + #line default + #line hidden + this.Write(" true\r\n"); + + #line 65 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + + } if (!string.IsNullOrEmpty(this.Project.FrameworkPathOverride)) { @@ -163,14 +174,14 @@ public virtual string TransformText() this.Write(" \r\n " + " "); - #line 65 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 71 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" this.Write(this.ToStringHelper.ToStringWithCulture(this.Project.FrameworkPathOverride)); #line default #line hidden this.Write("\r\n"); - #line 66 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 72 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } @@ -182,14 +193,14 @@ public virtual string TransformText() #line hidden this.Write(" "); - #line 72 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 78 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" this.Write(this.ToStringHelper.ToStringWithCulture(this.Project.SupressWarnings)); #line default #line hidden this.Write("\r\n"); - #line 73 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 79 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } @@ -202,14 +213,14 @@ public virtual string TransformText() this.Write(" false\r" + "\n "); - #line 80 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 86 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" this.Write(this.ToStringHelper.ToStringWithCulture(this.Project.OutputPathOverride)); #line default #line hidden this.Write("\r\n"); - #line 81 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 87 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } @@ -218,7 +229,7 @@ public virtual string TransformText() #line hidden this.Write(" \r\n"); - #line 85 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 91 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" if (this.Project.TargetFrameworks.Contains("netstandard2.0")) { @@ -230,7 +241,7 @@ public virtual string TransformText() "ramework)\' == \'netstandard2.0\'\">\r\n 8.0\r\n \r\n"); - #line 93 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 99 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } @@ -243,7 +254,7 @@ public virtual string TransformText() this.Write(" \r\n " + "true\r\n \r\n"); - #line 102 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 108 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } if (this.Project.AssemblyName.Contains("UnitTests") && this.Project.TargetFrameworks.Contains("net472")) @@ -255,7 +266,7 @@ public virtual string TransformText() this.Write(" \r\n true\r\n \r\n"); - #line 110 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 116 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } @@ -274,7 +285,7 @@ public virtual string TransformText() "); - #line 123 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 129 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" @@ -282,7 +293,7 @@ public virtual string TransformText() #line default #line hidden - #line 126 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 132 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" if (!this.Project.AssemblyName.Contains("UnitTests")) { @@ -293,7 +304,7 @@ public virtual string TransformText() this.Write(" \r\n\t"); - #line 131 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 137 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" this.Write(this.ToStringHelper.ToStringWithCulture(this.Project.FxcopAnalyzerRuleSetFilePath)); #line default @@ -301,14 +312,14 @@ public virtual string TransformText() this.Write("\r\n \r\n \r\n\t"); - #line 134 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 140 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" this.Write(this.ToStringHelper.ToStringWithCulture(this.Project.FxcopAnalyzerRuleSetFilePathForBuild)); #line default #line hidden this.Write("\r\n \r\n\r\n"); - #line 137 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 143 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } if (this.Project.SignBinaries) @@ -320,7 +331,7 @@ public virtual string TransformText() this.Write(" \r\n \r\n " + "\r\n"); - #line 145 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 151 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" if (this.Project.AssemblyName == "AWSSDK.UnitTests.NetFramework") { @@ -331,7 +342,7 @@ public virtual string TransformText() this.Write(" ../../awssdk.dll.snk\r\n"); - #line 150 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 156 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } @@ -339,7 +350,7 @@ public virtual string TransformText() #line default #line hidden - #line 153 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 159 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" else { @@ -352,7 +363,7 @@ public virtual string TransformText() this.Write(" ../../../../awssdk.dll.snk\r\n"); - #line 160 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 166 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } else @@ -364,7 +375,7 @@ public virtual string TransformText() this.Write(" ../../../awssdk.dll.snk\r\n"); - #line 166 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 172 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } } @@ -376,7 +387,7 @@ public virtual string TransformText() " $(AWSKeyFile)\r\n " + "\r\n \r\n \r\n\r\n"); - #line 179 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 185 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } if(this.Project.CustomRoslynAnalyzersDllDirectory != null) @@ -387,14 +398,14 @@ public virtual string TransformText() #line hidden this.Write(" \r\n \r\n"); - #line 187 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 193 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } if(this.Project.IndividualFileIncludes != null) @@ -405,7 +416,7 @@ public virtual string TransformText() #line hidden this.Write(" \r\n"); - #line 193 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 199 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" foreach (var compileIncludeEntry in this.Project.IndividualFileIncludes) { @@ -415,14 +426,14 @@ public virtual string TransformText() #line hidden this.Write(" \r\n"); - #line 202 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 208 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } @@ -443,7 +454,7 @@ public virtual string TransformText() #line hidden this.Write(" \r\n"); - #line 209 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 215 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" foreach (var compileRemoveEntry in this.Project.CompileRemoveList) { @@ -455,21 +466,21 @@ public virtual string TransformText() #line hidden this.Write(" \r\n\r\n"); - #line 227 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 233 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } @@ -503,7 +514,7 @@ public virtual string TransformText() #line default #line hidden - #line 230 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 236 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" if (this.Project.ProjectReferences != null) { @@ -513,7 +524,7 @@ public virtual string TransformText() #line hidden this.Write(" \r\n"); - #line 235 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 241 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" foreach (var projectReference in this.Project.ProjectReferences) { @@ -523,14 +534,14 @@ public virtual string TransformText() #line hidden this.Write(" \r\n\r\n"); - #line 245 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 251 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } @@ -547,7 +558,7 @@ public virtual string TransformText() #line default #line hidden - #line 248 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 254 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" if (this.Project.PackageReferences != null) { @@ -557,7 +568,7 @@ public virtual string TransformText() #line hidden this.Write(" \r\n"); - #line 253 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 259 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" foreach(var package in this.Project.PackageReferences.Where(p => p.IsAnalyzer)) { @@ -569,28 +580,28 @@ public virtual string TransformText() #line hidden this.Write(" \r\n"); - #line 262 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 268 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } else @@ -601,21 +612,21 @@ public virtual string TransformText() #line hidden this.Write("\t \r\n \r\n"); - #line 274 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 280 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" foreach(var package in this.Project.PackageReferences.Where(p => !p.IsAnalyzer)) { @@ -637,28 +648,28 @@ public virtual string TransformText() #line hidden this.Write(" \r\n"); - #line 283 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 289 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } else @@ -669,21 +680,21 @@ public virtual string TransformText() #line hidden this.Write("\t \r\n\r\n"); - #line 295 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 301 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } if (this.Project.ReferenceDependencies != null) @@ -704,7 +715,7 @@ public virtual string TransformText() #line hidden this.Write(" \r\n"); - #line 301 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 307 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" foreach (var reference in this.Project.ReferenceDependencies) { @@ -716,14 +727,14 @@ public virtual string TransformText() #line hidden this.Write(" \r\n\r\n"); - #line 322 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 328 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } if (this.Project.EmbeddedResources != null) @@ -769,7 +780,7 @@ public virtual string TransformText() #line hidden this.Write(" \r\n"); - #line 328 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 334 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" foreach (var resource in this.Project.EmbeddedResources) { @@ -779,14 +790,14 @@ public virtual string TransformText() #line hidden this.Write(" \r\n"); - #line 337 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 343 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } @@ -807,7 +818,7 @@ public virtual string TransformText() #line hidden this.Write(" \r\n"); - #line 344 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 350 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" foreach (var service in this.Project.Services) { @@ -817,14 +828,14 @@ public virtual string TransformText() #line hidden this.Write(" \r\n"); - #line 353 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 359 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" } @@ -844,7 +855,7 @@ public virtual string TransformText() return this.GenerationEnvironment.ToString(); } - #line 359 "C:\Projects\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" + #line 365 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\ProjectFiles\VS2017ProjectFile.tt" public Project Project { get; set; } public ServiceConfiguration ServiceConfiguration { get; set; } diff --git a/generator/ServiceClientGeneratorLib/Generators/ProjectFiles/VS2017ProjectFile.tt b/generator/ServiceClientGeneratorLib/Generators/ProjectFiles/VS2017ProjectFile.tt index 0c2149eda42e..3fd651c4f492 100644 --- a/generator/ServiceClientGeneratorLib/Generators/ProjectFiles/VS2017ProjectFile.tt +++ b/generator/ServiceClientGeneratorLib/Generators/ProjectFiles/VS2017ProjectFile.tt @@ -58,6 +58,12 @@ true <# + if (this.Project.TargetFrameworks.Contains("netcoreapp3.1") && this.ServiceConfiguration.ServiceModel.Type == ServiceType.Cbor) + { +#> + true +<# + } if (!string.IsNullOrEmpty(this.Project.FrameworkPathOverride)) { #> diff --git a/generator/ServiceClientGeneratorLib/ProjectFileCreator.cs b/generator/ServiceClientGeneratorLib/ProjectFileCreator.cs index c61029b7b372..bc45db44736d 100644 --- a/generator/ServiceClientGeneratorLib/ProjectFileCreator.cs +++ b/generator/ServiceClientGeneratorLib/ProjectFileCreator.cs @@ -120,7 +120,7 @@ public void Execute(string serviceFilesRoot, ServiceConfiguration serviceConfigu IncludePath = Utils.PathCombineAlt("..", "..", "Services", dependency, $"AWSSDK.{dependency}.{projectType}.csproj") }); } - + projectReferenceList.Add(new ProjectReference { IncludePath = serviceConfiguration.IsTestService @@ -128,9 +128,18 @@ public void Execute(string serviceFilesRoot, ServiceConfiguration serviceConfigu : Utils.PathCombineAlt("..", "..", "Core", $"AWSSDK.Core.{projectType}.csproj") }); + if (serviceConfiguration.ServiceModel.Type == ServiceType.Cbor) + { + projectReferenceList.Add(new ProjectReference + { + IncludePath = + Utils.PathCombineAlt("..", "..", "..", "..", "extensions", "src", "AWSSDK.Extensions.CborProtocol", $"AWSSDK.Extensions.CborProtocol.{projectType}.csproj") + }); + } + GenerateVS2017ProjectFile(serviceFilesRoot, serviceConfiguration, projectFileConfiguration, projectReferenceList); continue; - } + } var projectFilename = string.Concat(assemblyName, ".", projectType, ".csproj"); bool newProject = false; diff --git a/generator/ServiceClientGeneratorLib/ServiceModel.cs b/generator/ServiceClientGeneratorLib/ServiceModel.cs index 9ddca91dc1fa..543c9b496d22 100644 --- a/generator/ServiceClientGeneratorLib/ServiceModel.cs +++ b/generator/ServiceClientGeneratorLib/ServiceModel.cs @@ -269,6 +269,10 @@ public ServiceType Type { serviceType = "query"; } + else if (serviceType.Equals("smithy-rpc-v2-cbor", StringComparison.InvariantCulture)) + { + serviceType = "cbor"; + } if (!Enum.TryParse(serviceType, true, out ServiceType value)) { @@ -288,6 +292,7 @@ public ServiceType Type /// private readonly List _supportedProtocols = new List { + "smithy-rpc-v2-cbor", "json", "rest-json", "rest-xml", diff --git a/generator/ServiceClientGeneratorLib/SolutionFileCreator.cs b/generator/ServiceClientGeneratorLib/SolutionFileCreator.cs index c6ac40542d59..bfb92314f891 100644 --- a/generator/ServiceClientGeneratorLib/SolutionFileCreator.cs +++ b/generator/ServiceClientGeneratorLib/SolutionFileCreator.cs @@ -364,6 +364,15 @@ private void GenerateVS2017Solution(string solutionFileName, bool includeTests, ProjectGuid = projectGuidDictionary.ContainsKey(projectName) ? projectGuidDictionary[projectName] : Guid.NewGuid().ToString("B").ToUpper(), }); } + + // Add CborProtocol extension to core projects since it is required by some services. + var cborExtensionProjectName = string.Format("AWSSDK.Extensions.CborProtocol.{0}", configuration.Name); + coreProjects.Add(new Project + { + Name = cborExtensionProjectName, + ProjectPath = Utils.PathCombineAlt("..", "extensions", "src", "AWSSDK.Extensions.CborProtocol", $"{ cborExtensionProjectName}.csproj"), + ProjectGuid = projectGuidDictionary.ContainsKey(cborExtensionProjectName) ? projectGuidDictionary[cborExtensionProjectName] : Guid.NewGuid().ToString("B").ToUpper() + }); } IList testProjects = new List(); @@ -444,10 +453,11 @@ private void GenerateVS2017ServiceSolution(IEnumerable var session = new Dictionary(); var serviceSolutionFolders = new List(); var serviceDirectory = new DirectoryInfo(servicePath); - var folder = ServiceSolutionFolderFromPath(serviceDirectory.Name); + var serviceFolder = ServiceSolutionFolderFromPath(serviceDirectory.Name); var solutionFileName = serviceDirectory.Name + ".sln"; var serviceProjectDependencies = new List(); var testProjects = new List(); + var coreDependenciesProjects = new List(CoreProjects); var dependentProjects = new List(); var dependentProjectList = new List(); var solutionPath = Utils.PathCombineAlt(serviceDirectory.ToString(), solutionFileName); @@ -459,7 +469,7 @@ private void GenerateVS2017ServiceSolution(IEnumerable // To prevent all solution files from being modified, we re-use the GUID for the current service (if there's one available). if (projectGuidDictionary.ContainsKey(serviceDirectory.Name)) { - folder.ProjectGuid = projectGuidDictionary[serviceDirectory.Name]; + serviceFolder.ProjectGuid = projectGuidDictionary[serviceDirectory.Name]; } // Include only the service csproj files in the service specific solution. @@ -492,24 +502,33 @@ private void GenerateVS2017ServiceSolution(IEnumerable { filePath = Path.GetFileName(serviceProjectDependency); } - folder.Projects.Add(new Project + var project = new Project { Name = projectName, ProjectPath = filePath, ProjectGuid = projectGuidDictionary.ContainsKey(projectName) ? projectGuidDictionary[projectName] : Guid.NewGuid().ToString("B").ToUpper() - }); + }; + + if (filePath.Contains("AWSSDK.Extensions.")) // Extensions dependencies are added to the core folder not the service. + { + coreDependenciesProjects.Add(project); + } + else + { + serviceFolder.Projects.Add(project); + } } - if (folder.Projects.Count == 0) + if (serviceFolder.Projects.Count == 0) { continue; } ConvertToSlnRelativePath(testProjects, solutionPath); - serviceSolutionFolders.Add(folder); + serviceSolutionFolders.Add(serviceFolder); // Adding core projects to service solution - session["CoreProjects"] = CoreProjects; + session["CoreProjects"] = coreDependenciesProjects; // Adding service projects and its dependencies to the service solution session["ServiceSolutionFolders"] = serviceSolutionFolders; // Adding test projects to the service solution @@ -626,12 +645,12 @@ private List AddProjectDependencies(string projectFile, string serviceNa { var split = fileName.Split(Path.AltDirectorySeparatorChar); - // This is in a different folder in than the usual service dependencies. - // Also skipping the recursion since this does not currently have any ProjectReferences beyond Core - if (fileName.Contains("AWSSDK.Extensions.CrtIntegration")) + // Extensions are in a different folder in than the usual service dependencies. + // Also skipping the recursion since these does not currently have any ProjectReferences beyond Core + if (fileName.Contains("AWSSDK.Extensions.")) { - // Build the relative path to /extensions/src/AWSSDK.Extensions.CrtIntegration/AWSSDK.Extensions.CrtIntegration..csproj + // Build the relative path to /extensions/src/AWSSDK.Extensions.{ExtensionName}/AWSSDK.Extensions.{ExtensionName}..csproj var deps = Utils.PathCombineAlt("..", "..", "..", "..", split[split.Length - 4], split[split.Length - 3], split[split.Length - 2], split[split.Length - 1]); depsProjects.Add(deps); } diff --git a/sdk/AWSSDK.NetFramework.sln b/sdk/AWSSDK.NetFramework.sln index 76522c6a988c..fe4422551357 100644 --- a/sdk/AWSSDK.NetFramework.sln +++ b/sdk/AWSSDK.NetFramework.sln @@ -6,6 +6,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{9863FCB3-B EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.Core.NetFramework", "src/Core/AWSSDK.Core.NetFramework.csproj", "{1827E98F-AAD5-4354-897D-C64DA0F95495}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.Extensions.CborProtocol.NetFramework", "../extensions/src/AWSSDK.Extensions.CborProtocol/AWSSDK.Extensions.CborProtocol.NetFramework.csproj", "{139614FF-5A7B-4277-BFD3-234D04D3E149}" +EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Services", "Services", "{939EC5C2-8345-43E2-8F97-72EEEBEEA0AB}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AccessAnalyzer", "AccessAnalyzer", "{D35E1267-0F99-4C3C-BC76-23E855530127}" @@ -1792,6 +1794,10 @@ Global {1827E98F-AAD5-4354-897D-C64DA0F95495}.Debug|Any CPU.Build.0 = Debug|Any CPU {1827E98F-AAD5-4354-897D-C64DA0F95495}.Release|Any CPU.ActiveCfg = Release|Any CPU {1827E98F-AAD5-4354-897D-C64DA0F95495}.Release|Any CPU.Build.0 = Release|Any CPU + {139614FF-5A7B-4277-BFD3-234D04D3E149}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {139614FF-5A7B-4277-BFD3-234D04D3E149}.Debug|Any CPU.Build.0 = Debug|Any CPU + {139614FF-5A7B-4277-BFD3-234D04D3E149}.Release|Any CPU.ActiveCfg = Release|Any CPU + {139614FF-5A7B-4277-BFD3-234D04D3E149}.Release|Any CPU.Build.0 = Release|Any CPU {C9E03D46-8113-4476-8B66-69A307DC193E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C9E03D46-8113-4476-8B66-69A307DC193E}.Debug|Any CPU.Build.0 = Debug|Any CPU {C9E03D46-8113-4476-8B66-69A307DC193E}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -3586,6 +3592,7 @@ Global EndGlobalSection GlobalSection(NestedProjects) = preSolution {1827E98F-AAD5-4354-897D-C64DA0F95495} = {9863FCB3-BFA4-4B9C-B8F6-302BA5F660B8} + {139614FF-5A7B-4277-BFD3-234D04D3E149} = {9863FCB3-BFA4-4B9C-B8F6-302BA5F660B8} {D35E1267-0F99-4C3C-BC76-23E855530127} = {939EC5C2-8345-43E2-8F97-72EEEBEEA0AB} {C9E03D46-8113-4476-8B66-69A307DC193E} = {D35E1267-0F99-4C3C-BC76-23E855530127} {952ED7BB-663B-47BD-B5D9-393AF6BFF3E5} = {939EC5C2-8345-43E2-8F97-72EEEBEEA0AB} diff --git a/sdk/AWSSDK.NetStandard.sln b/sdk/AWSSDK.NetStandard.sln index 546d1369d07c..2ee3dc97ff70 100644 --- a/sdk/AWSSDK.NetStandard.sln +++ b/sdk/AWSSDK.NetStandard.sln @@ -6,6 +6,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{9863FCB3-B EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.Core.NetStandard", "src/Core/AWSSDK.Core.NetStandard.csproj", "{15BB19BE-ABCA-441F-8217-3AE9A993B5E7}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AWSSDK.Extensions.CborProtocol.NetStandard", "../extensions/src/AWSSDK.Extensions.CborProtocol/AWSSDK.Extensions.CborProtocol.NetStandard.csproj", "{5AB6FB6A-C197-41DD-A6FF-21576B5859FB}" +EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Services", "Services", "{939EC5C2-8345-43E2-8F97-72EEEBEEA0AB}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AccessAnalyzer", "AccessAnalyzer", "{CDEDFA0E-9192-5F7F-200A-5329D35913C5}" @@ -1788,6 +1790,10 @@ Global {15BB19BE-ABCA-441F-8217-3AE9A993B5E7}.Debug|Any CPU.Build.0 = Debug|Any CPU {15BB19BE-ABCA-441F-8217-3AE9A993B5E7}.Release|Any CPU.ActiveCfg = Release|Any CPU {15BB19BE-ABCA-441F-8217-3AE9A993B5E7}.Release|Any CPU.Build.0 = Release|Any CPU + {5AB6FB6A-C197-41DD-A6FF-21576B5859FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5AB6FB6A-C197-41DD-A6FF-21576B5859FB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5AB6FB6A-C197-41DD-A6FF-21576B5859FB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5AB6FB6A-C197-41DD-A6FF-21576B5859FB}.Release|Any CPU.Build.0 = Release|Any CPU {81A3EBDE-824D-458E-9ABF-359E5B32B773}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {81A3EBDE-824D-458E-9ABF-359E5B32B773}.Debug|Any CPU.Build.0 = Debug|Any CPU {81A3EBDE-824D-458E-9ABF-359E5B32B773}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -3578,6 +3584,7 @@ Global EndGlobalSection GlobalSection(NestedProjects) = preSolution {15BB19BE-ABCA-441F-8217-3AE9A993B5E7} = {9863FCB3-BFA4-4B9C-B8F6-302BA5F660B8} + {5AB6FB6A-C197-41DD-A6FF-21576B5859FB} = {9863FCB3-BFA4-4B9C-B8F6-302BA5F660B8} {CDEDFA0E-9192-5F7F-200A-5329D35913C5} = {939EC5C2-8345-43E2-8F97-72EEEBEEA0AB} {81A3EBDE-824D-458E-9ABF-359E5B32B773} = {CDEDFA0E-9192-5F7F-200A-5329D35913C5} {AEF6C919-A19B-DF6C-2AEC-8537B2BEE229} = {939EC5C2-8345-43E2-8F97-72EEEBEEA0AB} From 047776ade061e4d8d477583acc1abc0798bedd54 Mon Sep 17 00:00:00 2001 From: Muhammad Othman Date: Thu, 19 Jun 2025 11:46:21 -0400 Subject: [PATCH 02/15] Add Cbor request and structure marshallers generators --- .../CborWriterExtensions.cs | 51 +- .../GeneratorDriver.cs | 14 +- .../Marshallers/CborRequestMarshaller.cs | 343 ++++ .../Marshallers/CborRequestMarshaller.tt | 162 ++ .../Marshallers/CborStructureMarshaller.cs | 1502 +++++++++++++++++ .../Marshallers/CborStructureMarshaller.tt | 276 +++ .../ServiceClientGeneratorLib.csproj | 49 + 7 files changed, 2380 insertions(+), 17 deletions(-) create mode 100644 generator/ServiceClientGeneratorLib/Generators/Marshallers/CborRequestMarshaller.cs create mode 100644 generator/ServiceClientGeneratorLib/Generators/Marshallers/CborRequestMarshaller.tt create mode 100644 generator/ServiceClientGeneratorLib/Generators/Marshallers/CborStructureMarshaller.cs create mode 100644 generator/ServiceClientGeneratorLib/Generators/Marshallers/CborStructureMarshaller.tt diff --git a/extensions/src/AWSSDK.Extensions.CborProtocol/CborWriterExtensions.cs b/extensions/src/AWSSDK.Extensions.CborProtocol/CborWriterExtensions.cs index e06250550e71..06411c538fe0 100644 --- a/extensions/src/AWSSDK.Extensions.CborProtocol/CborWriterExtensions.cs +++ b/extensions/src/AWSSDK.Extensions.CborProtocol/CborWriterExtensions.cs @@ -12,16 +12,10 @@ * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ -using Amazon.Runtime; -using Amazon.Runtime.Internal; -using Amazon.Runtime.Internal.Transform; -using Amazon.Runtime.Internal.Util; -using Amazon.Util; + using System; -using System.Collections.Generic; using System.Formats.Cbor; -using System.IO; -using System.Text.RegularExpressions; +using Amazon.Util; namespace AWSSDK.Extensions.CborProtocol { @@ -47,57 +41,82 @@ public static void WriteOptimizedNumber(this CborWriter writer, double value) { if (double.IsNaN(value) || double.IsInfinity(value)) { - writer.WriteDouble(value); + writer.WriteDouble(value); // Write NaN or Infinity as a double. return; } + // If the value is an integer (without fractional part), write it as Int64 or UInt64. if (value % 1 == 0) { if (value >= long.MinValue && value <= long.MaxValue) { + // If the value fits within the signed 64-bit integer (long) range, + // WriteInt64 serializes it into the smallest CBOR type representation + // that can contain its value without loss of precision. writer.WriteInt64((long)value); return; } if (value >= 0 && value <= ulong.MaxValue) { + // If the value is non-negative and fits within the unsigned 64-bit range, + // WriteUInt64 serializes it into the smallest possible CBOR type representation. writer.WriteUInt64((ulong)value); return; } } + // Check if value can safely be represented as float32 + float floatCandidate = (float)value; + if ((double)floatCandidate == value) + { + WriteOptimizedNumber(writer, floatCandidate); + return; + } + + // If none of the above conditions are satisfied, write the value as a double. writer.WriteDouble(value); } /// /// Writes a float using the smallest CBOR representation that preserves value and precision. + /// This method uses manual encoding to avoid writing as a half-precision float. /// /// The CBOR writer to use. /// The float value to write. public static void WriteOptimizedNumber(this CborWriter writer, float value) { - if (float.IsNaN(value) || float.IsInfinity(value)) - { - writer.WriteSingle(value); - return; - } - + // If the value is an integer (without fractional part), write it as Int64 or UInt64. if (value % 1 == 0) { if (value >= long.MinValue && value <= long.MaxValue) { + // If the value fits within the signed 64-bit integer (long) range, + // WriteInt64 serializes it into the smallest CBOR type representation + // that can contain its value without loss of precision. writer.WriteInt64((long)value); return; } if (value >= 0 && value <= ulong.MaxValue) { + // If the value is non-negative and fits within the unsigned 64-bit range, + // WriteUInt64 serializes it into the smallest possible CBOR type representation. writer.WriteUInt64((ulong)value); return; } } - writer.WriteSingle(value); + // Manual encoding to avoid half-precision floats + var bytes = new byte[5]; + bytes[0] = 0xFA; // CBOR float32 marker + BitConverter.GetBytes(value).CopyTo(bytes, 1); + + // Ensure the bytes are in the correct endian order for CBOR. + if (BitConverter.IsLittleEndian) + Array.Reverse(bytes, 1, 4); + + writer.WriteEncodedValue(bytes); } } } diff --git a/generator/ServiceClientGeneratorLib/GeneratorDriver.cs b/generator/ServiceClientGeneratorLib/GeneratorDriver.cs index c9c5f7f24f9f..3b89aea5ae74 100644 --- a/generator/ServiceClientGeneratorLib/GeneratorDriver.cs +++ b/generator/ServiceClientGeneratorLib/GeneratorDriver.cs @@ -1402,7 +1402,7 @@ internal static bool WriteFile(string baseOutputDir, /// Sets the marshaller of the generator based on the service type /// /// The marshaller to be set - /// If the service type is a type of json then normalizeMarshallers is set to true, false otherwise + /// If the service type is using structure marshallers then normalizeMarshallers is set to true, false otherwise void GetRequestMarshaller(out BaseRequestMarshaller marshaller, out bool normalizeMarshallers) { normalizeMarshallers = false; @@ -1413,6 +1413,10 @@ void GetRequestMarshaller(out BaseRequestMarshaller marshaller, out bool normali marshaller = new JsonRPCRequestMarshaller(); normalizeMarshallers = true; break; + case ServiceType.Cbor: + marshaller = new CborRequestMarshaller(); + normalizeMarshallers = true; + break; case ServiceType.Query: marshaller = new AWSQueryRequestMarshaller(); break; @@ -1435,6 +1439,8 @@ BaseRequestMarshaller GetStructureMarshaller() case ServiceType.Rest_Json: case ServiceType.Json: return new JsonRPCStructureMarshaller(); + case ServiceType.Cbor: + return new CborStructureMarshaller(); default: throw new Exception("No structure marshaller for service type: " + this.Configuration.ServiceModel.Type); } @@ -1456,6 +1462,8 @@ BaseResponseUnmarshaller GetResponseUnmarshaller() return new AWSQueryResponseUnmarshaller(); case ServiceType.Rest_Xml: return new RestXmlResponseUnmarshaller(); + case ServiceType.Cbor: + return new CborResponseUnmarshaller(); default: throw new Exception("No response unmarshaller for service type: " + this.Configuration.ServiceModel.Type); } @@ -1476,6 +1484,8 @@ BaseResponseUnmarshaller GetStructureUnmarshaller() return new AWSQueryStructureUnmarshaller(); case ServiceType.Rest_Xml: return new RestXmlStructureUnmarshaller(); + case ServiceType.Cbor: + return new CborStructureUnmarshaller(); default: throw new Exception("No structure unmarshaller for service type: " + this.Configuration.ServiceModel.Type); } @@ -1495,6 +1505,8 @@ BaseResponseUnmarshaller GetExceptionUnmarshaller() return new AWSQueryExceptionUnmarshaller(); case ServiceType.Rest_Xml: return new RestXmlExceptionUnmarshaller(); + case ServiceType.Cbor: + return new CborExceptionUnmarshaller(); default: throw new Exception("No structure unmarshaller for service type: " + this.Configuration.ServiceModel.Type); } diff --git a/generator/ServiceClientGeneratorLib/Generators/Marshallers/CborRequestMarshaller.cs b/generator/ServiceClientGeneratorLib/Generators/Marshallers/CborRequestMarshaller.cs new file mode 100644 index 000000000000..a2bff38135c3 --- /dev/null +++ b/generator/ServiceClientGeneratorLib/Generators/Marshallers/CborRequestMarshaller.cs @@ -0,0 +1,343 @@ +// ------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version: 17.0.0.0 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ------------------------------------------------------------------------------ +namespace ServiceClientGenerator.Generators.Marshallers +{ + using System.Linq; + using System.Text; + using System.Collections.Generic; + using System; + + /// + /// Class to produce the template output + /// + + #line 1 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborRequestMarshaller.tt" + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")] + public partial class CborRequestMarshaller : CborStructureMarshaller + { +#line hidden + /// + /// Create the template output + /// + public override string TransformText() + { + + #line 6 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborRequestMarshaller.tt" + + AddLicenseHeader(); + + AddCommonUsingStatements(); + + + #line default + #line hidden + this.Write("using AWSSDK.Extensions.CborProtocol;\r\nusing AWSSDK.Extensions.CborProtocol.Inter" + + "nal;\r\n\r\n#pragma warning disable CS0612,CS0618\r\nnamespace "); + + #line 15 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborRequestMarshaller.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(this.Config.Namespace)); + + #line default + #line hidden + this.Write(".Model.Internal.MarshallTransformations\r\n{\r\n\t/// \r\n\t/// "); + + #line 18 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborRequestMarshaller.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(this.Operation.Name)); + + #line default + #line hidden + this.Write(" Request Marshaller\r\n\t/// \r\n\tpublic class "); + + #line 20 "C:\repos\aws-sdk-net-v4\generator\ServiceClientGeneratorLib\Generators\Marshallers\CborRequestMarshaller.tt" + this.Write(this.ToStringHelper.ToStringWithCulture(this.Operation.Name)); + + #line default + #line hidden + this.Write("RequestMarshaller : IMarshaller