Skip to content

Commit

Permalink
Reverted bug for decoding extension objects, bumped version.
Browse files Browse the repository at this point in the history
  • Loading branch information
nauful committed Jul 3, 2024
1 parent 34253aa commit 5cbe935
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion NET Core/LibUA/LibUA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Title>LibUA Core</Title>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/nauful/libua</RepositoryUrl>
<Version>1.0.22</Version>
<Version>1.0.23</Version>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>
Expand Down
6 changes: 1 addition & 5 deletions NET Core/LibUA/MemoryBufferExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ public static bool Decode(this MemoryBuffer mem, out DataValue dv)
return false;
}
return true;

}

public static int CodingSize(this MemoryBuffer mem, DataValue dv)
Expand Down Expand Up @@ -1642,10 +1642,6 @@ public static bool Decode(this MemoryBuffer mem, out ExtensionObject obj)
{
if (!mem.DecodeUAByteString(out byte[] str)) { return false; }
obj.Body = str;

return obj.TryDecodeByteString();


}

return true;
Expand Down
22 changes: 12 additions & 10 deletions NET Core/LibUA/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5803,7 +5803,7 @@ public class ExtensionObject
{
private static ConcurrentDictionary<Type, Func<MemoryBuffer, NodeId>> _objectEncoders = new();
private static ConcurrentDictionary<NodeId, Func<MemoryBuffer, object>> _objectDecoders = new();
public static void RegisterEncoder<TObject>(Func<MemoryBuffer,NodeId> encoder)
public static void RegisterEncoder<TObject>(Func<MemoryBuffer, NodeId> encoder)
{
_objectEncoders[typeof(TObject)] = encoder;
}
Expand All @@ -5813,8 +5813,6 @@ public static void RegisterDecoder<TObject>(NodeId TypeId, Func<MemoryBuffer, TO
_objectDecoders[TypeId] = decoder;
}



public NodeId TypeId { get; set; }
public byte[] Body { get; set; }

Expand All @@ -5828,11 +5826,13 @@ public bool TryEncodeByteString(int BufferCapacity)
using var buffer = new MemoryBuffer(BufferCapacity);
UAConst payloadType = 0;

if(_objectEncoders.TryGetValue(Payload.GetType(), out var encoder))
if (_objectEncoders.TryGetValue(Payload.GetType(), out var encoder))
{
TypeId = encoder(buffer);
if (TypeId == null)
{
return false;
}
}
else
{
Expand Down Expand Up @@ -5860,11 +5860,11 @@ public bool TryEncodeByteString(int BufferCapacity)
break;
case EUInformation eui:
payloadType = UAConst.EUInformation;
if(!buffer.Encode(eui)) { return false; }
if (!buffer.Encode(eui)) { return false; }
break;
case OpcRange range:
payloadType = UAConst.Range;
if(!buffer.Encode(range)) { return false; }
if (!buffer.Encode(range)) { return false; }
break;
default:
break;
Expand All @@ -5876,7 +5876,7 @@ public bool TryEncodeByteString(int BufferCapacity)
}
}

if(TypeId != null)
if (TypeId != null)
{
Body = new byte[buffer.Position];
Array.Copy(buffer.Buffer, Body, Body.Length);
Expand All @@ -5893,11 +5893,13 @@ public bool TryDecodeByteString()
{
var tmp = new MemoryBuffer(Body);

if(_objectDecoders.TryGetValue(TypeId, out var decoder))
if (_objectDecoders.TryGetValue(TypeId, out var decoder))
{
Payload = decoder(tmp);
if (Payload != null)
{
return true;
}
}

switch (TypeId.NumericIdentifier)
Expand Down Expand Up @@ -5929,12 +5931,12 @@ public bool TryDecodeByteString()
break;
case (uint)UAConst.EUInformation:
EUInformation eui;
if(!tmp.Decode(out eui)) { return false; }
if (!tmp.Decode(out eui)) { return false; }
Payload = eui;
break;
case (uint)UAConst.Range:
OpcRange range;
if(!tmp.Decode(out range)) { return false; }
if (!tmp.Decode(out range)) { return false; }
Payload = range;
break;
default:
Expand Down
2 changes: 0 additions & 2 deletions NET/LibUA/MemoryBufferExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1221,8 +1221,6 @@ public static bool Decode(this MemoryBuffer mem, out ExtensionObject obj)
{
if (!mem.DecodeUAByteString(out byte[] str)) { return false; }
obj.Body = str;

return true;
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# LibUA
Open-source OPC UA client and server library for .NET Framework and .NET Core based on IEC 62541. Available a library, a demo client and a demo server. Tested and commercially used in industrial applications with commercial vendors' UA servers and clients.

Available as a nuget package for .NET Core (1.0.22):
Available as a nuget package for .NET Core (1.0.23):
https://www.nuget.org/packages/nauful-LibUA-core

### Features
Expand Down

0 comments on commit 5cbe935

Please sign in to comment.