From d48ac20f7d1e25779a771969b93fe011a2493e34 Mon Sep 17 00:00:00 2001 From: Mihail Mitrovanov Date: Wed, 14 May 2025 12:58:14 +0300 Subject: [PATCH] Cbor bug fixes --- Example.Backend/Printer.cs | 6 ++++++ Example.Frontend/ClientBasedPrinter.cs | 5 +++++ Example.Frontend/Program.cs | 5 +++++ Example.Shared/IPrinter.cs | 1 + mROA.Cbor/PreParsedValue.cs | 15 +++++++++++++++ mROA.Cbor/mROA.Cbor.csproj | 3 +++ 6 files changed, 35 insertions(+) diff --git a/Example.Backend/Printer.cs b/Example.Backend/Printer.cs index dba9a98..9e9bb07 100644 --- a/Example.Backend/Printer.cs +++ b/Example.Backend/Printer.cs @@ -15,6 +15,12 @@ namespace Example.Backend Console.WriteLine(humanName + " is approaching"); } + public Task SetFingerPrint(int[] fingerPrint) + { + Console.WriteLine(fingerPrint.Length); + return Task.CompletedTask; + } + public void OnPrintExternal(IPage p0, RequestContext ro) { OnPrint?.Invoke(p0, ro); diff --git a/Example.Frontend/ClientBasedPrinter.cs b/Example.Frontend/ClientBasedPrinter.cs index 1233514..1c4f0cb 100644 --- a/Example.Frontend/ClientBasedPrinter.cs +++ b/Example.Frontend/ClientBasedPrinter.cs @@ -13,6 +13,11 @@ namespace Example.Frontend return Task.CompletedTask; } + public Task SetFingerPrint(int[] fingerPrint) + { + return Task.CompletedTask; + } + public void OnPrintExternal(IPage p0, RequestContext ro) { } diff --git a/Example.Frontend/Program.cs b/Example.Frontend/Program.cs index 129e91d..b118593 100644 --- a/Example.Frontend/Program.cs +++ b/Example.Frontend/Program.cs @@ -51,6 +51,11 @@ class Program using (var disposingPrinter = factory.Create("Test")) { + disposingPrinter.SetFingerPrint(new[] { 1, 2, 3 }).ContinueWith(r => + { + Console.WriteLine(r.Status); + }); + DemoCheck.CreatingPrinter = true; disposingPrinter.OnPrint += (_, _) => { diff --git a/Example.Shared/IPrinter.cs b/Example.Shared/IPrinter.cs index 505d614..e34b889 100644 --- a/Example.Shared/IPrinter.cs +++ b/Example.Shared/IPrinter.cs @@ -15,5 +15,6 @@ namespace Example.Shared event Action OnPrint; [Untrusted] Task SomeoneIsApproaching(string humanName); + Task SetFingerPrint(int[] fingerPrint); } } \ No newline at end of file diff --git a/mROA.Cbor/PreParsedValue.cs b/mROA.Cbor/PreParsedValue.cs index 9737b7e..c1b1575 100644 --- a/mROA.Cbor/PreParsedValue.cs +++ b/mROA.Cbor/PreParsedValue.cs @@ -1,5 +1,7 @@ using System; +using System.Collections; using System.Collections.Generic; +using System.Linq; using mROA.Abstract; using mROA.Implementation; @@ -34,6 +36,19 @@ namespace mROA.Cbor return so.UniversalValue; } + + if (type is { IsArray: true }) + { + var elementType = type.GetElementType(); + var array = Array.CreateInstance(elementType, _properties.Count); + Array.Copy(_properties.Select(i => Convert.ChangeType(i,elementType)).ToArray(), array, _properties.Count); + return array; + } + + + if (typeof(IList).IsAssignableFrom(type)) + return Convert.ChangeType(_properties.Select(i => Convert.ChangeType(i, type.GetElementType())).ToList(), type); + var instance = Activator.CreateInstance(type); if (instance == null) return null; diff --git a/mROA.Cbor/mROA.Cbor.csproj b/mROA.Cbor/mROA.Cbor.csproj index a2dbaf9..e59df81 100644 --- a/mROA.Cbor/mROA.Cbor.csproj +++ b/mROA.Cbor/mROA.Cbor.csproj @@ -3,6 +3,9 @@ netstandard2.1 enable + true + 2.0.1 + 9