opcua
opcua copied to clipboard
Support Variant array_length == 0
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.
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.
Empty arrays are allowed. For decoding we can handle length 0 == null array (length=-1).
Thank you for elaborating! I'll have a closer look at the source then and think about potential solutions.
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.
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:
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.