Exemplo n.º 1
0
        /// <summary>
        /// Registers a packet writer to this protocol.
        /// </summary>
        /// <param name="forType">The type of packet to register for.</param>
        /// <param name="packetWriter">The packet writer to register.</param>
        public void RegisterPacketWriter(OutgoingPacketType forType, IPacketWriter packetWriter)
        {
            packetWriter.ThrowIfNull(nameof(packetWriter));

            if (this.packetWritersMap.ContainsKey(forType))
            {
                throw new InvalidOperationException($"There is already a writer registered for the packet type: {forType}.");
            }

            this.logger.LogTrace($"Registered packet writer for type {forType}.");

            this.packetWritersMap[forType] = packetWriter;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Registers a packet writer to this protocol.
        /// </summary>
        /// <param name="forType">The type of packet to register for.</param>
        /// <param name="packetWriter">The packet writer to register.</param>
        public void RegisterPacketWriter(byte forType, IPacketWriter packetWriter)
        {
            packetWriter.ThrowIfNull(nameof(packetWriter));

            if (!Enum.IsDefined(typeof(OutgoingGatewayPacketType), forType))
            {
                throw new InvalidOperationException($"Unsupported packet type {forType:x2}. Check the types defined in {nameof(OutgoingGatewayPacketType)}.");
            }

            OutgoingGatewayPacketType packetType = (OutgoingGatewayPacketType)forType;

            if (this.packetWritersMap.ContainsKey(packetType))
            {
                throw new InvalidOperationException($"There is already a writer registered for the packet type: {packetType}.");
            }

            this.logger.Verbose($"Registered packet writer for type {packetType}.");

            this.packetWritersMap[packetType] = packetWriter;
        }