예제 #1
0
        /// <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;
        }
예제 #2
0
        /// <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(byte forType, IPacketReader packetReader)
        {
            packetReader.ThrowIfNull(nameof(packetReader));

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

            IncomingGatewayPacketType packetType = (IncomingGatewayPacketType)forType;

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

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

            this.packetReadersMap[packetType] = packetReader;
        }