Skip to content

Commit

Permalink
Revert changes for Matrix in Variant.
Browse files Browse the repository at this point in the history
  • Loading branch information
randy-armstrong committed Nov 25, 2024
1 parent a67f322 commit 9d46580
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 40 deletions.
40 changes: 6 additions & 34 deletions Stack/Opc.Ua.Core/Types/Encoders/JsonDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1302,36 +1302,6 @@ private Variant ReadVariantFromObject(string valueName, BuiltInType builtInType,
return array;
}

if (innerValue is Dictionary<string,object> 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);
}

Expand Down Expand Up @@ -2764,12 +2734,14 @@ public uint ReadSwitchField(Type switches)
{
if (m_stack.Peek() is Dictionary<string, object> 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);
}
}

Expand Down
7 changes: 1 addition & 6 deletions Stack/Opc.Ua.Core/Types/Encoders/JsonEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ public void UsingAlternateEncoding<T>(Action<string, T> action, string fieldName
/// <inheritdoc/>
public void WriteSwitchField(string fieldName, uint switchField)
{
if (EncodingToUse == JsonEncodingType.Reversible)
if ((!SuppressArtifacts && EncodingToUse == JsonEncodingType.Compact) || EncodingToUse == JsonEncodingType.Reversible)
{
WriteUInt32(fieldName, switchField);
}
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 9d46580

Please sign in to comment.