v9.8.2018.0605   由DataReader直接映射实体列表,以支持netstandard的MySql和SQLite,且提升性能
大石头 authored at 2018-06-05 00:45:23
1.13 KiB
X
using System;
using System.Collections.Generic;

namespace NewLife.Net.MQTT.Packets
{
    /// <summary>发布确认</summary>
    public sealed class SubAckPacket : PacketWithId
    {
        /// <summary>包类型</summary>
        public override PacketType PacketType => PacketType.SUBACK;

        /// <summary>返回代码</summary>
        public IReadOnlyList<QualityOfService> ReturnCodes { get; set; }

        public static SubAckPacket InResponseTo(SubscribePacket subscribePacket, QualityOfService maxQoS)
        {
            var subAckPacket = new SubAckPacket
            {
                PacketId = subscribePacket.PacketId
            };
            var subscriptionRequests = subscribePacket.Requests;
            var returnCodes = new QualityOfService[subscriptionRequests.Count];
            for (var i = 0; i < subscriptionRequests.Count; i++)
            {
                var requestedQos = subscriptionRequests[i].QualityOfService;
                returnCodes[i] = requestedQos <= maxQoS ? requestedQos : maxQoS;
            }

            subAckPacket.ReturnCodes = returnCodes;

            return subAckPacket;
        }
    }
}