Example #1
0
        public void BufferCanWriteAndReadPackages()
        {
            const string expectedMessage = "Some Message";
            const float  expectedValue   = 46.8f;

            using (PooledNetworkWriter writer = NetworkWriterPool.GetWriter())
            {
                writer.WriteString(expectedMessage);
                writer.WriteSingle(expectedValue);

                buffer.Write(writer.ToArraySegment());
            }
            ArraySegment <byte> package = buffer.GetNextPacket();

            string message;
            float  value;

            using (PooledNetworkReader reader = NetworkReaderPool.GetReader(package))
            {
                message = reader.ReadString();
                value   = reader.ReadSingle();
            }

            Assert.That(message, Is.EqualTo(expectedMessage));
            Assert.That(value, Is.EqualTo(expectedValue));
        }
Example #2
0
        public void BufferCanWriteReadMorePackageAfterCallingReset()
        {
            const string expectedMessage = "Some Message";
            const float  expectedValue   = 46.8f;

            for (int i = 0; i < 5; i++)
            {
                using (PooledNetworkWriter writer = NetworkWriterPool.GetWriter())
                {
                    writer.WriteInt32(i);
                    writer.WriteString(expectedMessage);
                    writer.WriteSingle(expectedValue);

                    buffer.Write(writer.ToArraySegment());
                }
                ArraySegment <byte> package = buffer.GetNextPacket();

                int    index;
                string message;
                float  value;
                using (PooledNetworkReader reader = NetworkReaderPool.GetReader(package))
                {
                    index   = reader.ReadInt32();
                    message = reader.ReadString();
                    value   = reader.ReadSingle();
                }

                Assert.That(index, Is.EqualTo(i));
                Assert.That(message, Is.EqualTo(expectedMessage));
                Assert.That(value, Is.EqualTo(expectedValue));

                buffer.ResetBuffer();
            }
        }