internal override void Serialize(PacketWriter writer, MqttProtocolVersion protocolVersion)
        {
            if (Topics.Length != QosLevels.Length)
            {
                throw new InvalidOperationException("The length of Topics should match the length of QosLevels");
            }

            if (protocolVersion == MqttProtocolVersion.V3_1_1)
            {
                writer.SetFixedHeader(PacketType, MqttQos.AtLeastOnce);
            }
            else
            {
                writer.SetFixedHeader(PacketType);
            }

            writer.AppendIntegerField(PacketId);

            for (int i = 0; i < Topics.Length; i++)
            {
                if (String.IsNullOrEmpty(this.Topics[i]) || this.Topics[i].Length > Packet.MaxTopicLength)
                {
                    throw new InvalidOperationException("Invalid topic length");
                }

                writer.AppendTextField(this.Topics[i]);
                writer.Append((byte)(((byte)this.QosLevels[i]) & QosPartMask));
            }
        }
Exemplo n.º 2
0
        internal override void Serialize(PacketWriter writer, MqttProtocolVersion protocolVersion)
        {
            if (protocolVersion == MqttProtocolVersion.V3_1_1)
            {
                writer.SetFixedHeader(PacketType, MqttQos.AtLeastOnce);
            }
            else
            {
                writer.SetFixedHeader(PacketType);
            }

            writer.AppendIntegerField(PacketId);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Writes the Connect packet to the given stream and using the given
        /// protocol version.
        /// </summary>
        /// <param name="stream">The stream to write to</param>
        /// <param name="protocolVersion">Protocol to be used to write</param>
        internal override void Serialize(PacketWriter writer, MqttProtocolVersion protocolVersion)
        {
            if (protocolVersion == MqttProtocolVersion.V3_1_1)
            {
                // will flag set, will topic and will message MUST be present
                if (this.WillFlag && (WillMessage == null || String.IsNullOrEmpty(WillTopic)))
                {
                    throw new MqttProtocolException("Last will message is invalid");
                }
                // willflag not set, retain must be 0 and will topic and message MUST NOT be present
                else if (!this.WillFlag && (this.WillRetain || WillMessage != null || !String.IsNullOrEmpty(WillTopic)))
                {
                    throw new MqttProtocolException("Last will message is invalid");
                }
            }

            if (this.WillFlag && ((this.WillTopic.Length < Packet.MinTopicLength) || (this.WillTopic.Length > Packet.MaxTopicLength)))
            {
                throw new MqttProtocolException("Invalid last will topic length");
            }

            writer.SetFixedHeader(PacketType);

            MakeVariableHeader(writer);
            MakePayload(writer);
        }
        internal override void Serialize(PacketWriter writer, MqttProtocolVersion protocolVersion)
        {
            if (protocolVersion == MqttProtocolVersion.V3_1_1)
            {
                writer.SetFixedHeader(PacketType, MqttQos.AtLeastOnce);
            }
            else
            {
                writer.SetFixedHeader(PacketType);
            }

            writer.AppendIntegerField(PacketId);

            foreach (string topic in this.Topics)
            {
                writer.AppendTextField(topic);
            }
        }
Exemplo n.º 5
0
        internal override void Serialize(PacketWriter writer, MqttProtocolVersion protocolVersion)
        {
            Validate();

            if (protocolVersion == MqttProtocolVersion.V3_1_1)
            {
                writer.SetFixedHeader(PacketType, MqttQos.AtLeastOnce);
            }
            else
            {
                writer.SetFixedHeader(PacketType);
            }

            writer.AppendIntegerField(PacketId);

            for (int i = 0; i < Topics.Length; i++)
            {
                writer.AppendTextField(this.Topics[i]);
                writer.Append((byte)(((byte)this.QosLevels[i]) & QosPartMask));
            }
        }
Exemplo n.º 6
0
        internal override void Serialize(PacketWriter writer, MqttProtocolVersion protocolVersion)
        {
            if (protocolVersion == MqttProtocolVersion.V3_1_1)
            {
                if (this.QosLevel == MqttQos.AtMostOnce && this.PacketId > 0)
                {
                    throw new ArgumentException("When using QoS 0 (at most once) the PacketId must not be set");
                }
            }

            writer.SetFixedHeader(PacketType, DupFlag, QosLevel, Retain);

            // variable header
            writer.AppendTextField(this.Topic);

            if (this.QosLevel > MqttQos.AtMostOnce)
            {
                writer.AppendIntegerField(this.PacketId);
            }

            writer.Append(this.Message);
        }
Exemplo n.º 7
0
 internal override void Serialize(PacketWriter writer, MqttProtocolVersion protocolVersion)
 {
     writer.SetFixedHeader(PacketType);
     writer.AppendIntegerField(PacketId);
 }
Exemplo n.º 8
0
 internal override void Serialize(PacketWriter writer, MqttProtocolVersion protocolVersion)
 {
     writer.SetFixedHeader(PacketType);
 }