From 9d46580547d3b573d5099a13ec2dc3d2a1f8206c Mon Sep 17 00:00:00 2001 From: Randy Armstrong Date: Mon, 25 Nov 2024 06:37:19 -0800 Subject: [PATCH] Revert changes for Matrix in Variant. --- .../Opc.Ua.Core/Types/Encoders/JsonDecoder.cs | 40 +++---------------- .../Opc.Ua.Core/Types/Encoders/JsonEncoder.cs | 7 +--- 2 files changed, 7 insertions(+), 40 deletions(-) diff --git a/Stack/Opc.Ua.Core/Types/Encoders/JsonDecoder.cs b/Stack/Opc.Ua.Core/Types/Encoders/JsonDecoder.cs index ba721fafa..a4166c158 100644 --- a/Stack/Opc.Ua.Core/Types/Encoders/JsonDecoder.cs +++ b/Stack/Opc.Ua.Core/Types/Encoders/JsonDecoder.cs @@ -1302,36 +1302,6 @@ private Variant ReadVariantFromObject(string valueName, BuiltInType builtInType, return array; } - if (innerValue is Dictionary map && - map.Count == 2 && - map.ContainsKey("Array") && - map.ContainsKey("Dimensions")) - { - m_stack.Push(innerValue); - - var array = ReadVariantArrayBody("Array", builtInType); - var dimensions = ReadInt32Array("Dimensions"); - - Matrix matrix = null; - - if (dimensions?.Count > 1 && array.Value is Array matrixArray) - { - (bool valid, int matrixLength) = Matrix.ValidateDimensions(dimensions, matrixArray.Length, Context.MaxArrayLength); - - if (!valid || (matrixLength != matrixArray.Length)) - { - throw ServiceResultException.Create( - StatusCodes.BadDecodingError, - "ArrayDimensions length does not match with the ArrayLength in Variant object."); - } - - matrix = new Matrix(matrixArray, builtInType, dimensions.ToArray()); - } - - m_stack.Pop(); - return new Variant(matrix); - } - return ReadVariantBody(valueName, builtInType); } @@ -2764,12 +2734,14 @@ public uint ReadSwitchField(Type switches) { if (m_stack.Peek() is Dictionary context) { + if (context.ContainsKey("SwitchField")) + { + return ReadUInt32("SwitchField"); + } + foreach (var ii in context) { - if (ii.Key != "SwitchField") - { - return (uint)Enum.Parse(switches, ii.Key); - } + return (uint)Enum.Parse(switches, ii.Key); } } diff --git a/Stack/Opc.Ua.Core/Types/Encoders/JsonEncoder.cs b/Stack/Opc.Ua.Core/Types/Encoders/JsonEncoder.cs index e6a48bedb..1d8834a6a 100644 --- a/Stack/Opc.Ua.Core/Types/Encoders/JsonEncoder.cs +++ b/Stack/Opc.Ua.Core/Types/Encoders/JsonEncoder.cs @@ -518,7 +518,7 @@ public void UsingAlternateEncoding(Action action, string fieldName /// public void WriteSwitchField(string fieldName, uint switchField) { - if (EncodingToUse == JsonEncodingType.Reversible) + if ((!SuppressArtifacts && EncodingToUse == JsonEncodingType.Compact) || EncodingToUse == JsonEncodingType.Reversible) { WriteUInt32(fieldName, switchField); } @@ -1586,13 +1586,8 @@ private void WriteVariantIntoObject(string fieldName, Variant value) if (value.Value is Matrix matrix) { - PushStructure(null); - m_writer.Write(s_quotation); - EscapeString("Array"); - m_writer.Write(s_quotationColon); WriteVariantContents(value.Value, value.TypeInfo); WriteInt32Array("Dimensions", matrix.Dimensions); - PopStructure(); return; }