opcua icon indicating copy to clipboard operation
opcua copied to clipboard

Support Variant array_length == 0

Open milgner opened this issue 2 years ago • 6 comments

Although I personally would prefer using Variant::Empty in case of an empty array, I yesterday encountered this error when our client tried to decode the response from a server that sent a zero-length array.

Now this code does look very explicit about its intent and I was wondering whether there's anything in the OPC UA spec that forbids arrays of length 0?

In https://open62541.org/doc/0.3/types.html#variant they seem to have many different variations on dealing with array length 0.

milgner avatar Nov 26 '21 10:11 milgner

Mostly it's because I can't tell you a type of an array if there is nothing in it to infer a type. I'm open to fixes that comply with the spec on this.

locka99 avatar Nov 27 '21 19:11 locka99

Empty arrays are allowed. For decoding we can handle length 0 == null array (length=-1).

schroeder- avatar Nov 27 '21 20:11 schroeder-

Thank you for elaborating! I'll have a closer look at the source then and think about potential solutions.

milgner avatar Nov 29 '21 10:11 milgner

Found this in the specs for empty array, null array and Variant null: https://reference.opcfoundation.org/v105/Core/docs/Part6/5.1.9/ So null array == empty array is legal.

schroeder- avatar Nov 29 '21 11:11 schroeder-

Nice! That sounds like it would be also be in accordance with the specification if decoding would return Variant::Empty in case the array length is 0? :thinking:

milgner avatar Nov 29 '21 11:11 milgner

Its up to the implementation, if we want empty, null array and Variant::Empty to be decoded separate. But at least a comparison of Variant::Empty and empty/null array should return true.

schroeder- avatar Nov 29 '21 12:11 schroeder-