Skip to content

Commit

Permalink
Generated SQS changes as an example
Browse files Browse the repository at this point in the history
  • Loading branch information
peterrsongg committed Nov 19, 2024
1 parent 1732fba commit ebc898a
Show file tree
Hide file tree
Showing 86 changed files with 1,576 additions and 1,454 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
using Amazon.Runtime.Internal;
using Amazon.Runtime.Internal.Transform;
using Amazon.Runtime.Internal.Util;
using ThirdParty.Json.LitJson;

using System.Text.Json;
using System.Buffers;
#pragma warning disable CS0612,CS0618
namespace Amazon.SQS.Model.Internal.MarshallTransformations
{
Expand Down Expand Up @@ -63,54 +63,58 @@ public IRequest Marshall(AddPermissionRequest publicRequest)
request.HttpMethod = "POST";

request.ResourcePath = "/";
using (MemoryStream memoryStream = new MemoryStream())
#if NETCOREAPP3_1_OR_GREATER
ArrayBufferWriter<byte> arrayBufferWriter = new ArrayBufferWriter<byte>();
using Utf8JsonWriter writer = new Utf8JsonWriter(arrayBufferWriter);
#else
using var memoryStream = new MemoryStream();
using Utf8JsonWriter writer = new Utf8JsonWriter(memoryStream);
#endif
writer.WriteStartObject();
var context = new JsonMarshallerContext(request, writer);
if(publicRequest.IsSetActions())
{
using (StreamWriter streamWriter = new InvariantCultureStreamWriter(memoryStream))
context.Writer.WritePropertyName("Actions");
context.Writer.WriteStartArray();
foreach(var publicRequestActionsListValue in publicRequest.Actions)
{
JsonWriter writer = new JsonWriter(streamWriter);
writer.Validate = false;
writer.WriteObjectStart();
var context = new JsonMarshallerContext(request, writer);
if(publicRequest.IsSetActions())
{
context.Writer.WritePropertyName("Actions");
context.Writer.WriteArrayStart();
foreach(var publicRequestActionsListValue in publicRequest.Actions)
{
context.Writer.Write(publicRequestActionsListValue);
}
context.Writer.WriteArrayEnd();
}

if(publicRequest.IsSetAWSAccountIds())
{
context.Writer.WritePropertyName("AWSAccountIds");
context.Writer.WriteArrayStart();
foreach(var publicRequestAWSAccountIdsListValue in publicRequest.AWSAccountIds)
{
context.Writer.Write(publicRequestAWSAccountIdsListValue);
}
context.Writer.WriteArrayEnd();
}

if(publicRequest.IsSetLabel())
{
context.Writer.WritePropertyName("Label");
context.Writer.Write(publicRequest.Label);
}

if(publicRequest.IsSetQueueUrl())
{
context.Writer.WritePropertyName("QueueUrl");
context.Writer.Write(publicRequest.QueueUrl);
}
context.Writer.WriteStringValue(publicRequestActionsListValue);
}
context.Writer.WriteEndArray();
}

writer.WriteObjectEnd();
if(publicRequest.IsSetAWSAccountIds())
{
context.Writer.WritePropertyName("AWSAccountIds");
context.Writer.WriteStartArray();
foreach(var publicRequestAWSAccountIdsListValue in publicRequest.AWSAccountIds)
{
context.Writer.WriteStringValue(publicRequestAWSAccountIdsListValue);
}
context.Writer.WriteEndArray();
}

request.Content = memoryStream.ToArray();
if(publicRequest.IsSetLabel())
{
context.Writer.WritePropertyName("Label");
context.Writer.WriteStringValue(publicRequest.Label);
}

if(publicRequest.IsSetQueueUrl())
{
context.Writer.WritePropertyName("QueueUrl");
context.Writer.WriteStringValue(publicRequest.QueueUrl);
}

writer.WriteEndObject();
writer.Flush();
#if NETCOREAPP3_1_OR_GREATER
request.Content = arrayBufferWriter.WrittenMemory.ToArray();
#else
request.Content = memoryStream.ToArray();
#endif



return request;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
using Amazon.Runtime.Internal.Transform;
using Amazon.Runtime.Internal.Util;
using ThirdParty.Json.LitJson;

using System.Text.Json;
using Amazon.Util;
#pragma warning disable CS0612,CS0618
namespace Amazon.SQS.Model.Internal.MarshallTransformations
{
Expand All @@ -48,7 +49,6 @@ public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext cont
{
AddPermissionResponse response = new AddPermissionResponse();


return response;
}

Expand All @@ -61,39 +61,40 @@ public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext cont
/// <returns></returns>
public override AmazonServiceException UnmarshallException(JsonUnmarshallerContext context, Exception innerException, HttpStatusCode statusCode)
{
var errorResponse = JsonErrorResponseUnmarshaller.GetInstance().Unmarshall(context);
StreamingUtf8JsonReader reader = new StreamingUtf8JsonReader(context.Stream);
var errorResponse = JsonErrorResponseUnmarshaller.GetInstance().Unmarshall(context, ref reader);
errorResponse.InnerException = innerException;
errorResponse.StatusCode = statusCode;

var responseBodyBytes = context.GetResponseBodyBytes();

using (var streamCopy = new MemoryStream(responseBodyBytes))

using (var contextCopy = new JsonUnmarshallerContext(streamCopy, true, context.ResponseData))
{
StreamingUtf8JsonReader readerCopy = new StreamingUtf8JsonReader(streamCopy);
if (errorResponse.Code != null && errorResponse.Code.Equals("InvalidAddress"))
{
return InvalidAddressExceptionUnmarshaller.Instance.Unmarshall(contextCopy, errorResponse);
return InvalidAddressExceptionUnmarshaller.Instance.Unmarshall(contextCopy, errorResponse, ref readerCopy);
}
if (errorResponse.Code != null && errorResponse.Code.Equals("InvalidSecurity"))
{
return InvalidSecurityExceptionUnmarshaller.Instance.Unmarshall(contextCopy, errorResponse);
return InvalidSecurityExceptionUnmarshaller.Instance.Unmarshall(contextCopy, errorResponse, ref readerCopy);
}
if (errorResponse.Code != null && errorResponse.Code.Equals("OverLimit"))
{
return OverLimitExceptionUnmarshaller.Instance.Unmarshall(contextCopy, errorResponse);
return OverLimitExceptionUnmarshaller.Instance.Unmarshall(contextCopy, errorResponse, ref readerCopy);
}
if (errorResponse.Code != null && errorResponse.Code.Equals("QueueDoesNotExist"))
{
return QueueDoesNotExistExceptionUnmarshaller.Instance.Unmarshall(contextCopy, errorResponse);
return QueueDoesNotExistExceptionUnmarshaller.Instance.Unmarshall(contextCopy, errorResponse, ref readerCopy);
}
if (errorResponse.Code != null && errorResponse.Code.Equals("RequestThrottled"))
{
return RequestThrottledExceptionUnmarshaller.Instance.Unmarshall(contextCopy, errorResponse);
return RequestThrottledExceptionUnmarshaller.Instance.Unmarshall(contextCopy, errorResponse, ref readerCopy);
}
if (errorResponse.Code != null && errorResponse.Code.Equals("UnsupportedOperation"))
{
return UnsupportedOperationExceptionUnmarshaller.Instance.Unmarshall(contextCopy, errorResponse);
return UnsupportedOperationExceptionUnmarshaller.Instance.Unmarshall(contextCopy, errorResponse, ref readerCopy);
}
}
var errorCode = errorResponse.Code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,37 @@
using Amazon.Runtime.Internal;
using Amazon.Runtime.Internal.Transform;
using Amazon.Runtime.Internal.Util;
using ThirdParty.Json.LitJson;

using System.Text.Json;
using Amazon.Util;
#pragma warning disable CS0612,CS0618
namespace Amazon.SQS.Model.Internal.MarshallTransformations
{
/// <summary>
/// Response Unmarshaller for BatchEntryIdsNotDistinctException Object
/// </summary>
public class BatchEntryIdsNotDistinctExceptionUnmarshaller : IErrorResponseUnmarshaller<BatchEntryIdsNotDistinctException, JsonUnmarshallerContext>
public class BatchEntryIdsNotDistinctExceptionUnmarshaller : IJsonErrorResponseUnmarshaller<BatchEntryIdsNotDistinctException, JsonUnmarshallerContext>
{
/// <summary>
/// Unmarshaller the response from the service to the response class.
/// </summary>
/// <param name="context"></param>
/// <param name="reader"></param>
/// <returns></returns>
public BatchEntryIdsNotDistinctException Unmarshall(JsonUnmarshallerContext context)
public BatchEntryIdsNotDistinctException Unmarshall(JsonUnmarshallerContext context, ref StreamingUtf8JsonReader reader)
{
return this.Unmarshall(context, new Amazon.Runtime.Internal.ErrorResponse());
return this.Unmarshall(context, new Amazon.Runtime.Internal.ErrorResponse(), ref reader);
}

/// <summary>
/// Unmarshaller the response from the service to the response class.
/// </summary>
/// <param name="context"></param>
/// <param name="errorResponse"></param>
/// <param name="reader"></param>
/// <returns></returns>
public BatchEntryIdsNotDistinctException Unmarshall(JsonUnmarshallerContext context, Amazon.Runtime.Internal.ErrorResponse errorResponse)
public BatchEntryIdsNotDistinctException Unmarshall(JsonUnmarshallerContext context, Amazon.Runtime.Internal.ErrorResponse errorResponse, ref StreamingUtf8JsonReader reader)
{
context.Read();
context.Read(ref reader);

var errorCode = errorResponse.Code;
var errorType = errorResponse.Type;
Expand All @@ -83,7 +85,7 @@ public BatchEntryIdsNotDistinctException Unmarshall(JsonUnmarshallerContext cont
errorType, errorCode, errorResponse.RequestId, errorResponse.StatusCode);

int targetDepth = context.CurrentDepth;
while (context.ReadAtDepth(targetDepth))
while (context.ReadAtDepth(targetDepth, ref reader))
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,37 @@
using Amazon.Runtime.Internal;
using Amazon.Runtime.Internal.Transform;
using Amazon.Runtime.Internal.Util;
using ThirdParty.Json.LitJson;

using System.Text.Json;
using Amazon.Util;
#pragma warning disable CS0612,CS0618
namespace Amazon.SQS.Model.Internal.MarshallTransformations
{
/// <summary>
/// Response Unmarshaller for BatchRequestTooLongException Object
/// </summary>
public class BatchRequestTooLongExceptionUnmarshaller : IErrorResponseUnmarshaller<BatchRequestTooLongException, JsonUnmarshallerContext>
public class BatchRequestTooLongExceptionUnmarshaller : IJsonErrorResponseUnmarshaller<BatchRequestTooLongException, JsonUnmarshallerContext>
{
/// <summary>
/// Unmarshaller the response from the service to the response class.
/// </summary>
/// <param name="context"></param>
/// <param name="reader"></param>
/// <returns></returns>
public BatchRequestTooLongException Unmarshall(JsonUnmarshallerContext context)
public BatchRequestTooLongException Unmarshall(JsonUnmarshallerContext context, ref StreamingUtf8JsonReader reader)
{
return this.Unmarshall(context, new Amazon.Runtime.Internal.ErrorResponse());
return this.Unmarshall(context, new Amazon.Runtime.Internal.ErrorResponse(), ref reader);
}

/// <summary>
/// Unmarshaller the response from the service to the response class.
/// </summary>
/// <param name="context"></param>
/// <param name="errorResponse"></param>
/// <param name="reader"></param>
/// <returns></returns>
public BatchRequestTooLongException Unmarshall(JsonUnmarshallerContext context, Amazon.Runtime.Internal.ErrorResponse errorResponse)
public BatchRequestTooLongException Unmarshall(JsonUnmarshallerContext context, Amazon.Runtime.Internal.ErrorResponse errorResponse, ref StreamingUtf8JsonReader reader)
{
context.Read();
context.Read(ref reader);

var errorCode = errorResponse.Code;
var errorType = errorResponse.Type;
Expand All @@ -83,7 +85,7 @@ public BatchRequestTooLongException Unmarshall(JsonUnmarshallerContext context,
errorType, errorCode, errorResponse.RequestId, errorResponse.StatusCode);

int targetDepth = context.CurrentDepth;
while (context.ReadAtDepth(targetDepth))
while (context.ReadAtDepth(targetDepth, ref reader))
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,65 +29,56 @@
using Amazon.Runtime.Internal;
using Amazon.Runtime.Internal.Transform;
using Amazon.Runtime.Internal.Util;
using ThirdParty.Json.LitJson;
using System.Text.Json;

#pragma warning disable CS0612,CS0618
namespace Amazon.SQS.Model.Internal.MarshallTransformations
{
/// <summary>
/// Response Unmarshaller for BatchResultErrorEntry Object
/// </summary>
public class BatchResultErrorEntryUnmarshaller : IUnmarshaller<BatchResultErrorEntry, XmlUnmarshallerContext>, IUnmarshaller<BatchResultErrorEntry, JsonUnmarshallerContext>
public class BatchResultErrorEntryUnmarshaller : IJsonUnmarshaller<BatchResultErrorEntry, JsonUnmarshallerContext>
{
/// <summary>
/// Unmarshaller the response from the service to the response class.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
BatchResultErrorEntry IUnmarshaller<BatchResultErrorEntry, XmlUnmarshallerContext>.Unmarshall(XmlUnmarshallerContext context)
{
throw new NotImplementedException();
}

/// <summary>
/// Unmarshaller the response from the service to the response class.
/// </summary>
/// <param name="context"></param>
/// <param name="reader"></param>
/// <returns>The unmarshalled object</returns>
public BatchResultErrorEntry Unmarshall(JsonUnmarshallerContext context)
public BatchResultErrorEntry Unmarshall(JsonUnmarshallerContext context, ref StreamingUtf8JsonReader reader)
{
BatchResultErrorEntry unmarshalledObject = new BatchResultErrorEntry();
if (context.IsEmptyResponse)
return null;
context.Read();
if (context.CurrentTokenType == JsonToken.Null)
context.Read(ref reader);
if (context.CurrentTokenType == JsonTokenType.Null)
return null;

int targetDepth = context.CurrentDepth;
while (context.ReadAtDepth(targetDepth))
while (context.ReadAtDepth(targetDepth, ref reader))
{
if (context.TestExpression("Code", targetDepth))
{
var unmarshaller = StringUnmarshaller.Instance;
unmarshalledObject.Code = unmarshaller.Unmarshall(context);
unmarshalledObject.Code = unmarshaller.Unmarshall(context, ref reader);
continue;
}
if (context.TestExpression("Id", targetDepth))
{
var unmarshaller = StringUnmarshaller.Instance;
unmarshalledObject.Id = unmarshaller.Unmarshall(context);
unmarshalledObject.Id = unmarshaller.Unmarshall(context, ref reader);
continue;
}
if (context.TestExpression("Message", targetDepth))
{
var unmarshaller = StringUnmarshaller.Instance;
unmarshalledObject.Message = unmarshaller.Unmarshall(context);
unmarshalledObject.Message = unmarshaller.Unmarshall(context, ref reader);
continue;
}
if (context.TestExpression("SenderFault", targetDepth))
{
var unmarshaller = NullableBoolUnmarshaller.Instance;
unmarshalledObject.SenderFault = unmarshaller.Unmarshall(context);
unmarshalledObject.SenderFault = unmarshaller.Unmarshall(context, ref reader);
continue;
}
}
Expand Down
Loading

0 comments on commit ebc898a

Please sign in to comment.