コード例 #1
0
        public void CommandMessage()
        {
            // try setting value with constructor
            CommandMessage message = new CommandMessage
            {
                netId          = 42,
                componentIndex = 4,
                functionHash   = 0xABCDEF,
                payload        = new ArraySegment <byte>(new byte[] { 0x01, 0x02 })
            };

            byte[] arr = MessagePackerTest.PackToByteArray(message);

            // deserialize the same data - do we get the same result?
            CommandMessage fresh = MessagePackerTest.UnpackFromByteArray <CommandMessage>(arr);

            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]));
            }
        }
コード例 #2
0
        public void StructWithMethods()
        {
            byte[]      arr = MessagePackerTest.PackToByteArray(new TestMessage(1, "2", 3.3));
            TestMessage t   = MessagePackerTest.UnpackFromByteArray <TestMessage>(arr);

            Assert.AreEqual(1, t.IntValue);
        }
コード例 #3
0
        public void SendsData()
        {
            Message message = new Message
            {
                collection = new ClassWithNoConstructor[]
                {
                    new ClassWithNoConstructor {
                        a = 3
                    }, new ClassWithNoConstructor {
                        a = 4
                    }, new ClassWithNoConstructor {
                        a = 5
                    }
                }
            };

            byte[] data = MessagePackerTest.PackToByteArray(message);

            Message unpacked = MessagePackerTest.UnpackFromByteArray <Message>(data);

            ClassWithNoConstructor[] unpackedCollection = unpacked.collection;

            Assert.IsNotNull(unpackedCollection);
            Assert.IsNotEmpty(unpackedCollection);
            Assert.That(unpackedCollection[0].a, Is.EqualTo(new ClassWithNoConstructor {
                a = 3
            }.a));
            Assert.That(unpackedCollection[1].a, Is.EqualTo(new ClassWithNoConstructor {
                a = 4
            }.a));
            Assert.That(unpackedCollection[2].a, Is.EqualTo(new ClassWithNoConstructor {
                a = 5
            }.a));
        }
コード例 #4
0
        public void SendsData()
        {
            Message message = new Message
            {
                collection = new FloatStringStruct[]
                {
                    new FloatStringStruct {
                        value = 3, anotherValue = "Some"
                    }, new FloatStringStruct {
                        value = 4, anotherValue = "String"
                    }, new FloatStringStruct {
                        value = 5, anotherValue = "Values"
                    }
                }
            };

            byte[] data = MessagePackerTest.PackToByteArray(message);

            Message unpacked = MessagePackerTest.UnpackFromByteArray <Message>(data);

            FloatStringStruct[] unpackedCollection = unpacked.collection;

            Assert.IsNotNull(unpackedCollection);
            Assert.IsNotEmpty(unpackedCollection);
            Assert.That(unpackedCollection[0], Is.EqualTo(new FloatStringStruct {
                value = 3, anotherValue = "Some"
            }));
            Assert.That(unpackedCollection[1], Is.EqualTo(new FloatStringStruct {
                value = 4, anotherValue = "String"
            }));
            Assert.That(unpackedCollection[2], Is.EqualTo(new FloatStringStruct {
                value = 5, anotherValue = "Values"
            }));
        }
コード例 #5
0
        public void ErrorMessage()
        {
            // try setting value with constructor
            ErrorMessage message = new ErrorMessage(42);

            byte[]       arr   = MessagePackerTest.PackToByteArray(message);
            ErrorMessage fresh = MessagePackerTest.UnpackFromByteArray <ErrorMessage>(arr);

            Assert.That(fresh.value, Is.EqualTo(message.value));
        }
コード例 #6
0
        public void NetworkPingMessage()
        {
            // try setting value with constructor
            NetworkPingMessage message = new NetworkPingMessage(DateTime.Now.ToOADate());

            byte[]             arr   = MessagePackerTest.PackToByteArray(message);
            NetworkPingMessage fresh = MessagePackerTest.UnpackFromByteArray <NetworkPingMessage>(arr);

            Assert.That(fresh.clientTime, Is.EqualTo(message.clientTime));
        }
コード例 #7
0
        public void DisconnectMessage()
        {
            // try setting value with constructor
            DisconnectMessage message = new DisconnectMessage();

            byte[] arr = MessagePackerTest.PackToByteArray(message);
            Assert.DoesNotThrow(() =>
            {
                MessagePackerTest.UnpackFromByteArray <DisconnectMessage>(arr);
            });
        }
コード例 #8
0
        public void ReadyMessage()
        {
            // try setting value with constructor
            ReadyMessage message = new ReadyMessage();

            byte[] arr = MessagePackerTest.PackToByteArray(message);
            Assert.DoesNotThrow(() =>
            {
                ReadyMessage fresh = MessagePackerTest.UnpackFromByteArray <ReadyMessage>(arr);
            });
        }
コード例 #9
0
        public void ObjectSpawnStartedMessage()
        {
            // try setting value with constructor
            ObjectSpawnStartedMessage message = new ObjectSpawnStartedMessage();

            byte[] arr = MessagePackerTest.PackToByteArray(message);
            Assert.DoesNotThrow(() =>
            {
                ObjectSpawnStartedMessage fresh = MessagePackerTest.UnpackFromByteArray <ObjectSpawnStartedMessage>(arr);
            });
        }
コード例 #10
0
        public void StructWithEmptyMethods()
        {
            byte[] arr = MessagePackerTest.PackToByteArray(new StructWithEmptyMethodMessage {
                IntValue = 1, StringValue = "2", DoubleValue = 3.3
            });
            StructWithEmptyMethodMessage t = MessagePackerTest.UnpackFromByteArray <StructWithEmptyMethodMessage>(arr);

            Assert.AreEqual(1, t.IntValue);
            Assert.AreEqual("2", t.StringValue);
            Assert.AreEqual(3.3, t.DoubleValue);
        }
コード例 #11
0
        public void ObjectHideMessage()
        {
            // try setting value with constructor
            ObjectHideMessage message = new ObjectHideMessage
            {
                netId = 42,
            };

            byte[]            arr   = MessagePackerTest.PackToByteArray(message);
            ObjectHideMessage fresh = MessagePackerTest.UnpackFromByteArray <ObjectHideMessage>(arr);

            Assert.That(fresh.netId, Is.EqualTo(message.netId));
        }
コード例 #12
0
        public void SendsNull()
        {
            Message message = new Message
            {
                collection = default
            };

            byte[] data = MessagePackerTest.PackToByteArray(message);

            Message            unpacked           = MessagePackerTest.UnpackFromByteArray <Message>(data);
            ArraySegment <int> unpackedCollection = unpacked.collection;

            Assert.That(unpackedCollection.Array, Is.Null.Or.Empty);
        }
コード例 #13
0
        public void SendsNull()
        {
            Message message = new Message
            {
                collection = default
            };

            byte[] data = MessagePackerTest.PackToByteArray(message);

            Message unpacked = MessagePackerTest.UnpackFromByteArray <Message>(data);

            ClassWithNoConstructor[] unpackedCollection = unpacked.collection;

            Assert.That(unpackedCollection, Is.Null.Or.Empty);
        }
コード例 #14
0
        public void SendsEmpty()
        {
            Message message = new Message
            {
                collection = new int[] {}
            };

            byte[] data = MessagePackerTest.PackToByteArray(message);

            Message unpacked = MessagePackerTest.UnpackFromByteArray <Message>(data);

            int[] unpackedCollection = unpacked.collection;

            Assert.IsNotNull(unpackedCollection);
            Assert.IsEmpty(unpackedCollection);
        }
コード例 #15
0
        public void SpawnMessage()
        {
            DoTest(0);
            DoTest(42);

            void DoTest(ulong testSceneId)
            {
                // try setting value with constructor
                SpawnMessage message = new SpawnMessage
                {
                    netId         = 42,
                    isLocalPlayer = true,
                    isOwner       = true,
                    sceneId       = testSceneId,
                    assetId       = Guid.NewGuid(),
                    position      = UnityEngine.Vector3.one,
                    rotation      = UnityEngine.Quaternion.identity,
                    scale         = UnityEngine.Vector3.one,
                    payload       = new ArraySegment <byte>(new byte[] { 0x01, 0x02 })
                };

                byte[]       arr   = MessagePackerTest.PackToByteArray(message);
                SpawnMessage fresh = MessagePackerTest.UnpackFromByteArray <SpawnMessage>(arr);

                Assert.That(fresh.netId, Is.EqualTo(message.netId));
                Assert.That(fresh.isLocalPlayer, Is.EqualTo(message.isLocalPlayer));
                Assert.That(fresh.isOwner, Is.EqualTo(message.isOwner));
                Assert.That(fresh.sceneId, Is.EqualTo(message.sceneId));
                if (fresh.sceneId == 0)
                {
                    Assert.That(fresh.assetId, Is.EqualTo(message.assetId));
                }
                Assert.That(fresh.position, Is.EqualTo(message.position));
                Assert.That(fresh.rotation, Is.EqualTo(message.rotation));
                Assert.That(fresh.scale, Is.EqualTo(message.scale));
                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]));
                }
            }
        }
コード例 #16
0
        public void UpdateVarsMessage()
        {
            // try setting value with constructor
            UpdateVarsMessage message = new UpdateVarsMessage
            {
                netId   = 42,
                payload = new ArraySegment <byte>(new byte[] { 0x01, 0x02 })
            };

            byte[]            arr   = MessagePackerTest.PackToByteArray(message);
            UpdateVarsMessage fresh = MessagePackerTest.UnpackFromByteArray <UpdateVarsMessage>(arr);

            Assert.That(fresh.netId, Is.EqualTo(message.netId));
            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]));
            }
        }
コード例 #17
0
        public void SendsData()
        {
            Message message = new Message
            {
                collection = new Vector3[]
                {
                    new Vector3(1, 2, 3), new Vector3(4, 5, 6), new Vector3(7, 8, 9)
                }
            };

            byte[] data = MessagePackerTest.PackToByteArray(message);

            Message unpacked = MessagePackerTest.UnpackFromByteArray <Message>(data);

            Vector3[] unpackedCollection = unpacked.collection;

            Assert.IsNotNull(unpackedCollection);
            Assert.IsNotEmpty(unpackedCollection);
            Assert.That(unpackedCollection[0], Is.EqualTo(new Vector3(1, 2, 3)));
            Assert.That(unpackedCollection[1], Is.EqualTo(new Vector3(4, 5, 6)));
            Assert.That(unpackedCollection[2], Is.EqualTo(new Vector3(7, 8, 9)));
        }
コード例 #18
0
        public void SendsData()
        {
            Message message = new Message
            {
                collection = new int[]
                {
                    3, 4, 5
                }
            };

            byte[] data = MessagePackerTest.PackToByteArray(message);

            Message unpacked = MessagePackerTest.UnpackFromByteArray <Message>(data);

            int[] unpackedCollection = unpacked.collection;

            Assert.IsNotNull(unpackedCollection);
            Assert.IsNotEmpty(unpackedCollection);
            Assert.That(unpackedCollection[0], Is.EqualTo(3));
            Assert.That(unpackedCollection[1], Is.EqualTo(4));
            Assert.That(unpackedCollection[2], Is.EqualTo(5));
        }
コード例 #19
0
        public void SendsData()
        {
            Message message = new Message
            {
                collection = new string[]
                {
                    "Some", "String", "Value"
                }
            };

            byte[] data = MessagePackerTest.PackToByteArray(message);

            Message unpacked = MessagePackerTest.UnpackFromByteArray <Message>(data);

            string[] unpackedCollection = unpacked.collection;

            Assert.IsNotNull(unpackedCollection);
            Assert.IsNotEmpty(unpackedCollection);
            Assert.That(unpackedCollection[0], Is.EqualTo("Some"));
            Assert.That(unpackedCollection[1], Is.EqualTo("String"));
            Assert.That(unpackedCollection[2], Is.EqualTo("Value"));
        }