Example #1
0
        public void TestArraysDiff()
        {
            // Values changed test
            var byteOutDiffData = new byte[]
            {
                1,
                2,
                13,
                29,
                44,
                15
            };
            var byteOutData = new byte[]
            {
                1,
                2,
                13,
                37,
                69
            };

            // No change test
            var intOutDiffData = new int[]
            {
                1337,
                69420,
                12345,
                0,
                0,
                5
            };
            var intOutData = new int[]
            {
                1337,
                69420,
                12345,
                0,
                0,
                5
            };

            // Array resize test
            var doubleOutDiffData = new double[]
            {
                0.2,
                6,
                1E39
            };
            var doubleOutData = new double[]
            {
                0.02,
                0.06,
                1E40,
                256.0
            };

            // Serialize
            var outNetworkBuffer = new NetworkBuffer();
            var outNetworkWriter = new NetworkWriter(outNetworkBuffer);

            outNetworkWriter.WriteByteArrayDiff(byteOutData, byteOutDiffData);
            outNetworkWriter.WriteIntArrayDiff(intOutData, intOutDiffData);
            outNetworkWriter.WriteDoubleArrayDiff(doubleOutData, doubleOutDiffData);

            // Deserialize
            var inNetworkBuffer = new NetworkBuffer(outNetworkBuffer.GetBuffer());
            var inNetworkReader = new NetworkReader(inNetworkBuffer);
            var byteInData      = inNetworkReader.ReadByteArrayDiff(byteOutDiffData);
            var intInData       = inNetworkReader.ReadIntArrayDiff(intOutDiffData);
            var doubleInData    = inNetworkReader.ReadDoubleArrayDiff(doubleOutDiffData);

            // Compare
            Assert.That(byteInData, Is.EqualTo(byteOutData));
            Assert.That(intInData, Is.EqualTo(intOutData));
            Assert.That(doubleInData, Is.EqualTo(doubleOutData));
        }