示例#1
0
 /// <summary>
 /// Creates a BinaryValueWriter, passes it to the func to let the writing take place, and returns the generated contents.
 /// </summary>
 /// <param name="writeFunc">The func used to do the actual writing of the contents.</param>
 /// <param name="useEnumNames">If true, Enums I/O will be done using the Enum's name. If false,
 /// Enum I/O will use the underlying integer value of the Enum.</param>
 /// <returns>The BinaryValueWriter contents.</returns>
 public static byte[] CreateAndWrite(Action <BinaryValueWriter> writeFunc, bool useEnumNames = true)
 {
     using (BitStream bs = new BitStream())
     {
         using (BinaryValueWriter w = Create(bs, useEnumNames))
         {
             writeFunc(w);
         }
         bs.TrimExcess();
         return(bs.GetBuffer());
     }
 }
示例#2
0
        public void TestWriteReadValuesExtensive()
        {
            var writer = new BitStream(2048);
            var src = new DE();
            _dynamicEntityFactoryBase.Write(writer, src);
            var buffer = writer.GetBuffer();

            var reader = new BitStream(buffer);
            var dest = (DE)_dynamicEntityFactoryBase.Read(reader);

            Assert.AreEqual(src.Position, dest.Position);
            Assert.AreEqual(src.Size, dest.Size);
            Assert.AreEqual(src.Velocity, dest.Velocity);
            Assert.AreEqual(src.Weight, dest.Weight);
            Assert.AreEqual(src.MapEntityIndex, dest.MapEntityIndex);
            Assert.AreEqual(src.Center, dest.Center);

            Assert.AreEqual(src.A, dest.A);
            Assert.AreEqual(src.B, dest.B);
            Assert.AreEqual(src.C, dest.C);
            Assert.AreEqual(src.D, dest.D);
            Assert.AreEqual(src.E, dest.E);
            Assert.AreEqual(src.F, dest.F);
            Assert.AreEqual(src.G, dest.G);
            Assert.AreEqual(src.H, dest.H);
            Assert.AreEqual(src.I, dest.I);
            Assert.AreEqual(src.J, dest.J);
            Assert.AreEqual(src.K, dest.K);
            Assert.AreEqual(src.L, dest.L);
            Assert.AreEqual(src.M, dest.M);
            Assert.AreEqual(src.N, dest.N);
            Assert.AreEqual(src.O, dest.O);
            Assert.AreEqual(src.P, dest.P);
            Assert.AreEqual(src.Q, dest.Q);
            Assert.AreEqual(src.R, dest.R);
        }
示例#3
0
        public void TestWriteReadValuesAndUpdatePositionVelocity()
        {
            var writer = new BitStream(2048);
            var src = new DE();
            _dynamicEntityFactoryBase.Write(writer, src);
            var buffer = writer.GetBuffer();

            var reader = new BitStream(buffer);
            var dest = (DE)_dynamicEntityFactoryBase.Read(reader);

            Assert.AreEqual(src.Position, dest.Position);
            Assert.AreEqual(src.Size, dest.Size);
            Assert.AreEqual(src.Velocity, dest.Velocity);
            Assert.AreEqual(src.Weight, dest.Weight);
            Assert.AreEqual(src.MapEntityIndex, dest.MapEntityIndex);
            Assert.AreEqual(src.Center, dest.Center);

            Assert.AreEqual(src.A, dest.A);
            Assert.AreEqual(src.B, dest.B);
            Assert.AreEqual(src.C, dest.C);
            Assert.AreEqual(src.D, dest.D);
            Assert.AreEqual(src.E, dest.E);
            Assert.AreEqual(src.F, dest.F);
            Assert.AreEqual(src.G, dest.G);
            Assert.AreEqual(src.H, dest.H);
            Assert.AreEqual(src.I, dest.I);
            Assert.AreEqual(src.J, dest.J);
            Assert.AreEqual(src.K, dest.K);
            Assert.AreEqual(src.L, dest.L);
            Assert.AreEqual(src.M, dest.M);
            Assert.AreEqual(src.N, dest.N);
            Assert.AreEqual(src.O, dest.O);
            Assert.AreEqual(src.P, dest.P);
            Assert.AreEqual(src.Q, dest.Q);
            Assert.AreEqual(src.R, dest.R);

            src.Position = new Vector2(10981, -123);
            src.SetVelocity(new Vector2(0.114f, 10.181f));

            writer = new BitStream(2048);
            src.SerializePositionAndVelocity(writer, 0);

            buffer = writer.GetBuffer();

            reader = new BitStream(buffer);
            dest.DeserializePositionAndVelocity(reader);

            Assert.AreEqual(src.Position, dest.Position);
            Assert.AreEqual(src.Size, dest.Size);
            Assert.AreEqual(src.Velocity, dest.Velocity);
            Assert.AreEqual(src.Weight, dest.Weight);
            Assert.AreEqual(src.MapEntityIndex, dest.MapEntityIndex);
            Assert.AreEqual(src.Center, dest.Center);

            Assert.AreEqual(src.A, dest.A);
            Assert.AreEqual(src.B, dest.B);
            Assert.AreEqual(src.C, dest.C);
            Assert.AreEqual(src.D, dest.D);
            Assert.AreEqual(src.E, dest.E);
            Assert.AreEqual(src.F, dest.F);
            Assert.AreEqual(src.G, dest.G);
            Assert.AreEqual(src.H, dest.H);
            Assert.AreEqual(src.I, dest.I);
            Assert.AreEqual(src.J, dest.J);
            Assert.AreEqual(src.K, dest.K);
            Assert.AreEqual(src.L, dest.L);
            Assert.AreEqual(src.M, dest.M);
            Assert.AreEqual(src.N, dest.N);
            Assert.AreEqual(src.O, dest.O);
            Assert.AreEqual(src.P, dest.P);
            Assert.AreEqual(src.Q, dest.Q);
            Assert.AreEqual(src.R, dest.R);
        }
示例#4
0
        public void TestWriteReadValuesAndUpdateExtensive()
        {
            var writer = new BitStream(2048);
            var src = new DE();
            _dynamicEntityFactoryBase.Write(writer, src);
            var buffer = writer.GetBuffer();

            var reader = new BitStream(buffer);
            var dest = (DE)_dynamicEntityFactoryBase.Read(reader);

            Assert.AreEqual(src.Position, dest.Position);
            Assert.AreEqual(src.Size, dest.Size);
            Assert.AreEqual(src.Velocity, dest.Velocity);
            Assert.AreEqual(src.Weight, dest.Weight);
            Assert.AreEqual(src.MapEntityIndex, dest.MapEntityIndex);
            Assert.AreEqual(src.Center, dest.Center);

            Assert.AreEqual(src.A, dest.A);
            Assert.AreEqual(src.B, dest.B);
            Assert.AreEqual(src.C, dest.C);
            Assert.AreEqual(src.D, dest.D);
            Assert.AreEqual(src.E, dest.E);
            Assert.AreEqual(src.F, dest.F);
            Assert.AreEqual(src.G, dest.G);
            Assert.AreEqual(src.H, dest.H);
            Assert.AreEqual(src.I, dest.I);
            Assert.AreEqual(src.J, dest.J);
            Assert.AreEqual(src.K, dest.K);
            Assert.AreEqual(src.L, dest.L);
            Assert.AreEqual(src.M, dest.M);
            Assert.AreEqual(src.N, dest.N);
            Assert.AreEqual(src.O, dest.O);
            Assert.AreEqual(src.P, dest.P);
            Assert.AreEqual(src.Q, dest.Q);
            Assert.AreEqual(src.R, dest.R);

            src.A = false;
            src.D = 100;
            src.K = 5123;
            src.N = "asfdoiuweroijsadf";
            src.P = Alignment.Left;
            src.M = new GrhIndex(10091);
            src.L = new Vector2(213, 123);

            writer = new BitStream(2048);
            src.Serialize(writer);

            buffer = writer.GetBuffer();

            reader = new BitStream(buffer);
            dest.Deserialize(reader);

            Assert.AreEqual(src.Position, dest.Position);
            Assert.AreEqual(src.Size, dest.Size);
            Assert.AreEqual(src.Velocity, dest.Velocity);
            Assert.AreEqual(src.Weight, dest.Weight);
            Assert.AreEqual(src.MapEntityIndex, dest.MapEntityIndex);
            Assert.AreEqual(src.Center, dest.Center);

            Assert.AreEqual(src.A, dest.A);
            Assert.AreEqual(src.B, dest.B);
            Assert.AreEqual(src.C, dest.C);
            Assert.AreEqual(src.D, dest.D);
            Assert.AreEqual(src.E, dest.E);
            Assert.AreEqual(src.F, dest.F);
            Assert.AreEqual(src.G, dest.G);
            Assert.AreEqual(src.H, dest.H);
            Assert.AreEqual(src.I, dest.I);
            Assert.AreEqual(src.J, dest.J);
            Assert.AreEqual(src.K, dest.K);
            Assert.AreEqual(src.L, dest.L);
            Assert.AreEqual(src.M, dest.M);
            Assert.AreEqual(src.N, dest.N);
            Assert.AreEqual(src.O, dest.O);
            Assert.AreEqual(src.P, dest.P);
            Assert.AreEqual(src.Q, dest.Q);
            Assert.AreEqual(src.R, dest.R);
        }
示例#5
0
        public void TestWriteReadValues()
        {
            var writer = new BitStream(1024);
            var src = new DE();
            _dynamicEntityFactoryBase.Write(writer, src);
            var buffer = writer.GetBuffer();

            var reader = new BitStream(buffer);
            var dest = (DE)_dynamicEntityFactoryBase.Read(reader);

            Assert.AreEqual(src.Position, dest.Position);
            Assert.AreEqual(src.Size, dest.Size);
            Assert.AreEqual(src.Velocity, dest.Velocity);
            Assert.AreEqual(src.Weight, dest.Weight);
            Assert.AreEqual(src.MapEntityIndex, dest.MapEntityIndex);
            Assert.AreEqual(src.Center, dest.Center);
        }
示例#6
0
        public void TestWriteReadManyValuesExtensive()
        {
            const int count = 1000;

            var writer = new BitStream(1024 * 1024);
            var sources = new List<DE>(count);
            for (var i = 0; i < count; i++)
            {
                var src = new DE();
                sources.Add(src);
                _dynamicEntityFactoryBase.Write(writer, src);
            }
            var buffer = writer.GetBuffer();

            var reader = new BitStream(buffer);
            for (var i = 0; i < count; i++)
            {
                var src = sources[i];
                var dest = (DE)_dynamicEntityFactoryBase.Read(reader);

                Assert.AreEqual(src.Position, dest.Position);
                Assert.AreEqual(src.Size, dest.Size);
                Assert.AreEqual(src.Velocity, dest.Velocity);
                Assert.AreEqual(src.Weight, dest.Weight);
                Assert.AreEqual(src.MapEntityIndex, dest.MapEntityIndex);
                Assert.AreEqual(src.Center, dest.Center);

                Assert.AreEqual(src.A, dest.A, "Index: " + i);
                Assert.AreEqual(src.B, dest.B, "Index: " + i);
                Assert.AreEqual(src.C, dest.C, "Index: " + i);
                Assert.AreEqual(src.D, dest.D, "Index: " + i);
                Assert.AreEqual(src.E, dest.E, "Index: " + i);
                Assert.AreEqual(src.F, dest.F, "Index: " + i);
                Assert.AreEqual(src.G, dest.G, "Index: " + i);
                Assert.AreEqual(src.H, dest.H, "Index: " + i);
                Assert.AreEqual(src.I, dest.I, "Index: " + i);
                Assert.AreEqual(src.J, dest.J, "Index: " + i);
                Assert.AreEqual(src.K, dest.K, "Index: " + i);
                Assert.AreEqual(src.L, dest.L, "Index: " + i);
                Assert.AreEqual(src.M, dest.M, "Index: " + i);
                Assert.AreEqual(src.N, dest.N, "Index: " + i);
                Assert.AreEqual(src.O, dest.O, "Index: " + i);
                Assert.AreEqual(src.P, dest.P, "Index: " + i);
                Assert.AreEqual(src.Q, dest.Q, "Index: " + i);
                Assert.AreEqual(src.R, dest.R, "Index: " + i);
            }
        }
示例#7
0
        public void TestWriteRead()
        {
            var writer = new BitStream(2048);
            var src = new DE();
            _dynamicEntityFactoryBase.Write(writer, src);
            var buffer = writer.GetBuffer();

            var reader = new BitStream(buffer);
            _dynamicEntityFactoryBase.Read(reader);
        }
示例#8
0
        public void TestSkipNonSyncNetworkValues()
        {
            var writer = new BitStream(2048);
            var src = new DE { SkipA = 1, SkipB = 2, SkipC = 3 };
            _dynamicEntityFactoryBase.Write(writer, src);
            var buffer = writer.GetBuffer();

            var reader = new BitStream(buffer);
            var dest = (DE)_dynamicEntityFactoryBase.Read(reader);

            Assert.AreEqual(src.Position, dest.Position);
            Assert.AreEqual(src.Size, dest.Size);
            Assert.AreEqual(src.Velocity, dest.Velocity);
            Assert.AreEqual(src.Weight, dest.Weight);
            Assert.AreEqual(src.MapEntityIndex, dest.MapEntityIndex);
            Assert.AreEqual(src.Center, dest.Center);

            Assert.AreEqual(src.A, dest.A);
            Assert.AreEqual(src.B, dest.B);
            Assert.AreEqual(src.C, dest.C);
            Assert.AreEqual(src.D, dest.D);
            Assert.AreEqual(src.E, dest.E);
            Assert.AreEqual(src.F, dest.F);
            Assert.AreEqual(src.G, dest.G);
            Assert.AreEqual(src.H, dest.H);
            Assert.AreEqual(src.I, dest.I);
            Assert.AreEqual(src.J, dest.J);
            Assert.AreEqual(src.K, dest.K);
            Assert.AreEqual(src.L, dest.L);
            Assert.AreEqual(src.M, dest.M);
            Assert.AreEqual(src.N, dest.N);
            Assert.AreEqual(src.O, dest.O);
            Assert.AreEqual(src.P, dest.P);
            Assert.AreEqual(src.Q, dest.Q);
            Assert.AreEqual(src.R, dest.R);

            Assert.AreNotEqual(src.SkipA, dest.SkipA);
            Assert.AreNotEqual(src.SkipB, dest.SkipB);
            Assert.AreEqual(src.SkipC, dest.SkipC);

            src.A = false;
            src.D = 100;
            src.K = 5123;
            src.N = "asfdoiuweroijsadf";
            src.P = Alignment.Left;
            src.M = new GrhIndex(10091);
            src.L = new Vector2(213, 123);
            src.Q = new Vector3(123, 412, 1931);
            src.R = new Vector4(109, 12, 190, 51);

            writer = new BitStream(2048);
            src.Serialize(writer);

            buffer = writer.GetBuffer();

            reader = new BitStream(buffer);
            dest.Deserialize(reader);

            Assert.AreEqual(src.Position, dest.Position);
            Assert.AreEqual(src.Size, dest.Size);
            Assert.AreEqual(src.Velocity, dest.Velocity);
            Assert.AreEqual(src.Weight, dest.Weight);
            Assert.AreEqual(src.MapEntityIndex, dest.MapEntityIndex);
            Assert.AreEqual(src.Center, dest.Center);

            Assert.AreEqual(src.A, dest.A);
            Assert.AreEqual(src.B, dest.B);
            Assert.AreEqual(src.C, dest.C);
            Assert.AreEqual(src.D, dest.D);
            Assert.AreEqual(src.E, dest.E);
            Assert.AreEqual(src.F, dest.F);
            Assert.AreEqual(src.G, dest.G);
            Assert.AreEqual(src.H, dest.H);
            Assert.AreEqual(src.I, dest.I);
            Assert.AreEqual(src.J, dest.J);
            Assert.AreEqual(src.K, dest.K);
            Assert.AreEqual(src.L, dest.L);
            Assert.AreEqual(src.M, dest.M);
            Assert.AreEqual(src.N, dest.N);
            Assert.AreEqual(src.O, dest.O);
            Assert.AreEqual(src.P, dest.P);
            Assert.AreEqual(src.Q, dest.Q);
            Assert.AreEqual(src.R, dest.R);

            Assert.AreNotEqual(src.SkipA, dest.SkipA);
            Assert.AreNotEqual(src.SkipB, dest.SkipB);
            Assert.AreEqual(src.SkipC, dest.SkipC);
        }