Exemplo n.º 1
0
        public void TestArraysPacked()
        {
            var outShortArray = new short[]
            {
                1,
                2,
                13,
                37,
                69
            };
            var outIntArray = new int[]
            {
                1337,
                69420,
                12345,
                0,
                0,
                5
            };
            var outDoubleArray = new double[]
            {
                0.02,
                0.06,
                1E40,
                256.0
            };

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

            outNetworkWriter.WriteShortArrayPacked(outShortArray);
            outNetworkWriter.WriteIntArrayPacked(outIntArray);
            outNetworkWriter.WriteDoubleArrayPacked(outDoubleArray);

            var inNetworkBuffer = new NetworkBuffer(outNetworkBuffer.GetBuffer());
            var inNetworkReader = new NetworkReader(inNetworkBuffer);
            var inShortArray    = inNetworkReader.ReadShortArrayPacked();
            var inIntArray      = inNetworkReader.ReadIntArrayPacked();
            var inDoubleArray   = inNetworkReader.ReadDoubleArrayPacked();

            Assert.That(outShortArray, Is.EqualTo(inShortArray));
            Assert.That(outIntArray, Is.EqualTo(inIntArray));
            Assert.That(outDoubleArray, Is.EqualTo(inDoubleArray));
        }