Exemple #1
0
        public void Deserialize(byte[] data, int len)
        {
            ReusableStream reader = new ReusableStream(data, 0, len, false);

            Channel    = reader.ReadUInt16();
            Part       = reader.ReadUInt16();
            TotalParts = reader.ReadUInt16();
            Length     = reader.ReadInt32();
            ID         = reader.ReadUInt16();
            IsAsync    = reader.ReadBoolean();

            messageNum = reader.ReadUInt64();
            force      = reader.ReadBoolean();

            int numOfItems = reader.ReadInt32();

            for (int i = 0; i < numOfItems; ++i)
            {
                ulong  key      = reader.ReadUInt64();
                int    valueLen = reader.ReadInt32();
                byte[] objData  = new byte[valueLen];
                reader.Read(objData, 0, valueLen);

                networkData.Data.Add(key, objData);
            }
        }
Exemple #2
0
        public void Deserialize(byte[] data, int len)
        {
            ReusableStream reader = new ReusableStream(data, 0, len, false);

            Channel    = reader.ReadUInt16();
            Part       = reader.ReadUInt16();
            TotalParts = reader.ReadUInt16();
            Length     = reader.ReadInt32();
            ID         = reader.ReadUInt16();
            IsAsync    = reader.ReadBoolean();

            int l = reader.ReadInt32();

            PublicKey = new byte[l];
            reader.Read(PublicKey, 0, l);

            l    = reader.ReadInt32();
            Data = new byte[l];
            reader.Read(Data, 0, l);
        }
Exemple #3
0
        public unsafe void ReadPastEnd()
        {
            var s = new ReusableStream(16);

            s.Write((ulong)3);

            var buffer = new byte[16];

            fixed(byte *p = buffer)
            {
                var bufferPtr = p;

                Assert.AreEqual(-1, s.ReadByte());
                Assert.Throws <IndexOutOfRangeException>(() => s.ReadBoolean());
                Assert.Throws <IndexOutOfRangeException>(() => s.ReadInt8());
                Assert.Throws <IndexOutOfRangeException>(() => s.ReadUInt8());
                Assert.Throws <IndexOutOfRangeException>(() => s.ReadInt16());
                Assert.Throws <IndexOutOfRangeException>(() => s.ReadUInt16());
                Assert.Throws <IndexOutOfRangeException>(() => s.ReadInt32());
                Assert.Throws <IndexOutOfRangeException>(() => s.ReadUInt32());
                Assert.Throws <IndexOutOfRangeException>(() => s.ReadInt64());
                Assert.Throws <IndexOutOfRangeException>(() => s.ReadUInt64());
                Assert.Throws <IndexOutOfRangeException>(() => s.ReadSingle());
                Assert.Throws <IndexOutOfRangeException>(() => s.ReadDouble());
                Assert.Throws <IndexOutOfRangeException>(() => s.ReadDateTime());
                Assert.Throws <IndexOutOfRangeException>(() => s.ReadGuid());
                Assert.Throws <IndexOutOfRangeException>(() => s.ReadString(true));

                Assert.AreEqual(0, s.Read(buffer, 0, 1));
                Assert.AreEqual(0, s.Read(bufferPtr, 1));

                s.ResetForReading();
                Assert.AreEqual(8, s.Read(buffer, 0, 9));

                s.ResetForReading();
                Assert.AreEqual(8, s.Read(bufferPtr, 9));
            }
        }
Exemple #4
0
        public void Deserialize(byte[] data, int len)
        {
            ReusableStream reader = new ReusableStream(data, 0, len, false);

            Channel    = reader.ReadUInt16();
            Part       = reader.ReadUInt16();
            TotalParts = reader.ReadUInt16();
            Length     = reader.ReadInt32();
            ID         = reader.ReadUInt16();
            IsAsync    = reader.ReadBoolean();

            owner = reader.ReadInt32();

            int networkedObjectDataLen = reader.ReadInt32();

            networkedObjectData = new byte[networkedObjectDataLen];
            reader.Read(networkedObjectData, 0, networkedObjectDataLen);

            prefabName = reader.ReadString();
            spawnType  = (SpawnType)reader.ReadInt32();
        }
Exemple #5
0
        public void Deserialize(byte[] data, int len)
        {
            ReusableStream reader = new ReusableStream(data, 0, len, false);

            Channel    = reader.ReadUInt16();
            Part       = reader.ReadUInt16();
            TotalParts = reader.ReadUInt16();
            Length     = reader.ReadInt32();
            ID         = reader.ReadUInt16();
            IsAsync    = reader.ReadBoolean();

            sceneName = reader.ReadString();
            int mappingLen = reader.ReadInt32();

            sceneMapping = new Dictionary <ulong, byte[]>(mappingLen);
            for (int i = 0; i < mappingLen; ++i)
            {
                ulong  key    = reader.ReadUInt64();
                int    l      = reader.ReadInt32();
                byte[] buffer = new byte[l];
                reader.Read(buffer, 0, l);
                sceneMapping.Add(key, buffer);
            }
        }
Exemple #6
0
        public unsafe void ReadWriteBytes()
        {
            var s   = new ReusableStream(4000);
            var rng = new Random();

            var tests = new byte[][]
            {
                new byte[1],
                new byte[2],
                new byte[3],
                new byte[4],
                new byte[5],
                new byte[6],
                new byte[7],
                new byte[8],
                new byte[9],
                new byte[10],
                new byte[11],
                new byte[12],
                new byte[13],
                new byte[14],
                new byte[15],
                new byte[16],
                new byte[17],
                new byte[127],
                new byte[128],
                new byte[129],
                new byte[255],
                new byte[256],
                new byte[257],
                new byte[400],
                new byte[800],
                new byte[1200],
            };

            var expectedLength = 0;

            foreach (var test in tests)
            {
                rng.NextBytes(test);
                s.Write(test);
                expectedLength += test.Length;
                Assert.AreEqual(expectedLength, s.Length);
            }

            s.ResetForReading();

            foreach (var test in tests)
            {
                var read = new byte[test.Length];
                s.Read(read, 0, read.Length);
                AssertBytesAreEqual(test, read);
            }

            // do the same thing using the unsafe methods now

            s = new ReusableStream(4000);

            expectedLength = 0;

            foreach (var test in tests)
            {
                fixed(byte *ptr = test)
                {
                    s.Write(ptr, test.Length);
                }

                expectedLength += test.Length;
                Assert.AreEqual(expectedLength, s.Length);
            }

            s.ResetForReading();

            foreach (var test in tests)
            {
                var read = new byte[test.Length + 16];
                fixed(byte *ptr = read)
                {
                    const ulong GUARD = 0xAAAAAAAAAAAAAAAA;

                    var startGuard = (ulong *)ptr;
                    var data       = &ptr[8];
                    var endGuard   = (ulong *)&data[test.Length];

                    *startGuard = GUARD;
                    *endGuard   = GUARD;

                    s.Read(data, test.Length);

                    Assert.AreEqual(GUARD, *startGuard);
                    Assert.AreEqual(GUARD, *endGuard);
                }

                var actual = new byte[test.Length];
                Array.Copy(read, 8, actual, 0, test.Length);

                AssertBytesAreEqual(test, actual);
            }
        }