示例#1
0
        public void SingleQos_AtLeastOnce()
        {
            var expected = new[]
            {
                (byte)0x90,
                (byte)0x03,
                (byte)0x00,
                (byte)0x02,
                (byte)0x01,
            };

            MqttMessage msg = new MqttSubscribeAckMessage()
                .WithMessageIdentifier(2)
                .AddQosGrant(MqttQos.AtLeastOnce);

            Console.WriteLine(msg);

            byte[] actual = MessageSerializationHelper.GetMessageBytes(msg);

            Assert.Equal<int>(expected.Length, actual.Length);
            Assert.Equal<byte>(expected[0], actual[0]); // header byte 1
            Assert.Equal<byte>(expected[1], actual[1]); // remaining length
            Assert.Equal<byte>(expected[2], actual[2]); // message id b1
            Assert.Equal<byte>(expected[3], actual[3]); // message id b2
            Assert.Equal<byte>(expected[4], actual[4]); // QOS
        }
示例#2
0
        /// <summary>
        /// Confirms a subscription has been made with the broker. Marks the sub as confirmed in the subs storage.
        /// </summary>
        /// <param name="subAck"></param>
        private bool ConfirmSubscription(MqttMessage msg)
        {
            MqttSubscribeAckMessage subAck = (MqttSubscribeAckMessage)msg;

            Subscription sub;

            if (!pendingSubscriptions.TryGetValue(subAck.VariableHeader.MessageIdentifier, out sub))
            {
                throw new ArgumentException(
                          String.Format("There is no pending subscription against message identifier {0}", subAck.VariableHeader.MessageIdentifier));
            }

            // move it to the subscriptions pool, and out of the pending pool.
            subscriptions.Add(sub.Topic, sub);
            pendingSubscriptions.Remove(subAck.VariableHeader.MessageIdentifier);

            return(true);
        }
示例#3
0
        public void ClearGrantsClearsGrants()
        {
            MqttSubscribeAckMessage msg = new MqttSubscribeAckMessage()
                .WithMessageIdentifier(2)
                .AddQosGrant(MqttQos.AtMostOnce)
                .AddQosGrant(MqttQos.AtLeastOnce)
                .AddQosGrant(MqttQos.ExactlyOnce);

            Assert.Equal<int>(3, msg.Payload.QosGrants.Count);
            msg.Payload.ClearGrants();
            Assert.Equal<int>(0, msg.Payload.QosGrants.Count);
        }