using AVEVA.Historian.Client.Wcf; namespace AVEVA.Historian.Client.Tests; public sealed class WcfHistoricalWriteProtocolTests { // The exact 56-byte HistoryService.AddStreamValues "values" buffer captured live from the native // 2023 R2 client writing a historical Float sample (124.5) to a sandbox tag — see // docs/plans/revision-write-path.md §"R3.1 CAPTURED". private const string CapturedBufferHex = "4f4e0100380000002e00" + // "ON" + count(1) + totalLen(56) + payloadLen(46) "d51d3107e9f8664793b155d3d1aef544" + // tag GUID 07311dd5-f8e9-4766-93b1-55d3d1aef544 "70df38b1d101dd01" + // sample FILETIME "c000" + // OpcQuality = 192 "c0100100" + // analog double descriptor "e64bcb74e201dd01" + // received/version FILETIME "000000000000f942"; // double 124.5 [Fact] public void SerializeAddStreamValuesBuffer_MatchesCapturedNativeBuffer() { var tagGuid = new Guid("07311dd5-f8e9-4766-93b1-55d3d1aef544"); DateTime sampleTime = DateTime.FromFileTimeUtc(0x01dd01d1b138df70); DateTime receivedTime = DateTime.FromFileTimeUtc(0x01dd01e274cb4be6); byte[] actual = HistorianHistoricalWriteProtocol.SerializeAddStreamValuesBuffer( tagGuid, sampleTime, value: 124.5, receivedTime, quality: 192); Assert.Equal(Convert.FromHexString(CapturedBufferHex), actual); } [Fact] public void SerializeAddStreamValuesBuffer_HeaderDeclaresLengths() { byte[] buffer = HistorianHistoricalWriteProtocol.SerializeAddStreamValuesBuffer( Guid.NewGuid(), DateTime.UtcNow, value: 1.0, DateTime.UtcNow); Assert.Equal(56, buffer.Length); Assert.Equal(0x4E4F, BitConverter.ToUInt16(buffer, 0)); // "ON" Assert.Equal(1, BitConverter.ToUInt16(buffer, 2)); // sampleCount Assert.Equal((uint)buffer.Length, BitConverter.ToUInt32(buffer, 4)); Assert.Equal(buffer.Length - 10, BitConverter.ToUInt16(buffer, 8)); } }