From 70e4e3c98bbda562c034d04e4b3b4de5c024a080 Mon Sep 17 00:00:00 2001 From: Octavian Axente Date: Sun, 26 Nov 2023 12:31:43 +0200 Subject: [PATCH 1/3] String Value added, Enum implementation updated --- src/Mx.NET.SDK.Core/Domain/Abi/Abi.cs | 1 + .../Domain/Abi/AbiDefinition.cs | 7 +- .../Domain/Codec/EnumBinaryCodec.cs | 65 ++++++++++++++++--- .../Domain/Codec/StringBinaryCodec.cs | 40 ++++++++++++ .../Domain/Codec/StructBinaryCodec.cs | 17 +++-- .../Domain/Values/BytesValue.cs | 3 +- .../Domain/Values/ESDTIdentifierValue.cs | 7 +- .../Domain/Values/EnumField.cs | 19 ------ .../Domain/Values/EnumValue.cs | 15 +++-- .../Values/{StructField.cs => Field.cs} | 8 +-- .../Domain/Values/StringValue.cs | 47 ++++++++++++++ .../Domain/Values/StructValue.cs | 6 +- .../Domain/Values/TypeValue.cs | 22 ++++++- .../Domain/Values/VariantDefinition.cs | 18 +++++ .../TypeValueTesting/StructValueTesting.cs | 30 ++++----- 15 files changed, 230 insertions(+), 75 deletions(-) create mode 100644 src/Mx.NET.SDK.Core/Domain/Codec/StringBinaryCodec.cs delete mode 100644 src/Mx.NET.SDK.Core/Domain/Values/EnumField.cs rename src/Mx.NET.SDK.Core/Domain/Values/{StructField.cs => Field.cs} (77%) create mode 100644 src/Mx.NET.SDK.Core/Domain/Values/StringValue.cs create mode 100644 src/Mx.NET.SDK.Core/Domain/Values/VariantDefinition.cs diff --git a/src/Mx.NET.SDK.Core/Domain/Abi/Abi.cs b/src/Mx.NET.SDK.Core/Domain/Abi/Abi.cs index cc4ad01..48e1e78 100644 --- a/src/Mx.NET.SDK.Core/Domain/Abi/Abi.cs +++ b/src/Mx.NET.SDK.Core/Domain/Abi/Abi.cs @@ -30,6 +30,7 @@ public class Variant { public string Name { get; set; } public int Discriminant { get; set; } + public Field[] Fields { get; set; } } public class Endpoint diff --git a/src/Mx.NET.SDK.Core/Domain/Abi/AbiDefinition.cs b/src/Mx.NET.SDK.Core/Domain/Abi/AbiDefinition.cs index 579df26..f118f02 100644 --- a/src/Mx.NET.SDK.Core/Domain/Abi/AbiDefinition.cs +++ b/src/Mx.NET.SDK.Core/Domain/Abi/AbiDefinition.cs @@ -67,7 +67,10 @@ private TypeValue GetTypeValue(string type) return TypeValue.EnumValue(typeFromStruct.Type, typeFromStruct.Variants? .ToList() - .Select(c => new FieldDefinition(c.Name, "", GetTypeValue(TypeValue.FromRustType("Enum").RustType))) + .Select(v => new VariantDefinition(v.Name, "", v.Discriminant, v.Fields? + .ToList() + .Select(f=> new FieldDefinition(f.Name, "", GetTypeValue(f.Type))) + .ToArray())) .ToArray()); } else if (typeFromStruct.Type == "struct") @@ -75,7 +78,7 @@ private TypeValue GetTypeValue(string type) return TypeValue.StructValue(typeFromStruct.Type, typeFromStruct.Fields? .ToList() - .Select(c => new FieldDefinition(c.Name, "", GetTypeValue(c.Type))) + .Select(f => new FieldDefinition(f.Name, "", GetTypeValue(f.Type))) .ToArray()); } diff --git a/src/Mx.NET.SDK.Core/Domain/Codec/EnumBinaryCodec.cs b/src/Mx.NET.SDK.Core/Domain/Codec/EnumBinaryCodec.cs index fb85220..45a1832 100644 --- a/src/Mx.NET.SDK.Core/Domain/Codec/EnumBinaryCodec.cs +++ b/src/Mx.NET.SDK.Core/Domain/Codec/EnumBinaryCodec.cs @@ -2,11 +2,10 @@ using Mx.NET.SDK.Core.Domain.Values; using System.Collections.Generic; using System.Linq; -using System.Text; namespace Mx.NET.SDK.Core.Domain.Codec { - public class EnumBinaryCodec : IBinaryCodec + public class EnumBinaryCodec : IBinaryCodec { private readonly BinaryCodec _binaryCodec; public string Type => TypeValue.BinaryTypes.Enum; @@ -18,15 +17,33 @@ public EnumBinaryCodec(BinaryCodec binaryCodec) public (IBinaryType Value, int BytesLength) DecodeNested(byte[] data, TypeValue type) { - var fieldDefinitions = type.GetFieldDefinitions(); - var fields = new List(); var originalBuffer = data; + var offset = 0; - var (value, bytesLength) = _binaryCodec.DecodeNested(data, fieldDefinitions[0].Type); + var (discriminant, lengthOfDiscriminant) = ReadDiscriminant(data); + offset += lengthOfDiscriminant; + data = originalBuffer.Slice(offset); - var index = int.Parse(value.ToString()); - var enumValue = new EnumValue(type, new EnumField(fieldDefinitions[index].Name, value)); - return (enumValue, 1); + var index = int.Parse(discriminant.ToString()); + var variantDefinitions = type.GetVariantDefinitions(); + var fieldDefinitions = variantDefinitions[index].Fields ?? new FieldDefinition[0]; + var fields = new List(); + + foreach (var fieldDefinition in fieldDefinitions) + { + var (value, fieldsLength) = _binaryCodec.DecodeNested(data, fieldDefinition.Type); + fields.Add(new Field(fieldDefinition.Name, value)); + offset += fieldsLength; + data = originalBuffer.Slice(offset); + } + + var enumValue = new EnumValue(type, variantDefinitions[index], fields.ToArray()); + return (enumValue, offset); + } + + private (IBinaryType Value, int BytesLength) ReadDiscriminant(byte[] data) + { + return _binaryCodec.DecodeNested(data, TypeValue.U8TypeValue); } public IBinaryType DecodeTopLevel(byte[] data, TypeValue type) @@ -38,12 +55,40 @@ public IBinaryType DecodeTopLevel(byte[] data, TypeValue type) public byte[] EncodeNested(IBinaryType value) { var enumValue = value.ValueOf(); - return Encoding.ASCII.GetBytes(enumValue.Variant.Discriminant.ToString()); + var buffer = new List(); + + var discriminant = new NumericValue(TypeValue.U8TypeValue, enumValue.Discriminant); + var discriminantBuffer = _binaryCodec.EncodeNested(discriminant); + + buffer.Add(discriminantBuffer); + foreach (var field in enumValue.Fields) + { + var fieldBuffer = _binaryCodec.EncodeNested(field.Value); + buffer.Add(fieldBuffer); + } + + var data = buffer.SelectMany(s => s); + return data.ToArray(); } public byte[] EncodeTopLevel(IBinaryType value) { - return EncodeNested(value); + var enumValue = value.ValueOf(); + var hasFields = enumValue.Fields?.Length > 0; + var buffer = new List(); + + var discriminant = new NumericValue(TypeValue.U8TypeValue, enumValue.Discriminant); + var discriminantBuffer = hasFields ? _binaryCodec.EncodeNested(discriminant) : _binaryCodec.EncodeTopLevel(discriminant); + buffer.Add(discriminantBuffer); + + foreach (var field in enumValue.Fields) + { + var fieldBuffer = _binaryCodec.EncodeNested(field.Value); + buffer.Add(fieldBuffer); + } + + var data = buffer.SelectMany(s => s); + return data.ToArray(); } } } diff --git a/src/Mx.NET.SDK.Core/Domain/Codec/StringBinaryCodec.cs b/src/Mx.NET.SDK.Core/Domain/Codec/StringBinaryCodec.cs new file mode 100644 index 0000000..baa0934 --- /dev/null +++ b/src/Mx.NET.SDK.Core/Domain/Codec/StringBinaryCodec.cs @@ -0,0 +1,40 @@ +using Mx.NET.SDK.Core.Domain.Values; + +namespace Mx.NET.SDK.Core.Domain.Codec +{ + public class StringBinaryCodec : IBinaryCodec + { + private readonly BytesBinaryCodec _bytesBinaryCodec; + + public StringBinaryCodec() + { + _bytesBinaryCodec = new BytesBinaryCodec(); + } + public string Type => TypeValue.BinaryTypes.String; + + public (IBinaryType Value, int BytesLength) DecodeNested(byte[] data, TypeValue type) + { + var (value, bytesLength) = _bytesBinaryCodec.DecodeNested(data, type); + return (StringValue.FromUtf8(value.ValueOf().ToString()), bytesLength); + } + + public IBinaryType DecodeTopLevel(byte[] data, TypeValue type) + { + return new StringValue(data, type); + } + + public byte[] EncodeNested(IBinaryType value) + { + var stringValueObject = value.ValueOf(); + var buffer = BytesValue.FromUtf8(stringValueObject.ToString()); + + return _bytesBinaryCodec.EncodeNested(buffer); + } + + public byte[] EncodeTopLevel(IBinaryType value) + { + var bytes = value.ValueOf(); + return bytes.Buffer; + } + } +} diff --git a/src/Mx.NET.SDK.Core/Domain/Codec/StructBinaryCodec.cs b/src/Mx.NET.SDK.Core/Domain/Codec/StructBinaryCodec.cs index a0bbddb..6d7aab9 100644 --- a/src/Mx.NET.SDK.Core/Domain/Codec/StructBinaryCodec.cs +++ b/src/Mx.NET.SDK.Core/Domain/Codec/StructBinaryCodec.cs @@ -18,15 +18,15 @@ public StructBinaryCodec(BinaryCodec binaryCodec) public (IBinaryType Value, int BytesLength) DecodeNested(byte[] data, TypeValue type) { var fieldDefinitions = type.GetFieldDefinitions(); - var fields = new List(); + var fields = new List(); var originalBuffer = data; var offset = 0; foreach (var fieldDefinition in fieldDefinitions) { - var (value, bytesLength) = _binaryCodec.DecodeNested(data, fieldDefinition.Type); - fields.Add(new StructField(fieldDefinition.Name, value)); - offset += bytesLength; + var (value, fieldsLength) = _binaryCodec.DecodeNested(data, fieldDefinition.Type); + fields.Add(new Field(fieldDefinition.Name, value)); + offset += fieldsLength; data = originalBuffer.Slice(offset); } @@ -43,16 +43,15 @@ public IBinaryType DecodeTopLevel(byte[] data, TypeValue type) public byte[] EncodeNested(IBinaryType value) { var structValue = value.ValueOf(); - var buffers = new List(); - var fields = structValue.Fields; + var fieldsBuffer = new List(); - foreach (var field in fields) + foreach (var field in structValue.Fields) { var fieldBuffer = _binaryCodec.EncodeNested(field.Value); - buffers.Add(fieldBuffer); + fieldsBuffer.Add(fieldBuffer); } - var data = buffers.SelectMany(s => s); + var data = fieldsBuffer.SelectMany(s => s); return data.ToArray(); } diff --git a/src/Mx.NET.SDK.Core/Domain/Values/BytesValue.cs b/src/Mx.NET.SDK.Core/Domain/Values/BytesValue.cs index b35fa8f..75fe9a0 100644 --- a/src/Mx.NET.SDK.Core/Domain/Values/BytesValue.cs +++ b/src/Mx.NET.SDK.Core/Domain/Values/BytesValue.cs @@ -5,8 +5,7 @@ namespace Mx.NET.SDK.Core.Domain.Values { public class BytesValue : BaseBinaryValue { - public BytesValue(byte[] data, TypeValue type) - : base(type) + public BytesValue(byte[] data, TypeValue type) : base(type) { Buffer = data; } diff --git a/src/Mx.NET.SDK.Core/Domain/Values/ESDTIdentifierValue.cs b/src/Mx.NET.SDK.Core/Domain/Values/ESDTIdentifierValue.cs index 06cb366..c01ac65 100644 --- a/src/Mx.NET.SDK.Core/Domain/Values/ESDTIdentifierValue.cs +++ b/src/Mx.NET.SDK.Core/Domain/Values/ESDTIdentifierValue.cs @@ -5,16 +5,15 @@ namespace Mx.NET.SDK.Core.Domain.Values { public class ESDTIdentifierValue : BaseBinaryValue { + public string Value { get; } + public byte[] Buffer { get; } + public ESDTIdentifierValue(byte[] data, TypeValue type) : base(type) { Buffer = data; Value = Encoding.UTF8.GetString(data); } - public string Value { get; } - - public byte[] Buffer { get; } - public static ESDTIdentifierValue From(byte[] data) { return new ESDTIdentifierValue(data, TypeValue.TokenIdentifierValue); diff --git a/src/Mx.NET.SDK.Core/Domain/Values/EnumField.cs b/src/Mx.NET.SDK.Core/Domain/Values/EnumField.cs deleted file mode 100644 index 504dac8..0000000 --- a/src/Mx.NET.SDK.Core/Domain/Values/EnumField.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace Mx.NET.SDK.Core.Domain.Values -{ - public class EnumField - { - public IBinaryType Discriminant { get; } - public string Name { get; } - - public EnumField(string name, IBinaryType value) - { - Discriminant = value; - Name = name; - } - - public override string ToString() - { - return Discriminant.ToString(); - } - } -} diff --git a/src/Mx.NET.SDK.Core/Domain/Values/EnumValue.cs b/src/Mx.NET.SDK.Core/Domain/Values/EnumValue.cs index 9fa5ed8..ebe6396 100644 --- a/src/Mx.NET.SDK.Core/Domain/Values/EnumValue.cs +++ b/src/Mx.NET.SDK.Core/Domain/Values/EnumValue.cs @@ -1,19 +1,24 @@ using Mx.NET.SDK.Core.Domain.Helper; +using System.Linq; namespace Mx.NET.SDK.Core.Domain.Values { public class EnumValue : BaseBinaryValue { - public EnumField Variant { get; } + public string Name { get; } + public int Discriminant { get; } + public Field[] Fields { get; } - public EnumValue(TypeValue enumType, EnumField variant) : base(enumType) + public EnumValue(TypeValue enumType, VariantDefinition variant, Field[] fields) : base(enumType) { - Variant = variant; + Name = variant.Name; + Discriminant = variant.Discriminant; + Fields = fields; } public override string ToString() { - return Variant.Name; + return Discriminant.ToString(); } public override T ToObject() @@ -23,7 +28,7 @@ public override T ToObject() public override string ToJson() { - return JsonUnqtWrapper.Serialize(Variant.Discriminant.ToJson()); + return JsonUnqtWrapper.Serialize((Name, Fields.Select(f => f.Value.ToJson()))); } } } diff --git a/src/Mx.NET.SDK.Core/Domain/Values/StructField.cs b/src/Mx.NET.SDK.Core/Domain/Values/Field.cs similarity index 77% rename from src/Mx.NET.SDK.Core/Domain/Values/StructField.cs rename to src/Mx.NET.SDK.Core/Domain/Values/Field.cs index 5994140..b65c392 100644 --- a/src/Mx.NET.SDK.Core/Domain/Values/StructField.cs +++ b/src/Mx.NET.SDK.Core/Domain/Values/Field.cs @@ -1,14 +1,14 @@ namespace Mx.NET.SDK.Core.Domain.Values { - public class StructField + public class Field { - public IBinaryType Value { get; } public string Name { get; } + public IBinaryType Value { get; } - public StructField(string name, IBinaryType value) + public Field(string name, IBinaryType value) { - Value = value; Name = name; + Value = value; } public override string ToString() diff --git a/src/Mx.NET.SDK.Core/Domain/Values/StringValue.cs b/src/Mx.NET.SDK.Core/Domain/Values/StringValue.cs new file mode 100644 index 0000000..662a98e --- /dev/null +++ b/src/Mx.NET.SDK.Core/Domain/Values/StringValue.cs @@ -0,0 +1,47 @@ +using System.Text; +using Mx.NET.SDK.Core.Domain.Helper; + +namespace Mx.NET.SDK.Core.Domain.Values +{ + public class StringValue : BaseBinaryValue + { + public string Value { get; } + public byte[] Buffer { get; } + + public StringValue(byte[] data, TypeValue type) : base(type) + { + Buffer = data; + Value = Encoding.UTF8.GetString(data); + } + + public static StringValue FromUtf8(string utf8String) + { + return new StringValue(Encoding.UTF8.GetBytes(utf8String), TypeValue.StringValue); + } + + public static StringValue FromHex(string hexString) + { + return new StringValue(Converter.FromHexString(hexString), TypeValue.StringValue); + } + + public static StringValue FromBuffer(byte[] data) + { + return new StringValue(data, TypeValue.StringValue); + } + + public int GetLength() + { + return Value.Length; + } + + public override string ToString() + { + return Value; + } + + public override string ToJson() + { + return ToString(); + } + } +} diff --git a/src/Mx.NET.SDK.Core/Domain/Values/StructValue.cs b/src/Mx.NET.SDK.Core/Domain/Values/StructValue.cs index 4134102..c8cbf31 100644 --- a/src/Mx.NET.SDK.Core/Domain/Values/StructValue.cs +++ b/src/Mx.NET.SDK.Core/Domain/Values/StructValue.cs @@ -8,15 +8,15 @@ namespace Mx.NET.SDK.Core.Domain.Values { public class StructValue : BaseBinaryValue { - public StructField[] Fields { get; } + public Field[] Fields { get; } - public StructValue(TypeValue structType, StructField[] fields) : base(structType) + public StructValue(TypeValue structType, Field[] fields) : base(structType) { Fields = fields; CheckTyping(); } - public StructField GetStructField(string name) + public Field GetStructField(string name) { var field = Fields.SingleOrDefault(f => f.Name == name); return field; diff --git a/src/Mx.NET.SDK.Core/Domain/Values/TypeValue.cs b/src/Mx.NET.SDK.Core/Domain/Values/TypeValue.cs index 1249c0a..6c8dea4 100644 --- a/src/Mx.NET.SDK.Core/Domain/Values/TypeValue.cs +++ b/src/Mx.NET.SDK.Core/Domain/Values/TypeValue.cs @@ -15,6 +15,7 @@ public class TypeValue private readonly int? _sizeInBytes; private readonly bool? _withSign; private readonly FieldDefinition[] _fieldDefinitions; + private readonly VariantDefinition[] _variantDefinitions; [JsonConstructor] public TypeValue(string binaryType, string rustType, int? sizeInBytes = null, bool? withSign = null) @@ -32,6 +33,13 @@ public TypeValue(string binaryType, string rustType, FieldDefinition[] fieldDefi _fieldDefinitions = fieldDefinitions; } + public TypeValue(string binaryType, string rustType, VariantDefinition[] variantDefinitions) + { + BinaryType = binaryType; + RustType = rustType; + _variantDefinitions = variantDefinitions; + } + public TypeValue(string binaryType, TypeValue innerType = null, int? length = null) { BinaryType = binaryType; @@ -79,6 +87,7 @@ public static class BinaryTypes public const string Numeric = nameof(Numeric); public const string Struct = nameof(Struct); public const string Bytes = nameof(Bytes); + public const string String = nameof(String); public const string TokenIdentifier = nameof(TokenIdentifier); public const string Option = nameof(Option); public const string Optional = nameof(Optional); @@ -141,6 +150,7 @@ public static class RustTypes public const string Bool = "bool"; public const string Bytes = "bytes"; public const string Address = "Address"; + public const string String = "utf-8 string"; public const string H256 = "H256"; public const string TokenIdentifier = "TokenIdentifier"; public const string EgldOrEsdtTokenIdentifier = "EgldOrEsdtTokenIdentifier"; @@ -164,6 +174,7 @@ public static class RustTypes public static TypeValue BooleanValue => new TypeValue(BinaryTypes.Boolean, RustTypes.Bool); public static TypeValue AddressValue => new TypeValue(BinaryTypes.Address, RustTypes.Address); + public static TypeValue StringValue => new TypeValue(BinaryTypes.Bytes, RustTypes.String); public static TypeValue TokenIdentifierValue => new TypeValue(BinaryTypes.TokenIdentifier, RustTypes.TokenIdentifier); public static TypeValue ScResult => new TypeValue(BinaryTypes.Bytes, RustTypes.Bytes); @@ -181,8 +192,8 @@ public static class RustTypes public static TypeValue StructValue(string name, FieldDefinition[] fieldDefinitions) => new TypeValue(BinaryTypes.Struct, name, fieldDefinitions); - public static TypeValue EnumValue(string name, FieldDefinition[] fieldDefinitions) => - new TypeValue(BinaryTypes.Enum, name, fieldDefinitions); + public static TypeValue EnumValue(string name, VariantDefinition[] variantDefinitions) => + new TypeValue(BinaryTypes.Enum, name, variantDefinitions); public static TypeValue FromLearnedType(string learnedType, TypeValue[] types) { @@ -277,6 +288,8 @@ public static TypeValue FromRustType(string rustType) return BytesValue; case RustTypes.Address: return AddressValue; + case RustTypes.String: + return StringValue; case RustTypes.TokenIdentifier: return TokenIdentifierValue; case RustTypes.EgldOrEsdtTokenIdentifier: @@ -293,5 +306,10 @@ public FieldDefinition[] GetFieldDefinitions() { return _fieldDefinitions; } + + public VariantDefinition[] GetVariantDefinitions() + { + return _variantDefinitions; + } } } diff --git a/src/Mx.NET.SDK.Core/Domain/Values/VariantDefinition.cs b/src/Mx.NET.SDK.Core/Domain/Values/VariantDefinition.cs new file mode 100644 index 0000000..8dd9a3e --- /dev/null +++ b/src/Mx.NET.SDK.Core/Domain/Values/VariantDefinition.cs @@ -0,0 +1,18 @@ +namespace Mx.NET.SDK.Core.Domain.Values +{ + public class VariantDefinition + { + public string Name { get; } + public string Description { get; } + public int Discriminant { get; } + public FieldDefinition[] Fields { get; } + + public VariantDefinition(string name, string description, int discriminant, FieldDefinition[] fields) + { + Name = name; + Description = description; + Discriminant = discriminant; + Fields = fields; + } + } +} diff --git a/tests/MS Testing/TypeValueTesting/StructValueTesting.cs b/tests/MS Testing/TypeValueTesting/StructValueTesting.cs index 159158e..30290f3 100644 --- a/tests/MS Testing/TypeValueTesting/StructValueTesting.cs +++ b/tests/MS Testing/TypeValueTesting/StructValueTesting.cs @@ -17,10 +17,10 @@ public async Task Add_MyStruct() new FieldDefinition("long_value", "", TypeValue.U64TypeValue), }; - var fields = new StructField[2] + var fields = new Field[2] { - new StructField("name", BytesValue.FromUtf8("test")), - new StructField("long_value", NumericValue.U64Value(522)) + new Field("name", BytesValue.FromUtf8("test")), + new Field("long_value", NumericValue.U64Value(522)) }; @@ -55,11 +55,11 @@ public async Task Add_MyStruct2() new FieldDefinition("list_bool", "", TypeValue.ListValue(TypeValue.BooleanValue)), }; - var fields = new StructField[3] + var fields = new Field[3] { - new StructField("name", BytesValue.FromUtf8("test")), - new StructField("long_value", NumericValue.U64Value(522)), - new StructField("list_bool", ListValue.From(TypeValue.BooleanValue, new IBinaryType[]{ BooleanValue.From(true), BooleanValue.From(false), BooleanValue.From(true)})), + new Field("name", BytesValue.FromUtf8("test")), + new Field("long_value", NumericValue.U64Value(522)), + new Field("list_bool", ListValue.From(TypeValue.BooleanValue, new IBinaryType[]{ BooleanValue.From(true), BooleanValue.From(false), BooleanValue.From(true)})), }; @@ -98,19 +98,19 @@ public async Task Add_ManagedVec_MyStruct2() new FieldDefinition("list_bool", "", TypeValue.ListValue(TypeValue.BooleanValue)), }; - var myStruct1Fields = new StructField[3] + var myStruct1Fields = new Field[3] { - new StructField("name", BytesValue.FromUtf8("test")), - new StructField("long_value", NumericValue.U64Value(522)), - new StructField("list_bool", ListValue.From(TypeValue.BooleanValue, new IBinaryType[]{ BooleanValue.From(true), BooleanValue.From(false), BooleanValue.From(true)})), + new Field("name", BytesValue.FromUtf8("test")), + new Field("long_value", NumericValue.U64Value(522)), + new Field("list_bool", ListValue.From(TypeValue.BooleanValue, new IBinaryType[]{ BooleanValue.From(true), BooleanValue.From(false), BooleanValue.From(true)})), }; - var myStruct2Fields = new StructField[3] + var myStruct2Fields = new Field[3] { - new StructField("name", BytesValue.FromUtf8("struct2")), - new StructField("long_value", NumericValue.U64Value(9866475528)), - new StructField("list_bool", ListValue.From(TypeValue.BooleanValue, new IBinaryType[]{ BooleanValue.From(false), BooleanValue.From(false), BooleanValue.From(true)})), + new Field("name", BytesValue.FromUtf8("struct2")), + new Field("long_value", NumericValue.U64Value(9866475528)), + new Field("list_bool", ListValue.From(TypeValue.BooleanValue, new IBinaryType[]{ BooleanValue.From(false), BooleanValue.From(false), BooleanValue.From(true)})), }; From 6c3b8f506339cd5bb0801fcfc4ffea84a7168dfe Mon Sep 17 00:00:00 2001 From: Octavian Axente Date: Sun, 26 Nov 2023 12:32:01 +0200 Subject: [PATCH 2/3] nuget packege++ --- src/Mx.NET.SDK.Core/Mx.NET.SDK.Core.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mx.NET.SDK.Core/Mx.NET.SDK.Core.csproj b/src/Mx.NET.SDK.Core/Mx.NET.SDK.Core.csproj index 40b558a..73b5ba7 100644 --- a/src/Mx.NET.SDK.Core/Mx.NET.SDK.Core.csproj +++ b/src/Mx.NET.SDK.Core/Mx.NET.SDK.Core.csproj @@ -11,7 +11,7 @@ https://github.com/RemarkableTools/Mx.NET.SDK/tree/main/src/Mx.NET.SDK.Core GitHub Remarkable Tools - 2.0.3 + 2.0.4 true RemarkableTools.Mx.Core README.md From da4fe442dd77c648126b9e777272e0289df91c8d Mon Sep 17 00:00:00 2001 From: Octavian Axente Date: Sun, 26 Nov 2023 12:33:53 +0200 Subject: [PATCH 3/3] EnumValue fix --- src/Mx.NET.SDK.Core/Domain/Values/EnumValue.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mx.NET.SDK.Core/Domain/Values/EnumValue.cs b/src/Mx.NET.SDK.Core/Domain/Values/EnumValue.cs index ebe6396..bf599ba 100644 --- a/src/Mx.NET.SDK.Core/Domain/Values/EnumValue.cs +++ b/src/Mx.NET.SDK.Core/Domain/Values/EnumValue.cs @@ -28,7 +28,7 @@ public override T ToObject() public override string ToJson() { - return JsonUnqtWrapper.Serialize((Name, Fields.Select(f => f.Value.ToJson()))); + return JsonUnqtWrapper.Serialize((Name, Fields?.Select(f => f.Value.ToJson()))); } } }