Skip to content

Commit

Permalink
(#14) nuar: test ussage of messagePack [pack-all-force]
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintAngeLs committed Sep 29, 2024
1 parent 1c26707 commit 75bd726
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/Nuar/src/Nuar/Nuar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
</None>

<FrameworkReference Include="Microsoft.AspNetCore.App" />

<PackageReference Include="MessagePack" Version="2.5.172" />
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="2.2.2" />
Expand Down
31 changes: 14 additions & 17 deletions src/Nuar/src/Nuar/Requests/PayloadTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using NetJSON;
using MessagePack;
using Nuar.Options;
using Route = Nuar.Configuration.Route;

Expand All @@ -27,20 +27,11 @@ public PayloadTransformer(NuarOptions options, IPayloadManager payloadManager, I

public bool HasTransformations(string resourceId, Route route)
{
// Check if the resource ID exists
if (!string.IsNullOrWhiteSpace(resourceId))
{
return true;
}
// Skip payload processing for GET requests or routes without transformation
if (route.Method.ToLowerInvariant() == "get")
return false;

// Check if route binds exist
if (route.Bind != null && route.Bind.Any())
{
return true;
}

// Check if there are any transformations
if (route.Transform != null && route.Transform.Any())
if (!string.IsNullOrWhiteSpace(resourceId) || route.Bind != null && route.Bind.Any() || route.Transform != null && route.Transform.Any())
{
return true;
}
Expand All @@ -51,6 +42,12 @@ public bool HasTransformations(string resourceId, Route route)

public PayloadSchema Transform(string payload, string resourceId, Route route, HttpRequest request, RouteData data)
{
// Skip transformation for GET requests
if (route.Method.ToLowerInvariant() == "get")
{
return null;
}

var payloadKey = GetPayloadKey(route);
var command = _payloads.ContainsKey(payloadKey)
? GetObjectFromPayload(route, payload)
Expand Down Expand Up @@ -111,7 +108,7 @@ public PayloadSchema Transform(string payload, string resourceId, Route route, H
private object GetObjectFromPayload(Route route, string content)
{
var payloadValue = _payloads[GetPayloadKey(route)].Payload;
var request = NetJSON.NetJSON.Deserialize(payloadValue.GetType(), content);
var request = MessagePackSerializer.Deserialize(payloadValue.GetType(), System.Text.Encoding.UTF8.GetBytes(content));

var payloadValues = (IDictionary<string, object>)payloadValue;
var requestValues = (IDictionary<string, object>)request;
Expand All @@ -130,8 +127,8 @@ private object GetObjectFromPayload(Route route, string content)

private static object GetObject(string content)
{
// Deserialize directly to an ExpandoObject using NetJSON
return NetJSON.NetJSON.Deserialize<ExpandoObject>(content);
// Deserialize directly to an ExpandoObject using MessagePack
return MessagePackSerializer.Deserialize<ExpandoObject>(System.Text.Encoding.UTF8.GetBytes(content));
}

private string GetPayloadKey(Route route)
Expand Down
2 changes: 1 addition & 1 deletion src/Nuar/src/Nuar/obj/Debug/net9.0/Nuar.AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
[assembly: System.Reflection.AssemblyCopyrightAttribute("ITSharpPro © ")]
[assembly: System.Reflection.AssemblyDescriptionAttribute("Nuar - A framework for building API gateways in a microservices architecture")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+98aec01653883b77d79363dc0cb9c8642aed0ee1")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+1c267071c9e105f917ff8b6455cddb0d8d968c41")]
[assembly: System.Reflection.AssemblyProductAttribute("Nuar")]
[assembly: System.Reflection.AssemblyTitleAttribute("Nuar")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f5657c688c2db74647cbb018bce61daf836b7962dd555a348e867b98a4cf9c62
b5fc7bfd25e567d26982fac35ae5267766c22f5a82928e0604d6141a51e6344e

0 comments on commit 75bd726

Please sign in to comment.