public void AutoMoveCancelPacket_Initialization() { const IncomingPacketType ExpectedPacketType = IncomingPacketType.AutoMoveCancel; IActionWithoutContentInfo actionWithoutContentInfo = new AutoMoveCancelPacket(); Assert.AreEqual(ExpectedPacketType, actionWithoutContentInfo.Action, $"Expected {nameof(actionWithoutContentInfo.Action)} to match {ExpectedPacketType}."); }
public void StopAllActionsPacket_Initialization() { const IncomingPacketType ExpectedPacketType = IncomingPacketType.StopAllActions; IActionWithoutContentInfo actionWithoutContentInfo = new StopAllActionsPacket(); Assert.AreEqual(ExpectedPacketType, actionWithoutContentInfo.Action, $"Expected {nameof(actionWithoutContentInfo.Action)} to match {ExpectedPacketType}."); }
public void HeartbeatResponsePacket_Initialization() { const IncomingPacketType ExpectedPacketType = IncomingPacketType.HeartbeatResponse; IActionWithoutContentInfo actionWithoutContentInfo = new HeartbeatResponsePacket(); Assert.AreEqual(ExpectedPacketType, actionWithoutContentInfo.Action, $"Expected {nameof(actionWithoutContentInfo.Action)} to match {ExpectedPacketType}."); }
/// <summary> /// Selects the most appropriate packet reader for the specified type. /// </summary> /// <param name="forPacketType">The type of packet.</param> /// <returns>An instance of an <see cref="IPacketReader"/> implementation.</returns> public IPacketReader SelectPacketReader(IncomingPacketType forPacketType) { if (this.packetReadersMap.TryGetValue(forPacketType, out IPacketReader reader)) { return(reader); } return(null); }
/// <summary> /// Registers a packet reader to this protocol. /// </summary> /// <param name="forType">The type of packet to register for.</param> /// <param name="packetReader">The packet reader to register.</param> public void RegisterPacketReader(IncomingPacketType forType, IPacketReader packetReader) { packetReader.ThrowIfNull(nameof(packetReader)); if (this.packetReadersMap.ContainsKey(forType)) { throw new InvalidOperationException($"There is already a reader registered for the packet type {forType}."); } this.logger.LogTrace($"Registered packet reader for type {forType}."); this.packetReadersMap[forType] = packetReader; }
/// <summary> /// Constructs a new reader and tries to determine the internal header from the packet. /// </summary> /// <param name="data">The raw packet data</param> /// <param name="type">The type of incoming packet</param> public PacketReader(ref byte[] data, IncomingPacketType type) { DataBuffer = data; Type = type; switch (type) { case IncomingPacketType.StaticHeader: InternalHeader = ExternalHeader; Position += 2; break; case IncomingPacketType.DynamicHeader: Position += 2; break; case IncomingPacketType.NoHeader: default: InternalHeader = 0xFFFF; break; } }
public SplitPacket(IncomingPacketType type, byte[] packet) { this.Type = type; this.Packet = packet; }