/// <inheritdoc/> private void EncodeBinary(IEncoder encoder) { encoder.WriteUInt32("ContentMask", MessageContentMask); if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.NodeId) != 0) { encoder.WriteString(nameof(MonitoredItemMessageContentMask.NodeId), NodeId); } if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.EndpointUrl) != 0) { encoder.WriteString(nameof(MonitoredItemMessageContentMask.EndpointUrl), EndpointUrl); } if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.ApplicationUri) != 0) { encoder.WriteString(nameof(MonitoredItemMessageContentMask.ApplicationUri), ApplicationUri); } if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.DisplayName) != 0) { encoder.WriteString(nameof(MonitoredItemMessageContentMask.DisplayName), DisplayName); } if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.Timestamp) != 0) { encoder.WriteDateTime(nameof(MonitoredItemMessageContentMask.Timestamp), Timestamp); } encoder.WriteDataValue("Value", Value); if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.SequenceNumber) != 0) { encoder.WriteUInt32(nameof(MonitoredItemMessageContentMask.SequenceNumber), SequenceNumber); } if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.ExtensionFields) != 0) { if (ExtensionFields != null) { var dictionary = new KeyValuePairCollection(); foreach (var item in ExtensionFields) { dictionary.Add(new Ua.KeyValuePair() { Key = item.Key, Value = item.Value }); } encoder.WriteEncodeableArray("ExtensionFields", dictionary.ToArray(), typeof(Ua.KeyValuePair)); } } }
/// <inheritdoc/> public void Encode(IEncoder encoder) { encoder.WriteUInt32("ContentMask", MessageContentMask); if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.NodeId) != 0) { encoder.WriteExpandedNodeId(nameof(MonitoredItemMessageContentMask.NodeId), NodeId); } // todo check why Value is not encoded as DataValue type if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.ServerTimestamp) != 0) { encoder.WriteDateTime(nameof(MonitoredItemMessageContentMask.ServerTimestamp), Value?.ServerTimestamp ?? DateTime.MinValue); } if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.ServerPicoSeconds) != 0) { encoder.WriteUInt16(nameof(MonitoredItemMessageContentMask.ServerPicoSeconds), Value?.ServerPicoseconds ?? 0); } if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.SourceTimestamp) != 0) { encoder.WriteDateTime(nameof(MonitoredItemMessageContentMask.SourceTimestamp), Value?.SourceTimestamp ?? DateTime.MinValue); } if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.SourcePicoSeconds) != 0) { encoder.WriteUInt16(nameof(MonitoredItemMessageContentMask.SourcePicoSeconds), Value?.SourcePicoseconds ?? 0); } if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.StatusCode) != 0) { encoder.WriteStatusCode(nameof(MonitoredItemMessageContentMask.StatusCode), Value?.StatusCode ?? StatusCodes.BadNoData); } if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.Status) != 0) { encoder.WriteString(nameof(MonitoredItemMessageContentMask.Status), Value == null ? "" : StatusCode.LookupSymbolicId(Value.StatusCode.Code)); } if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.EndpointUrl) != 0) { encoder.WriteString(nameof(MonitoredItemMessageContentMask.EndpointUrl), EndpointUrl); } if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.SubscriptionId) != 0) { encoder.WriteString(nameof(MonitoredItemMessageContentMask.SubscriptionId), SubscriptionId); } if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.ApplicationUri) != 0) { encoder.WriteString(nameof(MonitoredItemMessageContentMask.ApplicationUri), ApplicationUri); } if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.DisplayName) != 0) { encoder.WriteString(nameof(MonitoredItemMessageContentMask.DisplayName), DisplayName); } if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.Timestamp) != 0) { encoder.WriteDateTime(nameof(MonitoredItemMessageContentMask.Timestamp), DateTime.UtcNow); } if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.PicoSeconds) != 0) { encoder.WriteUInt16(nameof(MonitoredItemMessageContentMask.PicoSeconds), 0); } if (Value?.WrappedValue != null) { encoder.WriteVariant("Value", Value.WrappedValue); } else { encoder.WriteVariant("Value", Variant.Null); } if ((MessageContentMask & (uint)MonitoredItemMessageContentMask.ExtraFields) != 0) { if (ExtensionFields != null) { var dictionary = new KeyValuePairCollection(); foreach (var item in ExtensionFields) { dictionary.Add(new Ua.KeyValuePair() { Key = item.Key, Value = item.Value }); } encoder.WriteEncodeableArray("ExtensionFields", dictionary.ToArray(), typeof(Ua.KeyValuePair)); } } }