Exemplo n.º 1
0
        public void TestWriteMisaligned()
        {
            var outNetworkBuffer = new NetworkBuffer();
            var outNetworkWriter = new NetworkWriter(outNetworkBuffer);

            outNetworkWriter.WriteBit(true);
            outNetworkWriter.WriteBit(false);
            // now the stream is misalligned,  lets write some bytes
            outNetworkWriter.WriteByte(244);
            outNetworkWriter.WriteByte(123);
            outNetworkWriter.WriteInt16(-5457);
            outNetworkWriter.WriteUInt64(4773753249);
            outNetworkWriter.WriteUInt64Packed(5435285812313212);
            outNetworkWriter.WriteInt64Packed(-5435285812313212);
            outNetworkWriter.WriteBit(true);
            outNetworkWriter.WriteByte(1);
            outNetworkWriter.WriteByte(0);

            var outBuffer = outNetworkBuffer.GetBuffer();

            var inNetworkBuffer = new NetworkBuffer(outBuffer);
            var inNetworkReader = new NetworkReader(inNetworkBuffer);

            Assert.That(inNetworkReader.ReadBit(), Is.True);
            Assert.That(inNetworkReader.ReadBit(), Is.False);
            Assert.That(inNetworkReader.ReadByte(), Is.EqualTo(244));
            Assert.That(inNetworkReader.ReadByte(), Is.EqualTo(123));
            Assert.That(inNetworkReader.ReadInt16(), Is.EqualTo(-5457));
            Assert.That(inNetworkReader.ReadUInt64(), Is.EqualTo(4773753249));
            Assert.That(inNetworkReader.ReadUInt64Packed(), Is.EqualTo(5435285812313212));
            Assert.That(inNetworkReader.ReadInt64Packed(), Is.EqualTo(-5435285812313212));
            Assert.That(inNetworkReader.ReadBit(), Is.True);
            Assert.That(inNetworkReader.ReadByte(), Is.EqualTo(1));
            Assert.That(inNetworkReader.ReadByte(), Is.EqualTo(0));
        }
Exemplo n.º 2
0
        public void TestReadWriteMissaligned()
        {
            var outNetworkBuffer = new NetworkBuffer();
            var outNetworkWriter = new NetworkWriter(outNetworkBuffer);

            outNetworkWriter.WriteBit(true);
            var writeBuffer = new byte[16]
            {
                0,
                5,
                2,
                54,
                192,
                60,
                214,
                65,
                95,
                2,
                43,
                62,
                252,
                190,
                45,
                2
            };

            outNetworkBuffer.Write(writeBuffer);

            var inNetworkBuffer = new NetworkBuffer(outNetworkBuffer.GetBuffer());

            Assert.That(inNetworkBuffer.ReadBit(), Is.True);
            var readBuffer = new byte[16];

            inNetworkBuffer.Read(readBuffer, 0, 16);
            Assert.That(readBuffer, Is.EquivalentTo(writeBuffer));
        }