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])); } }
public void StructWithMethods() { byte[] arr = MessagePackerTest.PackToByteArray(new TestMessage(1, "2", 3.3)); TestMessage t = MessagePackerTest.UnpackFromByteArray <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" })); }
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)); }
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)); }
public void DisconnectMessage() { // try setting value with constructor DisconnectMessage message = new DisconnectMessage(); byte[] arr = MessagePackerTest.PackToByteArray(message); Assert.DoesNotThrow(() => { MessagePackerTest.UnpackFromByteArray <DisconnectMessage>(arr); }); }
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); }); }
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); }); }
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); }
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)); }
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); }
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); }
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); }
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])); } } }
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 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)); }
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")); }