示例#1
0
        private static void TestEncoding(TsscEncoder encoder, TsscDecoder decoder, TsscEncoder encoder2, byte[] writeBuffer, byte randomValue, OrigReader reader2, ushort idOld, long timestampOld, uint qualityOld, float valueOld)
        {
            ushort id2;
            long   timestamp2;
            uint   quality2;
            float  value2;

            ushort id3        = 0;
            long   timestamp3 = 0;
            uint   quality3   = 0;
            float  value3     = 0;
            int    flushPosition;

            flushPosition = encoder.FinishBlock();
            Array.Clear(writeBuffer, flushPosition, writeBuffer.Length - flushPosition);

            byte[] writeBuffer2 = new byte[writeBuffer.Length];
            encoder2.SetBuffer(writeBuffer2, randomValue, writeBuffer2.Length - randomValue);

            decoder.SetBuffer(writeBuffer, randomValue, flushPosition - randomValue);

            while (decoder.TryGetMeasurement(out id2, out timestamp2, out quality2, out value2))
            {
                if (!encoder2.TryAddMeasurement(id2, timestamp2, quality2, value2))
                {
                    throw new Exception();
                }
                if (!reader2.ReadNextMeasurement(out id3, out timestamp3, out quality3, out value3))
                {
                    throw new Exception();
                }
                if (id2 != id3)
                {
                    throw new Exception();
                }
                if (timestamp2 != timestamp3)
                {
                    throw new Exception();
                }
                if (quality2 != quality3)
                {
                    throw new Exception();
                }
                if (value2 != value3)
                {
                    throw new Exception();
                }
            }

            if (idOld != id3)
            {
                throw new Exception();
            }
            if (timestampOld != timestamp3)
            {
                throw new Exception();
            }
            if (qualityOld != quality3)
            {
                throw new Exception();
            }
            if (valueOld != value3)
            {
                throw new Exception();
            }

            if (flushPosition != encoder2.FinishBlock())
            {
                throw new Exception();
            }

            for (int x = 0; x < writeBuffer.Length; x++)
            {
                if (writeBuffer[x] != writeBuffer2[x])
                {
                    throw new Exception();
                }
            }
        }
示例#2
0
        //[TestMethod]
        public unsafe void TestSmallerSegments()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            long totalSize                     = 0;
            long measurementsProcessed         = 0;
            int  quitAfterCount                = 0;
            Dictionary <Guid, ushort> idLookup = new Dictionary <Guid, ushort>();

            var encoder  = new TsscEncoder();
            var encoder2 = new TsscEncoder();
            var decoder  = new TsscDecoder();

            foreach (var file in Directory.GetFiles(@"D:\TsscTest", "*.PhasorStream"))
            {
                if (quitAfterCount == 1)
                {
                    return;
                }
                quitAfterCount++;

                byte[] data    = File.ReadAllBytes(file);
                var    reader1 = new OrigReader(data, idLookup);
                var    reader2 = new OrigReader(data, idLookup);

                byte   randomValue = Security.Cryptography.Random.ByteBetween(1, 200);
                byte[] writeBuffer = new byte[randomValue * 1024];
                encoder.SetBuffer(writeBuffer, randomValue, writeBuffer.Length - randomValue);

                ushort id;
                long   timestamp;
                uint   quality;
                float  value;

                ushort idOld        = 0;
                long   timestampOld = 0;
                uint   qualityOld   = 0;
                float  valueOld     = 0;

                int quitAfter = Security.Cryptography.Random.ByteBetween(0, 40);
                while (reader1.ReadNextMeasurement(out id, out timestamp, out quality, out value))
                {
                    measurementsProcessed++;
                    if (quitAfter <= 0 || !encoder.TryAddMeasurement(id, timestamp, quality, value))
                    {
                        totalSize += encoder.FinishBlock();
                        TestEncoding(encoder, decoder, encoder2, writeBuffer, randomValue, reader2, idOld, timestampOld, qualityOld, valueOld);

                        randomValue = Security.Cryptography.Random.ByteBetween(1, 200);
                        writeBuffer = new byte[randomValue * 1024];
                        encoder.SetBuffer(writeBuffer, randomValue, writeBuffer.Length - randomValue);
                        if (!encoder.TryAddMeasurement(id, timestamp, quality, value))
                        {
                            throw new Exception();
                        }

                        quitAfter = Security.Cryptography.Random.ByteBetween(0, 40);
                    }

                    quitAfter--;

                    idOld        = id;
                    timestampOld = timestamp;
                    qualityOld   = quality;
                    valueOld     = value;
                }

                totalSize += encoder.FinishBlock();
                TestEncoding(encoder, decoder, encoder2, writeBuffer, randomValue, reader2, idOld, timestampOld, qualityOld, valueOld);

                System.Console.WriteLine(measurementsProcessed.ToString("N0") + " " + file + " " + sw.Elapsed.TotalSeconds.ToString("N1") + " " + (totalSize * 8 / (double)measurementsProcessed).ToString("N2"));
            }
        }