Skip to content

Commit

Permalink
Add missing vars in session less message (#1505)
Browse files Browse the repository at this point in the history
**Type of Issue**
[X] Bug [ ] Enhancement [ ] Compliance [ ] Question [ ] Help wanted

The `SessionLessServiceMessage` misses the urisVersion field and localeIds

https://reference.opcfoundation.org/v104/Core/docs/Part4/6.3.2/

The urisVersion field is a VersionTime.
The urisVersion was misspelled in the Nodeset as an array. Nodeset was fixed in errata 1.04.8
  • Loading branch information
mregen committed Sep 13, 2021
1 parent a677141 commit 2b54136
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
33 changes: 32 additions & 1 deletion Stack/Opc.Ua.Core/Types/BuiltIn/SessionLessServiceMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ namespace Opc.Ua
/// </summary>
public class SessionLessServiceMessage
{
/// <summary>
/// The VersionTime of the namespaces URIs on the server.
/// </summary>
public UInt32 UriVersion;

/// <summary>
/// The namespaces URIs referenced by the message.
/// </summary>
Expand All @@ -29,6 +34,11 @@ public class SessionLessServiceMessage
/// </summary>
public StringTable ServerUris;

/// <summary>
/// The locale Ids referenced by the message.
/// </summary>
public StringTable LocaleIds;

/// <summary>
/// The message to encode or the decoded message.
/// </summary>
Expand All @@ -37,6 +47,7 @@ public class SessionLessServiceMessage
/// <inheritdoc cref="IEncodeable.Encode(IEncoder)" />
public void Encode(IEncoder encoder)
{
encoder.WriteUInt32("UriVersion", UriVersion);
if (NamespaceUris != null && NamespaceUris.Count > 1)
{
string[] uris = new string[NamespaceUris.Count - 1];
Expand Down Expand Up @@ -69,6 +80,15 @@ public void Encode(IEncoder encoder)
encoder.WriteStringArray("ServerUris", Array.Empty<string>());
}

if (LocaleIds != null && LocaleIds.Count > 1)
{
encoder.WriteStringArray("LocaleIds", LocaleIds.ToArray());
}
else
{
encoder.WriteStringArray("LocaleIds", Array.Empty<string>());
}

if (Message != null)
{
encoder.SetMappingTables(NamespaceUris, ServerUris);
Expand All @@ -90,8 +110,9 @@ public void Encode(IEncoder encoder)
/// <inheritdoc cref="IEncodeable.Decode(IDecoder)" />
public void Decode(IDecoder decoder)
{
NamespaceUris = new NamespaceTable();
UriVersion = decoder.ReadUInt32("UriVersion");

NamespaceUris = new NamespaceTable();
var uris = decoder.ReadStringArray("NamespaceUris");

if (uris != null && uris.Count > 0)
Expand All @@ -113,6 +134,16 @@ public void Decode(IDecoder decoder)
}
}

LocaleIds = new StringTable();
uris = decoder.ReadStringArray("LocaleIds");
if (uris != null && uris.Count > 0)
{
foreach (var uri in uris)
{
LocaleIds.Append(uri);
}
}

decoder.SetMappingTables(NamespaceUris, ServerUris);

uint typeId = decoder.ReadUInt32("ServiceId");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Newtonsoft.Json.Linq;
using NUnit.Framework;

Expand All @@ -18,6 +17,7 @@ public class SessionLessServiceMessageTests
public void WhenServerUrisAreLessThanNamespaces_ShouldNotThrowAndMustReturnCorrectServerUris()
{
//arrange
UInt32 uriVersion = 1234;
var namespaceTable = new NamespaceTable(new List<string> { Namespaces.OpcUa, "http://bar", "http://foo" });
var expectedServerUri = "http://foobar";
var serverUris = new StringTable(new[] { Namespaces.OpcUa, expectedServerUri });
Expand All @@ -26,6 +26,7 @@ public void WhenServerUrisAreLessThanNamespaces_ShouldNotThrowAndMustReturnCorre
using (var jsonEncoder = new JsonEncoder(context, true))
{
var envelope = new SessionLessServiceMessage {
UriVersion = uriVersion,
NamespaceUris = context.NamespaceUris,
ServerUris = context.ServerUris,
Message = null
Expand All @@ -41,6 +42,8 @@ public void WhenServerUrisAreLessThanNamespaces_ShouldNotThrowAndMustReturnCorre

var jObject = JObject.Parse(result);
Assert.IsNotNull(jObject);
UInt32 version = jObject["UriVersion"].ToObject<UInt32>();
Assert.AreEqual(uriVersion, version);
var serverUrisToken = jObject["ServerUris"];
Assert.IsNotNull(serverUrisToken);
var serverUrisEncoded = serverUrisToken.ToObject<string[]>();
Expand Down

0 comments on commit 2b54136

Please sign in to comment.