Write service: service returns BadTypeMismatch when writing an unknown structure subtype or array of structure subtype
Description
The toolkit server returns BadTypeMismatch as write value result when Variable DataType is a subtype of Structure in the 2 following cases.
- The server does not have the type encoder for the Structure subtype and cannot decode the value
- The write value request contains an array of the Structure subtype. The result is the same if the array is empty or not.
Analysis
The toolkit server typechecks fails due to the type extracted from the data value in the write value.
- The ExtensionObject TypeId field can contain the DefaultEncoding object instead of the DataType NodeId. In this case an additional resolution using address space nodes should be used to retrieve the corresponding DataType NodeId. Since it is not done we return the generic Structure DataType NodeId in this case.
- When the write value contains an array, in addition to the issue 1. which is still possible for each array item, each array item can contain different value type. It shall be verified that all fields contain same type (or compatible types but it is a bad property for typechecking). Moreover when the array is of size 0 the type cannot be more precise than Structure type but should be accepted for any Structure subtype.
Fixes
-
The "Default Binary" Encoding object node is now used to resolve the DataType node following the backward reference HasEncoding if the S2OPC_DYNAMIC_TYPE_RESOLUTION variable is defined at compilation time. This behavior is triggered in
address_space_bs__get_conv_Variant_Type
usingSOPC_AddressSpaceUtil_GetEncodingDataType
when the DataType encoder is not defined and thus local resolution of Variant DataType returned bySOPC_Variant_Get_DataType
ended as Structure abstract super-type. -
The
SOPC_Variant_Get_DataType
andaddress_space_bs__get_conv_Variant_Type
are also modified to manage array of extension objects, each element is checked to have the same DataType. Otherwise the Structure abstract type is kept since it is a correct approximation, it would be better to determine the first common super-type but it does seem to be a very complex case that does not have practical cases identified. Moreover the empty array/matrix case is already managed, a Null DataType is returned which is always accepted in type checking. It allows to write an empty extension object array into any variable data type allowing array content.