fix(scripting): #1109 byte[][] stays refused with a ByteString-specific reason
A script result has no ByteString-array form (its only byte shape is one flat Byte array) and the worker wire has no ByteString or nested-array tag, so byte[][] is left refused with every other jagged array (no new wire tag). Its reason now says it is not an array of ByteStrings and offers both forms that publish: a flat byte[] (SelectMany) or a string[] of Base64 blobs. Pinned by ScriptResultMaterializerTests.
This commit is contained in:
@@ -120,6 +120,32 @@ public sealed class ScriptResultMaterializerTests
|
||||
.Message.ShouldStartWith("The script returned a value of type 'Int32[][]'");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// lmxopcua#1109: <c>byte[][]</c> stays refused (a script result has no ByteString-array form and the worker wire has
|
||||
/// no tag for one — none was added), but its reason says so and offers the two forms that do publish. A lazy /
|
||||
/// collection sequence of byte[] is refused earlier (its element type is itself a sequence), before it runs.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void A_byte_array_of_arrays_is_refused_with_a_ByteString_specific_reason()
|
||||
{
|
||||
ScriptResultMaterializer.IsPublishable(typeof(byte[][])).ShouldBeFalse();
|
||||
var message = Should.Throw<ScriptResultException>(
|
||||
() => ScriptResultMaterializer.Materialize(new[] { new byte[] { 1, 2 }, new byte[] { 3 } }, 100)).Message;
|
||||
message.ShouldStartWith("The script returned a value of type 'Byte[][]', which an OPC UA node cannot carry: an array of arrays");
|
||||
message.ShouldContain("cannot be an array of ByteStrings");
|
||||
message.ShouldContain("SelectMany");
|
||||
message.ShouldContain("Convert.ToBase64String");
|
||||
|
||||
var ran = 0;
|
||||
Should.Throw<ScriptResultException>(() => ScriptResultMaterializer.Materialize(new List<byte[]> { new byte[] { 1 } }, 100));
|
||||
Should.Throw<ScriptResultException>(() => ScriptResultMaterializer.Materialize(
|
||||
Enumerable.Range(0, 2).Select(i => { ran++; return new[] { (byte)i }; }), 100));
|
||||
ran.ShouldBe(0);
|
||||
// The flat forms the reason offers do publish.
|
||||
ScriptResultMaterializer.Materialize(new byte[] { 1, 2, 3 }, 100).ShouldBeOfType<byte[]>();
|
||||
ScriptResultMaterializer.Materialize(new[] { "AQI=" }, 100).ShouldBeOfType<string[]>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_unpublishable_lazy_sequence_is_refused_before_it_runs()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user