The encoding of the DataSetMessage fields is handled like a Structure DataType where the DataSet fields are handled like Structure fields and fields with Structure DataType are handled like nested structures but in addition the fields are padded to the maximum size indicated by ArrayDimensions or MaxStringLength. The padding only applies to RawData field encoding.
All restrictions for the encoding of Structure DataTypes also apply to the RawData Field Encoding.
A DataSet field is encoded in the DataType and ValueRank specified in the DataSetMetaData for the DataSet. The following special handling shall be applied to ensure a fixed offset of the fields in the DataSetMessage.
- If the DataType of a DataSet field or a Structure field is String or ByteString and the actual size is smaller than the maximum possible size indicated by the MaxStringLength, the field shall be padded with bytes with value zero.
- If the ValueRank is OneDimension (1) or n>1 and the actual size of a dimension in ArrayDimensions is smaller than the maximum possible size indicated by the dimensions, the field shall be padded with bytes with value zero for each dimension.
- If the DataSet field or Structure field is a Structure with optional fields, the EncodingMask is encoded followed by all fields. Any optional field that is not present is encoded as padding with bytes with value zero. The size of the padding equals to the size needed to encode the field if it were present.
- If the DataSet field or Structure field is a Union, the encoding of the selected field is padded with bytes with value zero to the size of the longest Union field, when encoded using the rules in this chapter. The case when no field is selected is treated as if there was an encoded field whose encoded size is zero.
The following restrictions apply to the RawData field encoding.
- Fields shall have MaxStringLength defined in the FieldMetaData if the DataType is String or ByteString. Fields shall have arrayDimensions defined in the FieldMetaData if valueRank has a value of n > 0. This includes Structure fields with such DataTypes or ValueRank.
- DataSet fields and Structure fields shall not have an abstract DataType.
- DataSet fields and Structure fields shall have a concrete valueRank with values -1 or n > 0.
- DataSet fields and Structure fields shall not have the builtInType NodeId, ExpandedNodeId, QualifiedName, LocalizedText, XmlElement, DiagnosticInfo or DataValue.
- RawField encoding shall only be applied to Data Key Frame DataSetMessages.
The DataSetMessage valid bit 0 in DataSetFlags1 shall be set to false if the fields do not fulfil these requirements at the time the DataSetMessage is created.