Пример #1
0
        public void RpcMessageTest()
        {
            // try setting value with constructor
            RpcMessage message = new RpcMessage
            {
                netId          = 42,
                componentIndex = 4,
                functionHash   = 0xABCDEF,
                payload        = new ArraySegment <byte>(new byte[] { 0x01, 0x02 })
            };

            // serialize
            NetworkWriter writer = new NetworkWriter();

            message.Serialize(writer);
            byte[] writerData = writer.ToArray();

            // deserialize the same data - do we get the same result?
            RpcMessage fresh = new RpcMessage();

            fresh.Deserialize(new NetworkReader(writerData));
            Assert.That(fresh.netId, Is.EqualTo(message.netId));
            Assert.That(fresh.componentIndex, Is.EqualTo(message.componentIndex));
            Assert.That(fresh.functionHash, Is.EqualTo(message.functionHash));
            Assert.That(fresh.payload.Count, Is.EqualTo(message.payload.Count));
            for (int i = 0; i < fresh.payload.Count; ++i)
            {
                Assert.That(fresh.payload.Array[fresh.payload.Offset + i],
                            Is.EqualTo(message.payload.Array[message.payload.Offset + i]));
            }
        }