Example #1
0
        public void StructWithMethods()
        {
            byte[]      arr = MessagePackerTest.PackToByteArray(new TestMessage(1, "2", 3.3));
            TestMessage t   = MessagePacker.Unpack <TestMessage>(arr);

            Assert.AreEqual(1, t.IntValue);
        }
        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));
        }
        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"
            }));
        }
Example #4
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]));
            }
        }
Example #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));
        }
Example #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));
        }
Example #7
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);
            });
        }
Example #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);
            });
        }
Example #9
0
        public void DisconnectMessage()
        {
            // try setting value with constructor
            DisconnectMessage message = new DisconnectMessage();

            byte[] arr = MessagePackerTest.PackToByteArray(message);
            Assert.DoesNotThrow(() =>
            {
                MessagePackerTest.UnpackFromByteArray <DisconnectMessage>(arr);
            });
        }
Example #10
0
        public void StructWithEmptyMethods()
        {
            byte[] arr = MessagePackerTest.PackToByteArray(new StructWithEmptyMethodMessage {
                IntValue = 1, StringValue = "2", DoubleValue = 3.3
            });
            StructWithEmptyMethodMessage t = MessagePacker.Unpack <StructWithEmptyMethodMessage>(arr);

            Assert.AreEqual(1, t.IntValue);
            Assert.AreEqual("2", t.StringValue);
            Assert.AreEqual(3.3, t.DoubleValue);
        }
Example #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));
        }
Example #12
0
        public void ClassWithEmptyMethods()
        {
            ClassWithoutBaseMessage intMessage = new ClassWithoutBaseMessage
            {
                array = new[] { 3, 4, 5 }
            };

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

            ClassWithoutBaseMessage unpacked = MessagePacker.Unpack <ClassWithoutBaseMessage>(data);

            Assert.That(unpacked.array, Is.EquivalentTo(new int[] { 3, 4, 5 }));
        }
Example #13
0
        public void AbstractBaseClassWorks()
        {
            const int       value      = 10;
            OverrideMessage intMessage = new OverrideMessage
            {
                someValue = value
            };

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

            OverrideMessage unpacked = MessagePacker.Unpack <OverrideMessage>(data);

            Assert.That(unpacked.someValue, Is.EqualTo(value));
        }
        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);
        }
Example #15
0
        public void NullObjectMessageTest()
        {
            NullableObjectMessage nullableObjectMessage = new NullableObjectMessage
            {
                name    = "pepe",
                nullObj = null
            };

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

            NullableObjectMessage unpacked = MessagePacker.Unpack <NullableObjectMessage>(data);

            Assert.That(unpacked.name, Is.EqualTo("pepe"));
            Assert.That(unpacked.nullObj, Is.Null);
        }
Example #16
0
        public void SendsNull()
        {
            Message message = new Message
            {
                collection = default
            };

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

            Message unpacked = MessagePacker.Unpack <Message>(data);

            string[] unpackedCollection = unpacked.collection;

            Assert.That(unpackedCollection, Is.Null.Or.Empty);
        }
        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);
        }
Example #18
0
        public void SendsEmpty()
        {
            Message message = new Message
            {
                collection = new FloatStringStruct[] { }
            };

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

            Message unpacked = MessagePacker.Unpack <Message>(data);

            FloatStringStruct[] unpackedCollection = unpacked.collection;

            Assert.IsNotNull(unpackedCollection);
            Assert.IsEmpty(unpackedCollection);
        }
Example #19
0
        public void SendsEmpty()
        {
            Message message = new Message
            {
                collection = new ClassWithNoConstructor[] { }
            };

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

            Message unpacked = MessagePacker.Unpack <Message>(data);

            ClassWithNoConstructor[] unpackedCollection = unpacked.collection;

            Assert.IsNotNull(unpackedCollection);
            Assert.IsEmpty(unpackedCollection);
        }
        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);
        }
Example #21
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]));
                }
            }
        }
Example #22
0
        public void MessageInheirtanceWorksWithMultipleLayers()
        {
            const int     value1     = 10;
            const int     value2     = 13;
            const int     value3     = 15;
            Layer3Message intMessage = new Layer3Message
            {
                value1 = value1,
                value2 = value2,
                value3 = value3
            };

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

            Layer3Message unpacked = MessagePacker.Unpack <Layer3Message>(data);

            Assert.That(unpacked.value1, Is.EqualTo(value1));
            Assert.That(unpacked.value2, Is.EqualTo(value2));
            Assert.That(unpacked.value3, Is.EqualTo(value3));
        }
Example #23
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]));
            }
        }
        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"));
        }
        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)));
        }
        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));
        }
Example #27
0
        public void RpcMessage()
        {
            // try setting value with constructor
            RpcMessage message = new RpcMessage
            {
                netId          = 42,
                componentIndex = 4,
                functionHash   = 0xABCDEF,
                payload        = new ArraySegment <byte>(new byte[] { 0x01, 0x02 })
            };

            byte[]     arr   = MessagePackerTest.PackToByteArray(message);
            RpcMessage fresh = MessagePacker.Unpack <RpcMessage>(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]));
            }
        }