public void WriteAndRead()
        {
            var buffer        = new ResizableByteBuffer();
            var testInheritor = new TestedTypeInheritor();

            const byte a = 0x5A, b = 0x7F, c = 0x51, d = 0xE0, e = 0x1A;

            testInheritor.bytes = new List <byte>()
            {
                a, b, c, d, e
            };

            buffer.RestartForWriting();
            testInheritor.Serialize(buffer);


            testInheritor.bytes = new List <byte>()
            {
            };

            buffer.RestartForReading();
            testInheritor.Deserialize(buffer);

            Assert.AreEqual(a, testInheritor.bytes[0]);
            Assert.AreEqual(b, testInheritor.bytes[1]);
            Assert.AreEqual(c, testInheritor.bytes[2]);
            Assert.AreEqual(d, testInheritor.bytes[3]);
            Assert.AreEqual(e, testInheritor.bytes[4]);
        }
Exemplo n.º 2
0
        public void Serialization_WriteAndReadChunk()
        {
            const ushort location = 7, value = 58;
            const byte   b = 0xFE;

            var blockDataPoolingRegistry = new BlockDataPoolRegistry();

            blockDataPoolingRegistry.Register(value, () => new MockBlockData());

            var chunkState1 = new ChunkState();
            var chunkState2 = new ChunkState();

            var blockData = chunkState1.SetBlock(location, value, blockDataPoolingRegistry) as MockBlockData;

            blockData.theByte = b;

            var buffer = new ResizableByteBuffer();

            buffer.RestartForWriting();
            chunkState1.Serialize(buffer);

            buffer.RestartForReading();
            chunkState2.Deserialize(buffer, blockDataPoolingRegistry);

            var resultId       = chunkState2.GetBlockID(location);
            var resultData     = (MockBlockData)chunkState2.GetBlockData(location);
            var resultDataByte = resultData.theByte;

            Assert.AreEqual(value, resultId);
            Assert.AreEqual(b, resultDataByte);
        }
        public void SerializeAndDeserialize_String()
        {
            const string pi = "PI is a number!";

            var buffer = new ResizableByteBuffer();

            buffer.RestartForWriting();
            buffer.WriteString(pi);

            buffer.RestartForReading();
            var result = buffer.ReadString();

            Assert.AreEqual(pi, result);
        }
        public void SerializeAndDeserialize_UShort()
        {
            const ushort pi = 31415;

            var buffer = new ResizableByteBuffer();

            buffer.RestartForWriting();
            buffer.WriteFloat(pi);

            buffer.RestartForReading();
            var result = buffer.ReadFloat();

            Assert.AreEqual(pi, result);
        }