Example #1
0
        static void TestDelta <TInputStream, TOutputStream>(NetworkSchema schema, List <object> values, List <object> baselineValues)  where TInputStream : NetworkCompression.IInputStream, new()
            where TOutputStream : NetworkCompression.IOutputStream, new()
        {
            var inputBuffer    = new byte[1024 * 64];
            var baselineBuffer = new byte[1024 * 64];
            var deltaBuffer    = new byte[1024 * 64];
            var outputBuffer   = new byte[1024 * 64];

            NetworkTestUtils.WriteValues(values, inputBuffer, schema);

            if (baselineValues != null)
            {
                NetworkTestUtils.WriteValues(baselineValues, baselineBuffer, schema);
            }
            else
            {
                baselineBuffer = new byte[1024 * 64];
            }

            var outputStream = new TOutputStream();

            outputStream.Initialize(NetworkCompressionModel.DefaultModel, deltaBuffer, 0, null);
            uint hash = 0;

            DeltaWriter.Write(ref outputStream, schema, inputBuffer, baselineBuffer, zeroFieldsChanged, 0, ref hash);
            outputStream.Flush();

            var inputStream = new TInputStream();

            inputStream.Initialize(NetworkCompressionModel.DefaultModel, deltaBuffer, 0);
            hash = 0;
            DeltaReader.Read(ref inputStream, schema, outputBuffer, baselineBuffer, zeroFieldsChanged, 0, ref hash);

            NetworkTestUtils.ReadAndAssertValues(values, outputBuffer, schema);
        }
Example #2
0
        public void Delta_RandomBaseline <TInputStream, TOutputStream>() where TInputStream : NetworkCompression.IInputStream, new()
            where TOutputStream : NetworkCompression.IOutputStream, new()
        {
            var random = new System.Random(12091);

            for (int i = 0; i < 1024; ++i)
            {
                var schema         = NetworkTestUtils.GenerateRandomSchema(64, random.Next());
                var values         = NetworkTestUtils.GenerateRandomValues(schema, random.Next());
                var baselineValues = NetworkTestUtils.GenerateRandomValues(schema, random.Next());

                TestDelta <TInputStream, TOutputStream>(schema, values, baselineValues);
            }
        }
Example #3
0
        public void NetworkReadWrite_TestRandomValues()
        {
            var random = new System.Random(192831);

            var buffer = new byte[1024 * 1024];

            for (int i = 0; i < 100; ++i)
            {
                var schema = NetworkTestUtils.GenerateRandomSchema(64, random.Next());
                var values = NetworkTestUtils.GenerateRandomValues(schema, random.Next());

                NetworkTestUtils.WriteValues(values, buffer, schema);
                NetworkTestUtils.ReadAndAssertValues(values, buffer, schema);
            }
        }