public void CanDeserializeMovePacket()
        {
            _mockGuidSerializer.Deserialize("A").Returns(_packet.Id);
            _mockVectorSerializer.Deserialize("B").Returns(_packet.Move);
            _mockQuaternionSerializer.Deserialize("C").Returns(_packet.Rotation);

            Check.That(_serializer.Deserialize(string.Format("A{0}B{0}C{0}1", Environment.NewLine)))
            .IsEqualTo(_packet);
        }
Beispiel #2
0
        private PacketSerializer SetupPacketSerializer()
        {
            var packetSerializer     = new PacketSerializer();
            var movePacketSerializer = new MovePacketSerializer(new GuidSerializer(), new Vector3Serializer(),
                                                                new QuaternionSerializer());
            var spawnPacketSerializer = new SpawnPacketSerializer(new GuidSerializer(), new Vector3Serializer(),
                                                                  new QuaternionSerializer());
            var destroyPacketSerializer = new DestroyPacketSerializer();

            packetSerializer.Deserializers.Add(typeof(MovePacket), packet => movePacketSerializer.Deserialize(packet));
            packetSerializer.Deserializers.Add(typeof(SpawnPacket), packet => spawnPacketSerializer.Deserialize(packet));
            packetSerializer.Deserializers.Add(typeof(DestroyPacket), packet => new DestroyPacket(destroyPacketSerializer.Deserialize(packet)));
            return(packetSerializer);
        }
Beispiel #3
0
        private PacketSerializer GetPacketSerializer()
        {
            var serializer     = new PacketSerializer();
            var spawnConverter = new SpawnPacketSerializer(
                new GuidSerializer(),
                new Vector3Serializer(),
                new QuaternionSerializer());
            var moveConverter = new MovePacketSerializer(
                new GuidSerializer(),
                new Vector3Serializer(),
                new QuaternionSerializer());
            IPacketConverter <DestroyPacket> destroyConverter = new DestroyPacketSerializer();

            serializer.Deserializers.Add(typeof(SpawnPacket), s => spawnConverter.Deserialize(s));
            serializer.Deserializers.Add(typeof(MovePacket), s => moveConverter.Deserialize(s));
            serializer.Deserializers.Add(typeof(DestroyPacket), s => destroyConverter.Deserialize(s));

            serializer.Serializers.Add(typeof(SpawnPacket), packet => spawnConverter.Serialize((SpawnPacket)packet));
            serializer.Serializers.Add(typeof(MovePacket), packet => moveConverter.Serialize((MovePacket)packet));
            serializer.Serializers.Add(typeof(DestroyPacket), packet => destroyConverter.Serialize((DestroyPacket)packet));

            return(serializer);
        }