Exemple #1
0
        public void Test()
        {
            var player = new Player();

            player.UserName    = "******";
            player.ID          = 100;
            player.Sex         = true;
            player.Signature   = "签名";
            player.HeadId      = 100;
            player.MobilePhone = "100086";
            player.CardCount   = 5000;
            player.PlayTimes   = 40000;

            PoolAllocator <IWriteStream> .SetPool((arguments => new WriteStream()));

            var writeStream = PoolAllocator <IWriteStream> .GetObject();

            var writer = new EndianBinaryWriter(writeStream);

            player.ToBinaryWriter(writer);

            var byteFragment = writeStream.ToByteFragment();

            PoolAllocator <IReadStream> .SetPool((arguments => new ReadStream()));

            var readStream = PoolAllocator <IReadStream> .GetObject();

            readStream.CopyBuffer(byteFragment.Buffer, byteFragment.Offset, byteFragment.Count);
            var reader = new EndianBinaryReader(readStream);

            var check = new Player();

            check.FromBinaryReader(reader);

            Assert.That(check.UserName, Is.EqualTo(player.UserName));
            Assert.That(check.ID, Is.EqualTo(player.ID));
            Assert.That(check.Sex, Is.EqualTo(player.Sex));
            Assert.That(check.Signature, Is.EqualTo(player.Signature));
            Assert.That(check.HeadId, Is.EqualTo(player.HeadId));
            Assert.That(check.MobilePhone, Is.EqualTo(player.MobilePhone));
            Assert.That(check.CardCount, Is.EqualTo(player.CardCount));
            Assert.That(check.PlayTimes, Is.EqualTo(player.PlayTimes));
        }