public void TestWritePacket() { // Create the test packet. var packet = new DefaultPacket() { TestProperty1 = Vector3.One, TestProperty2 = Vector3.Zero, TestProperty3 = 4, TestProperty4 = 4, TestProperty5 = 4, }; // Test writing the packet. var reader = new BitReader(StructPacketParser.WritePacket(packet)); Assert.IsTrue(reader.ReadBit()); Assert.AreEqual(reader.Read <Vector3>(), Vector3.One); Assert.IsFalse(reader.ReadBit()); Assert.IsTrue(reader.ReadBit()); Assert.AreEqual(reader.Read <int>(), 4); Assert.IsFalse(reader.ReadBit()); Assert.AreEqual(reader.Read <int>(), 4); }
public void TestWritePacketNested() { // Create the test packet. var packet = new NestedPacket() { Value = 2, SubPacket = new DefaultPacket() { TestProperty1 = Vector3.One, TestProperty2 = Vector3.Zero, TestProperty3 = 4, TestProperty4 = 4, TestProperty5 = 4, }, SubPackets = new DefaultPacket[] { new DefaultPacket() { TestProperty1 = Vector3.One, TestProperty2 = Vector3.Zero, TestProperty3 = 5, TestProperty4 = 5, TestProperty5 = 5, }, new DefaultPacket() { TestProperty1 = Vector3.One, TestProperty2 = Vector3.Zero, TestProperty3 = 6, TestProperty4 = 6, TestProperty5 = 6, }, } }; // Test writing the packet. var reader = new BitReader(StructPacketParser.WritePacket(packet)); Assert.AreEqual(reader.Read <int>(), 2); Assert.IsTrue(reader.ReadBit()); Assert.IsTrue(reader.ReadBit()); Assert.AreEqual(reader.Read <Vector3>(), Vector3.One); Assert.IsFalse(reader.ReadBit()); Assert.IsTrue(reader.ReadBit()); Assert.AreEqual(reader.Read <int>(), 4); Assert.IsFalse(reader.ReadBit()); Assert.AreEqual(reader.Read <int>(), 4); Assert.AreEqual(reader.Read <int>(), 2); Assert.IsTrue(reader.ReadBit()); Assert.AreEqual(reader.Read <Vector3>(), Vector3.One); Assert.IsFalse(reader.ReadBit()); Assert.IsTrue(reader.ReadBit()); Assert.AreEqual(reader.Read <int>(), 5); Assert.IsTrue(reader.ReadBit()); Assert.AreEqual(reader.Read <int>(), 5); Assert.AreEqual(reader.Read <int>(), 5); Assert.IsTrue(reader.ReadBit()); Assert.AreEqual(reader.Read <Vector3>(), Vector3.One); Assert.IsFalse(reader.ReadBit()); Assert.IsTrue(reader.ReadBit()); Assert.AreEqual(reader.Read <int>(), 6); Assert.IsTrue(reader.ReadBit()); Assert.AreEqual(reader.Read <int>(), 6); Assert.AreEqual(reader.Read <int>(), 6); }
/// <summary> /// The data that is sent every time an update accrues. /// </summary> /// <param name="writer"></param> public override void Serialize(BitWriter writer) { StructPacketParser.WritePacket(this.GetSerializePacket(), writer); }
/// <summary> /// The data that is only sent once to each client. /// </summary> /// <param name="writer"></param> public override void Construct(BitWriter writer) { StructPacketParser.WritePacket(this.GetConstructPacket(), writer); }